Skip to content
Latchkey

Release workflow (MagicStack/asyncpg)

The Release workflow from MagicStack/asyncpg, explained and optimized by Latchkey.

F

CI health: F - at risk

Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: MagicStack/asyncpg.github/workflows/release.ymlLicense Apache-2.0View source

What it does

This is the Release workflow from the MagicStack/asyncpg repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Release

on:
  pull_request:
    branches:
      - "master"
      - "ci"
      - "[0-9]+.[0-9x]+*"
    paths:
      - "asyncpg/_version.py"

jobs:
  validate-release-request:
    runs-on: ubuntu-latest
    steps:
    - name: Validate release PR
      uses: edgedb/action-release/validate-pr@master
      id: checkver
      with:
        require_team: Release Managers
        require_approval: no
        github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
        version_file: asyncpg/_version.py
        version_line_pattern: |
          __version__(?:\s*:\s*typing\.Final)?\s*=\s*(?:['"])([[:PEP440:]])(?:['"])

    - name: Stop if not approved
      if: steps.checkver.outputs.approved != 'true'
      run: |
        echo ::error::PR is not approved yet.
        exit 1

    - name: Store release version for later use
      env:
        VERSION: ${{ steps.checkver.outputs.version }}
      run: |
        mkdir -p dist/
        echo "${VERSION}" > dist/VERSION

    - uses: actions/upload-artifact@v4
      with:
        name: dist-version
        path: dist/VERSION

  build-sdist:
    needs: validate-release-request
    runs-on: ubuntu-latest

    env:
      PIP_DISABLE_PIP_VERSION_CHECK: 1

    steps:
    - uses: actions/checkout@v5
      with:
        fetch-depth: 50
        submodules: true
        persist-credentials: false

    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        python-version: "3.x"

    - name: Build source distribution
      run: |
        pip install -U setuptools wheel pip
        python setup.py sdist

    - uses: actions/upload-artifact@v4
      with:
        name: dist-sdist
        path: dist/*.tar.*

  build-wheels-matrix:
    needs: validate-release-request
    runs-on: ubuntu-latest
    outputs:
      include: ${{ steps.set-matrix.outputs.include }}
    steps:
      - uses: actions/checkout@v5
        with:
          persist-credentials: false
      - uses: actions/setup-python@v6
        with:
          python-version: "3.x"
      - run: pip install cibuildwheel==3.3.0
      - id: set-matrix
        run: |
          MATRIX_INCLUDE=$(
            {
              cibuildwheel --print-build-identifiers --platform linux --archs x86_64,aarch64 | grep cp |  jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \
              && cibuildwheel --print-build-identifiers --platform macos --archs x86_64,arm64 | grep cp |  jq -nRc '{"only": inputs, "os": "macos-latest"}' \
              && cibuildwheel --print-build-identifiers --platform windows --archs x86,AMD64 | grep cp |  jq -nRc '{"only": inputs, "os": "windows-latest"}'
            } | jq -sc
          )
          echo "include=$MATRIX_INCLUDE" >> $GITHUB_OUTPUT

  build-wheels:
    needs: build-wheels-matrix
    runs-on: ${{ matrix.os }}
    name: Build ${{ matrix.only }}

    strategy:
      fail-fast: false
      matrix:
        include: ${{ fromJson(needs.build-wheels-matrix.outputs.include) }}

    defaults:
      run:
        shell: bash

    env:
      PIP_DISABLE_PIP_VERSION_CHECK: 1

    steps:
    - uses: actions/checkout@v5
      with:
        fetch-depth: 50
        submodules: true
        persist-credentials: false

    - name: Set up QEMU
      if: runner.os == 'Linux'
      uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392  # v3.6.0

    - uses: pypa/cibuildwheel@63fd63b352a9a8bdcc24791c9dbee952ee9a8abc  # v3.3.0
      with:
        only: ${{ matrix.only }}
      env:
        CIBW_BUILD_VERBOSITY: 1

    - uses: actions/upload-artifact@v4
      with:
        name: dist-wheels-${{ matrix.only }}
        path: wheelhouse/*.whl

  merge-artifacts:
    runs-on: ubuntu-latest
    needs: [build-sdist, build-wheels]
    steps:
      - name: Merge Artifacts
        uses: actions/upload-artifact/merge@v4
        with:
          name: dist
          delete-merged: true

  publish-docs:
    needs: [build-sdist, build-wheels]
    runs-on: ubuntu-latest

    env:
      PIP_DISABLE_PIP_VERSION_CHECK: 1

    steps:
    - name: Checkout source
      uses: actions/checkout@v5
      with:
        fetch-depth: 5
        submodules: true
        persist-credentials: false

    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        python-version: "3.x"

    - name: Build docs
      run: |
        pip install --group docs
        pip install -e .
        make htmldocs

    - name: Checkout gh-pages
      uses: actions/checkout@v5
      with:
        fetch-depth: 5
        ref: gh-pages
        path: docs/gh-pages
        persist-credentials: false

    - name: Sync docs
      run: |
        rsync -a docs/_build/html/ docs/gh-pages/current/

    - name: Commit and push docs
      uses: magicstack/gha-commit-and-push@master
      with:
        target_branch: gh-pages
        workdir: docs/gh-pages
        commit_message: Automatic documentation update
        github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
        ssh_key: ${{ secrets.RELEASE_BOT_SSH_KEY }}
        gpg_key: ${{ secrets.RELEASE_BOT_GPG_KEY }}
        gpg_key_id: "5C468778062D87BF!"

  publish:
    needs: [build-sdist, build-wheels, publish-docs]
    runs-on: ubuntu-latest

    environment:
      name: pypi
      url: https://pypi.org/p/asyncpg
    permissions:
      id-token: write
      attestations: write
      contents: write
      deployments: write

    steps:
    - uses: actions/checkout@v5
      with:
        fetch-depth: 5
        submodules: false
        persist-credentials: false

    - uses: actions/download-artifact@v4
      with:
        name: dist
        path: dist/

    - name: Extract Release Version
      id: relver
      run: |
        set -e
        echo "version=$(cat dist/VERSION)" >> $GITHUB_OUTPUT
        rm dist/VERSION

    - name: Merge and tag the PR
      uses: edgedb/action-release/merge@master
      with:
        github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
        ssh_key: ${{ secrets.RELEASE_BOT_SSH_KEY }}
        gpg_key: ${{ secrets.RELEASE_BOT_GPG_KEY }}
        gpg_key_id: "5C468778062D87BF!"
        tag_name: v${{ steps.relver.outputs.version }}

    - name: Publish Github Release
      uses: elprans/gh-action-create-release@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: v${{ steps.relver.outputs.version }}
        release_name: v${{ steps.relver.outputs.version }}
        target: ${{ github.event.pull_request.base.ref }}
        body: ${{ github.event.pull_request.body }}

    - run: |
        ls -al dist/

    - name: Upload to PyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        attestations: true

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: Release
 
on:
  pull_request:
    branches:
      - "master"
      - "ci"
      - "[0-9]+.[0-9x]+*"
    paths:
      - "asyncpg/_version.py"
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  validate-release-request:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
    - name: Validate release PR
      uses: edgedb/action-release/validate-pr@master
      id: checkver
      with:
        require_team: Release Managers
        require_approval: no
        github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
        version_file: asyncpg/_version.py
        version_line_pattern: |
          __version__(?:\s*:\s*typing\.Final)?\s*=\s*(?:['"])([[:PEP440:]])(?:['"])
 
    - name: Stop if not approved
      if: steps.checkver.outputs.approved != 'true'
      run: |
        echo ::error::PR is not approved yet.
        exit 1
 
    - name: Store release version for later use
      env:
        VERSION: ${{ steps.checkver.outputs.version }}
      run: |
        mkdir -p dist/
        echo "${VERSION}" > dist/VERSION
 
    - uses: actions/upload-artifact@v4
      with:
        name: dist-version
        path: dist/VERSION
 
  build-sdist:
    timeout-minutes: 30
    needs: validate-release-request
    runs-on: latchkey-small
 
    env:
      PIP_DISABLE_PIP_VERSION_CHECK: 1
 
    steps:
    - uses: actions/checkout@v5
      with:
        fetch-depth: 50
        submodules: true
        persist-credentials: false
 
    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        cache: 'pip'
        python-version: "3.x"
 
    - name: Build source distribution
      run: |
        pip install -U setuptools wheel pip
        python setup.py sdist
 
    - uses: actions/upload-artifact@v4
      with:
        name: dist-sdist
        path: dist/*.tar.*
 
  build-wheels-matrix:
    timeout-minutes: 30
    needs: validate-release-request
    runs-on: latchkey-small
    outputs:
      include: ${{ steps.set-matrix.outputs.include }}
    steps:
      - uses: actions/checkout@v5
        with:
          persist-credentials: false
      - uses: actions/setup-python@v6
        with:
          cache: 'pip'
          python-version: "3.x"
      - run: pip install cibuildwheel==3.3.0
      - id: set-matrix
        run: |
          MATRIX_INCLUDE=$(
            {
              cibuildwheel --print-build-identifiers --platform linux --archs x86_64,aarch64 | grep cp |  jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \
              && cibuildwheel --print-build-identifiers --platform macos --archs x86_64,arm64 | grep cp |  jq -nRc '{"only": inputs, "os": "macos-latest"}' \
              && cibuildwheel --print-build-identifiers --platform windows --archs x86,AMD64 | grep cp |  jq -nRc '{"only": inputs, "os": "windows-latest"}'
            } | jq -sc
          )
          echo "include=$MATRIX_INCLUDE" >> $GITHUB_OUTPUT
 
  build-wheels:
    timeout-minutes: 30
    needs: build-wheels-matrix
    runs-on: ${{ matrix.os }}
    name: Build ${{ matrix.only }}
 
    strategy:
      fail-fast: false
      matrix:
        include: ${{ fromJson(needs.build-wheels-matrix.outputs.include) }}
 
    defaults:
      run:
        shell: bash
 
    env:
      PIP_DISABLE_PIP_VERSION_CHECK: 1
 
    steps:
    - uses: actions/checkout@v5
      with:
        fetch-depth: 50
        submodules: true
        persist-credentials: false
 
    - name: Set up QEMU
      if: runner.os == 'Linux'
      uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392  # v3.6.0
 
    - uses: pypa/cibuildwheel@63fd63b352a9a8bdcc24791c9dbee952ee9a8abc  # v3.3.0
      with:
        only: ${{ matrix.only }}
      env:
        CIBW_BUILD_VERBOSITY: 1
 
    - uses: actions/upload-artifact@v4
      with:
        name: dist-wheels-${{ matrix.only }}
        path: wheelhouse/*.whl
 
  merge-artifacts:
    timeout-minutes: 30
    runs-on: latchkey-small
    needs: [build-sdist, build-wheels]
    steps:
      - name: Merge Artifacts
        uses: actions/upload-artifact/merge@v4
        with:
          name: dist
          delete-merged: true
 
  publish-docs:
    timeout-minutes: 30
    needs: [build-sdist, build-wheels]
    runs-on: latchkey-small
 
    env:
      PIP_DISABLE_PIP_VERSION_CHECK: 1
 
    steps:
    - name: Checkout source
      uses: actions/checkout@v5
      with:
        fetch-depth: 5
        submodules: true
        persist-credentials: false
 
    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        cache: 'pip'
        python-version: "3.x"
 
    - name: Build docs
      run: |
        pip install --group docs
        pip install -e .
        make htmldocs
 
    - name: Checkout gh-pages
      uses: actions/checkout@v5
      with:
        fetch-depth: 5
        ref: gh-pages
        path: docs/gh-pages
        persist-credentials: false
 
    - name: Sync docs
      run: |
        rsync -a docs/_build/html/ docs/gh-pages/current/
 
    - name: Commit and push docs
      uses: magicstack/gha-commit-and-push@master
      with:
        target_branch: gh-pages
        workdir: docs/gh-pages
        commit_message: Automatic documentation update
        github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
        ssh_key: ${{ secrets.RELEASE_BOT_SSH_KEY }}
        gpg_key: ${{ secrets.RELEASE_BOT_GPG_KEY }}
        gpg_key_id: "5C468778062D87BF!"
 
  publish:
    timeout-minutes: 30
    needs: [build-sdist, build-wheels, publish-docs]
    runs-on: latchkey-small
 
    environment:
      name: pypi
      url: https://pypi.org/p/asyncpg
    permissions:
      id-token: write
      attestations: write
      contents: write
      deployments: write
 
    steps:
    - uses: actions/checkout@v5
      with:
        fetch-depth: 5
        submodules: false
        persist-credentials: false
 
    - uses: actions/download-artifact@v4
      with:
        name: dist
        path: dist/
 
    - name: Extract Release Version
      id: relver
      run: |
        set -e
        echo "version=$(cat dist/VERSION)" >> $GITHUB_OUTPUT
        rm dist/VERSION
 
    - name: Merge and tag the PR
      uses: edgedb/action-release/merge@master
      with:
        github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
        ssh_key: ${{ secrets.RELEASE_BOT_SSH_KEY }}
        gpg_key: ${{ secrets.RELEASE_BOT_GPG_KEY }}
        gpg_key_id: "5C468778062D87BF!"
        tag_name: v${{ steps.relver.outputs.version }}
 
    - name: Publish Github Release
      uses: elprans/gh-action-create-release@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: v${{ steps.relver.outputs.version }}
        release_name: v${{ steps.relver.outputs.version }}
        target: ${{ github.event.pull_request.base.ref }}
        body: ${{ github.event.pull_request.body }}
 
    - run: |
        ls -al dist/
 
    - name: Upload to PyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        attestations: true
 

What changed

4 third-party actions are referenced by a movable tag. Pin them to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.

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:

This workflow runs 7 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow