Skip to content

Create release

Create release #3

Workflow file for this run

name: Create release
on: [workflow_dispatch]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
release_gh:
name: Create a release on Githb
permissions:
contents: write
runs-on: ubuntu-latest
if: format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
# only release on default branch
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Install Hatch
run: pipx install hatch
- name: Set variables
id: set_variables
shell: bash
run: |
metadata=$(hatch project metadata)
echo "::group::Variables"
cat << EOF | tee -a "$GITHUB_OUTPUT"
tag=$(git for-each-ref refs/tags --sort=-creatordate --format='%(refname:strip=2)' --count=1)
version=v$(echo ${metadata} | jq -r .version)
project_name=$(echo ${metadata} | jq -r .name)
EOF
echo "::endgroup::"
- name: Bundle and create release notes
id: bundle
env:
GH_TOKEN: ${{ github.token }}
tag: ${{ steps.set_variables.outputs.tag }}
version: ${{ steps.set_variables.outputs.version }}
project_name: ${{ steps.set_variables.outputs.project_name }}
shell: bash
run: |
mkdir bundle/
cp -r yt_dlp_plugins bundle/
cd bundle/
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
zip -9 --recurse-paths "${project_name}" *
printf "## What's Changed\n\n" >> CHANGELOG.md
gh pr list --json author,number,title,mergedAt --base "${{ github.event.repository.default_branch }}" --state merged -R ${{ github.repository }} \
| jq -r --arg authortime "$(git log --format='%at' -n1 ${tag})" \
'.[]|select((.mergedAt|strptime("%Y-%m-%dT%H:%M:%SZ")|mktime)>($authortime|tonumber))| "* \(.title) by @\(.author.login) in #\(.number|tostring)"' \
>> CHANGELOG.md
printf "\n**Full Changelog**: ${{ github.server_url }}/${{ github.repository }}/compare/${tag}...${version}\n" >> CHANGELOG.md
r=$(cat CHANGELOG.md) # <--- Read release Notes
r="${r//'%'/'%25'}" # Multiline escape sequences for %
r="${r//$'\n'/'%0A'}" # Multiline escape sequences for '\n'
r="${r//$'\r'/'%0D'}" # Multiline escape sequences for '\r'
echo "RELEASE_BODY=$r" | tee -a $GITHUB_OUTPUT # <--- Set environment variable
- name: Create a release on Github
uses: svenstaro/upload-release-action@v2
with:
tag: ${{ steps.set_variables.outputs.version }}
release_name: |
${{ steps.set_variables.outputs.project_name }} ${{ steps.set_variables.outputs.version }}
body: ${{ steps.bundle.outputs.RELEASE_BODY }}
file: bundle/${{ steps.set_variables.outputs.project_name }}.zip
asset_name: ${{ steps.set_variables.outputs.project_name }}.zip
overwrite: true
release_pypi:
name: Publish plugin to PyPI
if: format('refs/heads/{0}', github.event.repository.default_branch) == github.ref
# only release on default branch
runs-on: ubuntu-latest
permissions:
id-token: write # mandatory for trusted publishing
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build hatchling
- name: Build
shell: bash
run: |
rm -rf dist/**
printf '%s\n\n' \
"Official repository: <${{ github.server_url }}/${{ github.repository }}>" > ./README.md.new
cat ../README.md >> ./README.md.new && mv -f ./README.md.new ./README.md
python -m build --no-isolation .
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
packages-dir: dist