Create Release and Upload Assets workflow (tangyoha/telegram_media_downloader)
The Create Release and Upload Assets workflow from tangyoha/telegram_media_downloader, explained and optimized by Latchkey.
CI health: D - needs work
Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Create Release and Upload Assets workflow from the tangyoha/telegram_media_downloader repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Create Release and Upload Assets
on:
push:
tags:
- 'v*'
jobs:
build-tdl-binaries:
name: Build tdl binaries for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest] #[macos-latest, ubuntu-20.04, windows-latest]
include:
- os: macos-latest
TARGET: macos
- os: ubuntu-20.04
TARGET: linux-amd64
- os: windows-latest
TARGET: win64
container: ${{ matrix.CONTAINER }}
env:
DISTPATH: tdl-${{ matrix.TARGET }}
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Set up Python 3.11
uses: actions/setup-python@master
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
python3 -m pip install -r requirements.txt
python3 gen_filter_cache.py
pip install pyinstaller==6.7.0
- name: Build with PyInstaller
run: |
pyinstaller --distpath ./${{ env.DISTPATH }} media_downloader.spec
- name: Add license and readme
shell: bash
run: mv README_CN.md README.md ./${{ env.DISTPATH }}
- name: Archive artifact
uses: actions/upload-artifact@master
with:
name: ${{ env.DISTPATH }}
path: ${{ env.DISTPATH }}
# release:
# needs: build-tdl-binaries
# runs-on: ubuntu-latest
# steps:
# - name: Check out code
# uses: actions/checkout@v2
# with:
# fetch-depth: 0
# - name: Get Release Date
# id: release_date
# run: |
# RELEASE_DATE=$(date +%Y-%m-%d)
# echo "RELEASE_DATE=$RELEASE_DATE" | tee -a $GITHUB_ENV
# echo "release_date=$RELEASE_DATE" >> $GITHUB_OUTPUT
# - name: Generate changelog
# id: changelog
# run: |
# PREVIOUS_TAG=$(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
# CURRENT_TAG=${{ github.ref }}
# LOG=$(git log --pretty=format:'* %s by @%an in %H' $PREVIOUS_TAG...$CURRENT_TAG)
# echo "changelog=$LOG" >> $GITHUB_OUTPUT
create_release:
name: Create GitHub release
if: startsWith(github.ref, 'refs/tags/')
needs: build-tdl-binaries
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
steps:
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }},${{ steps.release_date.outputs.release_date }}
draft: false
prerelease: false
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
shell: bash
upload_assets:
name: Upload release assets
if: startsWith(github.ref, 'refs/tags/')
needs: create_release
runs-on: ubuntu-latest
strategy:
matrix:
TARGET: [win64] #[macos, linux-amd64, win64]
env:
DISTPATH: tdl-${{ needs.create_release.outputs.VERSION }}-${{ matrix.TARGET }}
steps:
- name: Download built binaries
uses: actions/download-artifact@master
- name: Rename and package binaries
run: |
zip -r ${{ env.DISTPATH }}.zip ./tdl-${{ matrix.TARGET }}/*
- name: Upload release assets
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: "${{ env.DISTPATH }}.zip"
asset_name: "${{ env.DISTPATH }}.zip"
asset_content_type: application/zip
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: Create Release and Upload Assets on: push: tags: - 'v*' concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build-tdl-binaries: timeout-minutes: 30 name: Build tdl binaries for ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: os: [windows-latest] #[macos-latest, ubuntu-20.04, windows-latest] include: - os: macos-latest TARGET: macos - os: ubuntu-20.04 TARGET: linux-amd64 - os: windows-latest TARGET: win64 container: ${{ matrix.CONTAINER }} env: DISTPATH: tdl-${{ matrix.TARGET }} steps: - name: Checkout repository uses: actions/checkout@master - name: Set up Python 3.11 uses: actions/setup-python@master with: cache: 'pip' python-version: 3.11 - name: Install dependencies run: | python -m pip install --upgrade pip setuptools python3 -m pip install -r requirements.txt python3 gen_filter_cache.py pip install pyinstaller==6.7.0 - name: Build with PyInstaller run: | pyinstaller --distpath ./${{ env.DISTPATH }} media_downloader.spec - name: Add license and readme shell: bash run: mv README_CN.md README.md ./${{ env.DISTPATH }} - name: Archive artifact uses: actions/upload-artifact@master with: name: ${{ env.DISTPATH }} path: ${{ env.DISTPATH }} # release: # needs: build-tdl-binaries # runs-on: latchkey-small # steps: # - name: Check out code # uses: actions/checkout@v2 # with: # fetch-depth: 0 # - name: Get Release Date # id: release_date # run: | # RELEASE_DATE=$(date +%Y-%m-%d) # echo "RELEASE_DATE=$RELEASE_DATE" | tee -a $GITHUB_ENV # echo "release_date=$RELEASE_DATE" >> $GITHUB_OUTPUT # - name: Generate changelog # id: changelog # run: | # PREVIOUS_TAG=$(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`) # CURRENT_TAG=${{ github.ref }} # LOG=$(git log --pretty=format:'* %s by @%an in %H' $PREVIOUS_TAG...$CURRENT_TAG) # echo "changelog=$LOG" >> $GITHUB_OUTPUT create_release: timeout-minutes: 30 name: Create GitHub release if: startsWith(github.ref, 'refs/tags/') needs: build-tdl-binaries runs-on: latchkey-small outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} VERSION: ${{ steps.get_version.outputs.VERSION }} steps: - name: Create release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} with: tag_name: ${{ github.ref }} release_name: ${{ github.ref }},${{ steps.release_date.outputs.release_date }} draft: false prerelease: false - name: Get version id: get_version run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} shell: bash upload_assets: timeout-minutes: 30 name: Upload release assets if: startsWith(github.ref, 'refs/tags/') needs: create_release runs-on: latchkey-small strategy: matrix: TARGET: [win64] #[macos, linux-amd64, win64] env: DISTPATH: tdl-${{ needs.create_release.outputs.VERSION }}-${{ matrix.TARGET }} steps: - name: Download built binaries uses: actions/download-artifact@master - name: Rename and package binaries run: | zip -r ${{ env.DISTPATH }}.zip ./tdl-${{ matrix.TARGET }}/* - name: Upload release assets id: upload-release-asset uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} with: upload_url: ${{ needs.create_release.outputs.upload_url }} asset_path: "${{ env.DISTPATH }}.zip" asset_name: "${{ env.DISTPATH }}.zip" asset_content_type: application/zip
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
This workflow runs 3 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.