[build] Various build workflow improvements

- Wait for build before publishing to PyPI
- Do not run `meta_files` job if release is cancelled
- Customizable channel in release workflow
- Display badges above changelog

Authored by: bashonly, Grub4K
This commit is contained in:
bashonly 2023-05-20 11:08:50 -05:00
parent 44a79958f0
commit c4efa0aefe
No known key found for this signature in database
GPG key ID: 783F096F253D15B0
5 changed files with 90 additions and 37 deletions

View file

@ -41,7 +41,7 @@ on:
required: true required: true
type: string type: string
channel: channel:
description: Update channel (stable/nightly) description: Update channel (stable/nightly/...)
required: true required: true
default: stable default: stable
type: string type: string
@ -316,7 +316,7 @@ jobs:
dist/yt-dlp_x86.exe dist/yt-dlp_x86.exe
meta_files: meta_files:
if: inputs.meta_files && always() if: inputs.meta_files && always() && !cancelled()
needs: needs:
- unix - unix
- linux_arm - linux_arm

View file

@ -2,16 +2,20 @@ name: Publish
on: on:
workflow_call: workflow_call:
inputs: inputs:
nightly: channel:
default: false default: stable
required: false required: true
type: boolean type: string
version: version:
required: true required: true
type: string type: string
target_commitish: target_commitish:
required: true required: true
type: string type: string
prerelease:
default: false
required: true
type: boolean
secrets: secrets:
ARCHIVE_REPO_TOKEN: ARCHIVE_REPO_TOKEN:
required: false required: false
@ -34,6 +38,19 @@ jobs:
- name: Generate release notes - name: Generate release notes
run: | run: |
printf '%s' \
'[![Installation](https://img.shields.io/badge/-Which%20file%20should%20I%20download%3F-white.svg?style=for-the-badge)]' \
'(https://github.com/yt-dlp/yt-dlp#installation "Installation instructions") ' \
'[![Documentation](https://img.shields.io/badge/-Docs-brightgreen.svg?style=for-the-badge&logo=GitBook&labelColor=555555)]' \
'(https://github.com/yt-dlp/yt-dlp/tree/2023.03.04#readme "Documentation") ' \
'[![Donate](https://img.shields.io/badge/_-Donate-red.svg?logo=githubsponsors&labelColor=555555&style=for-the-badge)]' \
'(https://github.com/yt-dlp/yt-dlp/blob/master/Collaborators.md#collaborators "Donate") ' \
'[![Discord](https://img.shields.io/discord/807245652072857610?color=blue&labelColor=555555&label=&logo=discord&style=for-the-badge)]' \
'(https://discord.gg/H5MNcFW63r "Discord") ' \
${{ inputs.channel != 'nightly' && '"[![Nightly](https://img.shields.io/badge/Get%20nightly%20builds-purple.svg?style=for-the-badge)]" \
"(https://github.com/yt-dlp/yt-dlp-nightly-builds/releases/latest \"Nightly builds\")"' || '' }} \
> ./RELEASE_NOTES
printf '\n\n' >> ./RELEASE_NOTES
cat >> ./RELEASE_NOTES << EOF cat >> ./RELEASE_NOTES << EOF
#### A description of the various files are in the [README](https://github.com/yt-dlp/yt-dlp#release-files) #### A description of the various files are in the [README](https://github.com/yt-dlp/yt-dlp#release-files)
--- ---
@ -41,9 +58,9 @@ jobs:
$(python ./devscripts/make_changelog.py -vv) $(python ./devscripts/make_changelog.py -vv)
</details> </details>
EOF EOF
echo "**This is an automated nightly pre-release build**" >> ./PRERELEASE_NOTES printf '%s\n\n' '**This is an automated nightly pre-release build**' >> ./NIGHTLY_NOTES
cat ./RELEASE_NOTES >> ./PRERELEASE_NOTES cat ./RELEASE_NOTES >> ./NIGHTLY_NOTES
echo "Generated from: https://github.com/${{ github.repository }}/commit/${{ inputs.target_commitish }}" >> ./ARCHIVE_NOTES printf '%s\n\n' 'Generated from: https://github.com/${{ github.repository }}/commit/${{ inputs.target_commitish }}' >> ./ARCHIVE_NOTES
cat ./RELEASE_NOTES >> ./ARCHIVE_NOTES cat ./RELEASE_NOTES >> ./ARCHIVE_NOTES
- name: Archive nightly release - name: Archive nightly release
@ -51,7 +68,7 @@ jobs:
GH_TOKEN: ${{ secrets.ARCHIVE_REPO_TOKEN }} GH_TOKEN: ${{ secrets.ARCHIVE_REPO_TOKEN }}
GH_REPO: ${{ vars.ARCHIVE_REPO }} GH_REPO: ${{ vars.ARCHIVE_REPO }}
if: | if: |
inputs.nightly && env.GH_TOKEN != '' && env.GH_REPO != '' inputs.channel == 'nightly' && env.GH_TOKEN != '' && env.GH_REPO != ''
run: | run: |
gh release create \ gh release create \
--notes-file ARCHIVE_NOTES \ --notes-file ARCHIVE_NOTES \
@ -60,7 +77,7 @@ jobs:
artifact/* artifact/*
- name: Prune old nightly release - name: Prune old nightly release
if: inputs.nightly && !vars.ARCHIVE_REPO if: inputs.channel == 'nightly' && !vars.ARCHIVE_REPO
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
run: | run: |
@ -68,14 +85,15 @@ jobs:
git tag --delete "nightly" || true git tag --delete "nightly" || true
sleep 5 # Enough time to cover deletion race condition sleep 5 # Enough time to cover deletion race condition
- name: Publish release${{ inputs.nightly && ' (nightly)' || '' }} - name: Publish release${{ inputs.channel == 'nightly' && ' (nightly)' || '' }}
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
if: (inputs.nightly && !vars.ARCHIVE_REPO) || !inputs.nightly if: (inputs.channel == 'nightly' && !vars.ARCHIVE_REPO) || inputs.channel != 'nightly'
run: | run: |
gh release create \ gh release create \
--notes-file ${{ inputs.nightly && 'PRE' || '' }}RELEASE_NOTES \ --notes-file ${{ inputs.channel == 'nightly' && 'NIGHTLY_NOTES' || 'RELEASE_NOTES' }} \
--target ${{ inputs.target_commitish }} \ --target ${{ inputs.target_commitish }} \
--title "yt-dlp ${{ inputs.nightly && 'nightly ' || '' }}${{ inputs.version }}" \ --title "yt-dlp ${{ inputs.channel == 'nightly' && 'nightly ' || '' }}${{ inputs.version }}" \
${{ inputs.nightly && '--prerelease "nightly"' || inputs.version }} \ ${{ inputs.prerelease && '--prerelease' || '' }} \
${{ inputs.channel == 'nightly' && '"nightly"' || inputs.version }} \
artifact/* artifact/*

View file

@ -46,6 +46,7 @@ jobs:
permissions: permissions:
contents: write contents: write
with: with:
nightly: true channel: nightly
prerelease: true
version: ${{ needs.prepare.outputs.version }} version: ${{ needs.prepare.outputs.version }}
target_commitish: ${{ github.sha }} target_commitish: ${{ github.sha }}

View file

@ -1,5 +1,22 @@
name: Release name: Release
on: workflow_dispatch on:
workflow_dispatch:
inputs:
version:
description: Version tag (YYYY.MM.DD[.REV])
required: false
default: ''
type: string
channel:
description: Update channel (stable/nightly/...)
required: false
default: ''
type: string
prerelease:
description: Pre-release
default: false
type: boolean
permissions: permissions:
contents: read contents: read
@ -9,8 +26,9 @@ jobs:
contents: write contents: write
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
channel: ${{ steps.set_channel.outputs.channel }}
version: ${{ steps.update_version.outputs.version }} version: ${{ steps.update_version.outputs.version }}
head_sha: ${{ steps.push_release.outputs.head_sha }} head_sha: ${{ steps.get_target.outputs.head_sha }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -21,10 +39,18 @@ jobs:
with: with:
python-version: "3.10" python-version: "3.10"
- name: Set channel
id: set_channel
run: |
CHANNEL="${{ github.repository == 'yt-dlp/yt-dlp' && 'stable' || github.repository }}"
echo "channel=${{ inputs.channel || '$CHANNEL' }}" > "$GITHUB_OUTPUT"
- name: Update version - name: Update version
id: update_version id: update_version
run: | run: |
python devscripts/update-version.py ${{ vars.PUSH_VERSION_COMMIT == '' && '"$(date -u +"%H%M%S")"' || '' }} | \ REVISION="${{ vars.PUSH_VERSION_COMMIT == '' && '$(date -u +"%H%M%S")' || '' }}"
REVISION="${{ inputs.prerelease && '$(date -u +"%H%M%S")' || '$REVISION' }}"
python devscripts/update-version.py ${{ inputs.version || '$REVISION' }} | \
grep -Po "version=\d+\.\d+\.\d+(\.\d+)?" >> "$GITHUB_OUTPUT" grep -Po "version=\d+\.\d+\.\d+(\.\d+)?" >> "$GITHUB_OUTPUT"
- name: Update documentation - name: Update documentation
@ -39,6 +65,7 @@ jobs:
- name: Push to release - name: Push to release
id: push_release id: push_release
if: ${{ !inputs.prerelease }}
run: | run: |
git config --global user.name github-actions git config --global user.name github-actions
git config --global user.email github-actions@example.com git config --global user.email github-actions@example.com
@ -46,14 +73,30 @@ jobs:
git commit -m "Release ${{ steps.update_version.outputs.version }}" \ git commit -m "Release ${{ steps.update_version.outputs.version }}" \
-m "Created by: ${{ github.event.sender.login }}" -m ":ci skip all :ci run dl" -m "Created by: ${{ github.event.sender.login }}" -m ":ci skip all :ci run dl"
git push origin --force ${{ github.event.ref }}:release git push origin --force ${{ github.event.ref }}:release
- name: Get target commitish
id: get_target
run: |
echo "head_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" echo "head_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Update master - name: Update master
if: vars.PUSH_VERSION_COMMIT != '' if: vars.PUSH_VERSION_COMMIT != '' && !inputs.prerelease
run: git push origin ${{ github.event.ref }} run: git push origin ${{ github.event.ref }}
publish_pypi_homebrew: build:
needs: prepare needs: prepare
uses: ./.github/workflows/build.yml
with:
version: ${{ needs.prepare.outputs.version }}
channel: ${{ needs.prepare.outputs.channel }}
permissions:
contents: read
packages: write # For package cache
secrets:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
publish_pypi_homebrew:
needs: [prepare, build]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -77,7 +120,7 @@ jobs:
env: env:
TWINE_USERNAME: __token__ TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
if: env.TWINE_PASSWORD != '' if: env.TWINE_PASSWORD != '' && !inputs.prerelease
run: | run: |
rm -rf dist/* rm -rf dist/*
make pypi-files make pypi-files
@ -89,7 +132,7 @@ jobs:
env: env:
BREW_TOKEN: ${{ secrets.BREW_TOKEN }} BREW_TOKEN: ${{ secrets.BREW_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
if: env.BREW_TOKEN != '' && env.PYPI_TOKEN != '' if: env.BREW_TOKEN != '' && env.PYPI_TOKEN != '' && !inputs.prerelease
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
repository: yt-dlp/homebrew-taps repository: yt-dlp/homebrew-taps
@ -100,7 +143,7 @@ jobs:
env: env:
BREW_TOKEN: ${{ secrets.BREW_TOKEN }} BREW_TOKEN: ${{ secrets.BREW_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
if: env.BREW_TOKEN != '' && env.PYPI_TOKEN != '' if: env.BREW_TOKEN != '' && env.PYPI_TOKEN != '' && !inputs.prerelease
run: | run: |
python devscripts/update-formulae.py taps/Formula/yt-dlp.rb "${{ needs.prepare.outputs.version }}" python devscripts/update-formulae.py taps/Formula/yt-dlp.rb "${{ needs.prepare.outputs.version }}"
git -C taps/ config user.name github-actions git -C taps/ config user.name github-actions
@ -108,22 +151,13 @@ jobs:
git -C taps/ commit -am 'yt-dlp: ${{ needs.prepare.outputs.version }}' git -C taps/ commit -am 'yt-dlp: ${{ needs.prepare.outputs.version }}'
git -C taps/ push git -C taps/ push
build:
needs: prepare
uses: ./.github/workflows/build.yml
with:
version: ${{ needs.prepare.outputs.version }}
permissions:
contents: read
packages: write # For package cache
secrets:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
publish: publish:
needs: [prepare, build] needs: [prepare, build]
uses: ./.github/workflows/publish.yml uses: ./.github/workflows/publish.yml
permissions: permissions:
contents: write contents: write
with: with:
channel: ${{ needs.prepare.outputs.channel }}
prerelease: ${{ inputs.prerelease }}
version: ${{ needs.prepare.outputs.version }} version: ${{ needs.prepare.outputs.version }}
target_commitish: ${{ needs.prepare.outputs.head_sha }} target_commitish: ${{ needs.prepare.outputs.head_sha }}

View file

@ -51,7 +51,7 @@ def get_git_head():
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Update the version.py file') parser = argparse.ArgumentParser(description='Update the version.py file')
parser.add_argument( parser.add_argument(
'-c', '--channel', choices=['stable', 'nightly'], default='stable', '-c', '--channel', default='stable',
help='Select update channel (default: %(default)s)') help='Select update channel (default: %(default)s)')
parser.add_argument( parser.add_argument(
'-o', '--output', default='yt_dlp/version.py', '-o', '--output', default='yt_dlp/version.py',