Skip to content
Latchkey

Publish to PyPI workflow (thinkst/opencanary)

The Publish to PyPI workflow from thinkst/opencanary, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get caching, 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: thinkst/opencanary.github/workflows/publish.ymlLicense BSD-3-ClauseView source

What it does

This is the Publish to PyPI workflow from the thinkst/opencanary repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.

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

The workflow

workflow (.yml)
name: Publish to PyPI
on:
  release:
    types:
      - published

  workflow_dispatch:

jobs:
  pypi-publish:
    name: Upload release to PyPI
    runs-on: ubuntu-latest
    environment:
      name: release
      url: https://pypi.org/p/opencanary
    permissions:
      id-token: write  # IMPORTANT: this permission is mandatory for trusted publishing
    steps:
    # retrieve your distributions here
    - name: Set up Python
      uses: actions/setup-python@v3
    - name: "Check out repository code"
      uses: "actions/checkout@v6"
    - name: Install uv
      uses: astral-sh/setup-uv@v7
    - name: Install setuptools
      run: pip3 install setuptools>=63.2.0
    - name: Install wheel
      run: pip3 install wheel
    - name: Build package distributions
      run: uv build
    - name: check version matches tag
      run: |
            uv pip install --system dist/*.tar.gz
            version_to_release=$(opencanaryd --version)
            tag_name="${{ github.event.release.tag_name }}"
            tag_name_without_v="${tag_name#v}"
            if [[ "$version_to_release" == "$tag_name_without_v" ]]; then
                echo "Versions match - may it be a great release"
                exit 0
            else
              echo "Versions do not match - not publishing"
              echo "Opencanary version is: $version_to_release"
              echo "Git tag is: $tag_name -> $tag_name_without_v"
              exit 1
            fi
    - name: Publish
      run: uv publish

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: Publish to PyPI
on:
  release:
    types:
      - published
 
  workflow_dispatch:
 
jobs:
  pypi-publish:
    timeout-minutes: 30
    name: Upload release to PyPI
    runs-on: latchkey-small
    environment:
      name: release
      url: https://pypi.org/p/opencanary
    permissions:
      id-token: write  # IMPORTANT: this permission is mandatory for trusted publishing
    steps:
    # retrieve your distributions here
    - name: Set up Python
      uses: actions/setup-python@v3
      with:
        cache: 'pip'
    - name: "Check out repository code"
      uses: "actions/checkout@v6"
    - name: Install uv
      uses: astral-sh/setup-uv@v7
    - name: Install setuptools
      run: pip3 install setuptools>=63.2.0
    - name: Install wheel
      run: pip3 install wheel
    - name: Build package distributions
      run: uv build
    - name: check version matches tag
      run: |
            uv pip install --system dist/*.tar.gz
            version_to_release=$(opencanaryd --version)
            tag_name="${{ github.event.release.tag_name }}"
            tag_name_without_v="${tag_name#v}"
            if [[ "$version_to_release" == "$tag_name_without_v" ]]; then
                echo "Versions match - may it be a great release"
                exit 0
            else
              echo "Versions do not match - not publishing"
              echo "Opencanary version is: $version_to_release"
              echo "Git tag is: $tag_name -> $tag_name_without_v"
              exit 1
            fi
    - name: Publish
      run: uv publish
 

What changed

1 third-party action is referenced by a movable tag. Pin it 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 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow