Wheel building and publishing workflow (gumyr/build123d)
The Wheel building and publishing workflow from gumyr/build123d, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Wheel building and publishing workflow from the gumyr/build123d 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
name: Wheel building and publishing
on: [push, pull_request, workflow_dispatch] # TODO: update this later
permissions: {}
jobs:
build_wheel:
# This does the actual wheel building or if triggered manually via the workflow dispatch, or for a tag.
# this job does NOT publish the wheel
name: Build wheel on ubuntu-latest
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
if: (github.repository == 'gumyr/build123d' && ( startsWith(github.ref, 'refs/tags/v'))) || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
with:
persist-credentials: false
fetch-depth: 0 # get all history for setuptools_scm
- name: Build sdist and wheel
shell: bash
run: |
pwd
ls -lR
python3 -V
python3 -m pip install --upgrade pip
python3 -m pip -V
python3 -m pip install build
python3 -m build --outdir wheelhouse
python3 -m pip freeze
ls -lR
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a #v7.0.1
with:
path: ./wheelhouse/build123d*.* # store the build123d wheel and sdist
upload_pypi:
needs: [build_wheel]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/build123d
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
# or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this)
if: needs.build_wheel.result == 'success'
#if: (github.repository == 'gumyr/build123d' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
steps:
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 #v7.0.0
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b #v1.14.0
# with: # for testing with test.pypi.org
# To test: repository-url: https://test.pypi.org/legacy/
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Wheel building and publishing on: [push, pull_request, workflow_dispatch] # TODO: update this later permissions: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build_wheel: timeout-minutes: 30 # This does the actual wheel building or if triggered manually via the workflow dispatch, or for a tag. # this job does NOT publish the wheel name: Build wheel on ubuntu-latest runs-on: latchkey-small permissions: contents: read actions: write if: (github.repository == 'gumyr/build123d' && ( startsWith(github.ref, 'refs/tags/v'))) || github.event_name == 'workflow_dispatch' steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2 with: persist-credentials: false fetch-depth: 0 # get all history for setuptools_scm - name: Build sdist and wheel shell: bash run: | pwd ls -lR python3 -V python3 -m pip install --upgrade pip python3 -m pip -V python3 -m pip install build python3 -m build --outdir wheelhouse python3 -m pip freeze ls -lR - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a #v7.0.1 with: path: ./wheelhouse/build123d*.* # store the build123d wheel and sdist upload_pypi: timeout-minutes: 30 needs: [build_wheel] runs-on: latchkey-small environment: name: pypi url: https://pypi.org/p/build123d permissions: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing # or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this) if: needs.build_wheel.result == 'success' #if: (github.repository == 'gumyr/build123d' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) steps: - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 #v7.0.0 with: # unpacks default artifact into dist/ # if `name: artifact` is omitted, the action will create extra parent dir name: artifact path: dist - uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b #v1.14.0 # with: # for testing with test.pypi.org # To test: repository-url: https://test.pypi.org/legacy/
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.
- 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 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.