Skip to content
Latchkey

Build and Upload cotengra to PyPI workflow (jcmgray/cotengra)

The Build and Upload cotengra to PyPI workflow from jcmgray/cotengra, 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: jcmgray/cotengra.github/workflows/pypi-release.ymlLicense Apache-2.0View source

What it does

This is the Build and Upload cotengra to PyPI workflow from the jcmgray/cotengra 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: Build and Upload cotengra to PyPI
on:
  release:
    types:
      - published
  push:
    tags:
      - 'v*'

jobs:
  build-artifacts:
    runs-on: ubuntu-latest
    if: github.repository == 'jcmgray/cotengra'
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: actions/setup-python@v6
        name: Install Python
        with:
          python-version: "3.12"

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install build twine

      - name: Build tarball and wheels
        run: |
          git clean -xdf
          git restore -SW .
          python -m build

      - name: Check built artifacts
        run: |
          python -m twine check --strict dist/*
          pwd
          if [ -f dist/cotengra-0.0.0.tar.gz ]; then
            echo "❌ INVALID VERSION NUMBER"
            exit 1
          else
            echo "✅ Looks good"
          fi
      - uses: actions/upload-artifact@v7
        with:
          name: releases
          path: dist

  test-built-dist:
    needs: build-artifacts
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-python@v6
        name: Install Python
        with:
          python-version: "3.12"
      - uses: actions/download-artifact@v8
        with:
          name: releases
          path: dist
      - name: List contents of built dist
        run: |
          ls -ltrh
          ls -ltrh dist

      - name: Verify the built dist/wheel is valid
        if: github.event_name == 'push'
        run: |
          python -m pip install --upgrade pip
          python -m pip install dist/cotengra*.whl

  upload-to-test-pypi:
    needs: test-built-dist
    if: github.event_name == 'push'
    runs-on: ubuntu-latest

    environment:
      name: pypi
      url: https://test.pypi.org/p/cotengra
    permissions:
      id-token: write

    steps:
      - uses: actions/download-artifact@v8
        with:
          name: releases
          path: dist
      - name: Publish package to TestPyPI
        if: github.event_name == 'push'
        uses: pypa/gh-action-pypi-publish@v1.14.0
        with:
          repository-url: https://test.pypi.org/legacy/
          verbose: true


  upload-to-pypi:
    needs: test-built-dist
    if: github.event_name == 'release'
    runs-on: ubuntu-latest

    environment:
      name: pypi
      url: https://pypi.org/p/cotengra
    permissions:
      id-token: write

    steps:
      - uses: actions/download-artifact@v8
        with:
          name: releases
          path: dist
      - name: Publish package to PyPI
        uses: pypa/gh-action-pypi-publish@v1.14.0
        with:
          verbose: 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: Build and Upload cotengra to PyPI
on:
  release:
    types:
      - published
  push:
    tags:
      - 'v*'
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build-artifacts:
    timeout-minutes: 30
    runs-on: latchkey-small
    if: github.repository == 'jcmgray/cotengra'
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: actions/setup-python@v6
        name: Install Python
        with:
          cache: 'pip'
          python-version: "3.12"
 
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install build twine
 
      - name: Build tarball and wheels
        run: |
          git clean -xdf
          git restore -SW .
          python -m build
 
      - name: Check built artifacts
        run: |
          python -m twine check --strict dist/*
          pwd
          if [ -f dist/cotengra-0.0.0.tar.gz ]; then
            echo "❌ INVALID VERSION NUMBER"
            exit 1
          else
            echo "✅ Looks good"
          fi
      - uses: actions/upload-artifact@v7
        with:
          name: releases
          path: dist
 
  test-built-dist:
    timeout-minutes: 30
    needs: build-artifacts
    runs-on: latchkey-small
    steps:
      - uses: actions/setup-python@v6
        name: Install Python
        with:
          cache: 'pip'
          python-version: "3.12"
      - uses: actions/download-artifact@v8
        with:
          name: releases
          path: dist
      - name: List contents of built dist
        run: |
          ls -ltrh
          ls -ltrh dist
 
      - name: Verify the built dist/wheel is valid
        if: github.event_name == 'push'
        run: |
          python -m pip install --upgrade pip
          python -m pip install dist/cotengra*.whl
 
  upload-to-test-pypi:
    timeout-minutes: 30
    needs: test-built-dist
    if: github.event_name == 'push'
    runs-on: latchkey-small
 
    environment:
      name: pypi
      url: https://test.pypi.org/p/cotengra
    permissions:
      id-token: write
 
    steps:
      - uses: actions/download-artifact@v8
        with:
          name: releases
          path: dist
      - name: Publish package to TestPyPI
        if: github.event_name == 'push'
        uses: pypa/gh-action-pypi-publish@v1.14.0
        with:
          repository-url: https://test.pypi.org/legacy/
          verbose: true
 
 
  upload-to-pypi:
    timeout-minutes: 30
    needs: test-built-dist
    if: github.event_name == 'release'
    runs-on: latchkey-small
 
    environment:
      name: pypi
      url: https://pypi.org/p/cotengra
    permissions:
      id-token: write
 
    steps:
      - uses: actions/download-artifact@v8
        with:
          name: releases
          path: dist
      - name: Publish package to PyPI
        uses: pypa/gh-action-pypi-publish@v1.14.0
        with:
          verbose: true

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 4 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