Skip to content
Latchkey

Create wheel workflow (sqlalchemy/sqlalchemy)

The Create wheel workflow from sqlalchemy/sqlalchemy, explained and optimized by Latchkey.

C

CI health: C - fair

Run this on Latchkey for self-healing, caching, and up to 58% lower cost.

Grade your own workflow free or run it on Latchkey →
Source: sqlalchemy/sqlalchemy.github/workflows/create-wheels.yamlLicense MITView source

What it does

This is the Create wheel workflow from the sqlalchemy/sqlalchemy 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

workflow (.yml)
name: Create wheel

on:
  # run when a release has been created
  release:
    types: [created]
  # push:
  #   branches:
  #     - "go_wheel_*"

permissions:
  id-token: write
  contents: write

# env:
#   # comment TWINE_REPOSITORY_URL to use the real pypi. NOTE: change also the secret used in TWINE_PASSWORD
#   TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/

jobs:
  build_wheels:
    name: ${{ matrix.wheel_mode }} wheels ${{ matrix.python }} on ${{ matrix.os }} ${{ matrix.os == 'ubuntu-22.04' && matrix.linux_archs || '' }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        # emulated wheels on linux take too much time, split wheels into multiple runs
        python:
          - "cp310-* cp311-*"
          - "cp312-* cp313-* cp314-*"
          - "cp314t-*"
        wheel_mode:
          - compiled
        os:
          - "windows-2022"
          - "windows-11-arm"
          - "macos-15"
          - "ubuntu-22.04"
          - "ubuntu-22.04-arm"
        linux_archs:
          # this is only meaningful on linux. windows and macos ignore exclude all but one arch
          - "aarch64"
          - "x86_64"
          - "riscv64"

        include:
          # create pure python build
          - os: ubuntu-22.04
            wheel_mode: pure-python
            python: "cp-314*"

        exclude:
          - os: "windows-2022"
            linux_archs: "aarch64"
          # ignored on windows, just avoid to run it multiple times
          - os: "windows-11-arm"
            linux_archs: "aarch64"
          - os: "macos-15"
            linux_archs: "x86_64"
          - os: "ubuntu-22.04"
            linux_archs: "aarch64"
          - os: "ubuntu-22.04-arm"
            linux_archs: "x86_64"
          - os: "windows-2022"
            linux_archs: "riscv64"
          - os: "windows-11-arm"
            linux_archs: "riscv64"
          - os: "macos-15"
            linux_archs: "riscv64"
          - os: "ubuntu-22.04-arm"
            linux_archs: "riscv64"

      fail-fast: false

    steps:
      - uses: actions/checkout@v7

      # See details at https://cibuildwheel.readthedocs.io/en/stable/faq/#emulation
      - name: Set up QEMU
        if: matrix.linux_archs == 'riscv64'
        uses: docker/setup-qemu-action@v4
        with:
          platforms: riscv64

      - name: Remove tag-build from pyproject.toml
        # sqlalchemy has `tag-build` set to `dev` in pyproject.toml. It needs to be removed before creating the wheel
        # otherwise it gets tagged with `dev0`
        shell: pwsh
        # This is equivalent to the sed commands:
        # `sed -i '/tag-build="dev"/d' pyproject.toml`
        # `sed -i '/tag-build = "dev"/d' pyproject.toml`

        # `-replace` uses a regexp match
        run: |
          (get-content pyproject.toml) | %{$_ -replace 'tag-build.?=.?"dev"',""} | set-content pyproject.toml

      - name: Build compiled wheels
        if: ${{ matrix.wheel_mode == 'compiled' }}
        uses: pypa/cibuildwheel@v4.1.0
        env:
          CIBW_ARCHS_LINUX: ${{ matrix.linux_archs }}
          CIBW_BUILD: ${{ matrix.python }}
          # setting it here does not work on linux
          # PYTHONNOUSERSITE: "1"


      - name: Set up Python for pure-python wheel
        uses: actions/setup-python@v6
        with:
          python-version: "3.14"

      - name: Build pure-python wheel
        if: ${{ matrix.wheel_mode == 'pure-python' && runner.os == 'Linux' }}
        run: |
          python -m pip install --upgrade pip
          pip --version
          pip install build
          pip list
          DISABLE_SQLALCHEMY_CEXT=y python -m build --wheel --outdir ./wheelhouse

      # - uses: actions/upload-artifact@v3
      #   with:
      #     path: ./wheelhouse/*.whl

      - name: Upload wheels to release
        # upload the generated wheels to the github release
        continue-on-error: true
        uses: sqlalchemyorg/upload-release-assets@sa
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          files: './wheelhouse/*.whl'

      - name: Generate attestations
        id: attestations
        continue-on-error: true
        shell: bash
        env:
          PYTHONUTF8: "1"
        run: |
          python -m pip install pypi-attestations
          python -m pypi_attestations sign ./wheelhouse/*

      - name: Publish wheel
        shell: bash
        run: |
          python -m pip install "twine>=6.2.0"
          if [[ "${{ steps.attestations.outcome }}" == "success" ]]; then
            python -m twine upload --skip-existing --attestations ./wheelhouse/*
          else
            python -m twine upload --skip-existing ./wheelhouse/*
          fi

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 wheel
 
on:
  # run when a release has been created
  release:
    types: [created]
  # push:
  #   branches:
  #     - "go_wheel_*"
 
permissions:
  id-token: write
  contents: write
 
# env:
#   # comment TWINE_REPOSITORY_URL to use the real pypi. NOTE: change also the secret used in TWINE_PASSWORD
#   TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
 
jobs:
  build_wheels:
    timeout-minutes: 30
    name: ${{ matrix.wheel_mode }} wheels ${{ matrix.python }} on ${{ matrix.os }} ${{ matrix.os == 'ubuntu-22.04' && matrix.linux_archs || '' }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        # emulated wheels on linux take too much time, split wheels into multiple runs
        python:
          - "cp310-* cp311-*"
          - "cp312-* cp313-* cp314-*"
          - "cp314t-*"
        wheel_mode:
          - compiled
        os:
          - "windows-2022"
          - "windows-11-arm"
          - "macos-15"
          - "ubuntu-22.04"
          - "ubuntu-22.04-arm"
        linux_archs:
          # this is only meaningful on linux. windows and macos ignore exclude all but one arch
          - "aarch64"
          - "x86_64"
          - "riscv64"
 
        include:
          # create pure python build
          - os: ubuntu-22.04
            wheel_mode: pure-python
            python: "cp-314*"
 
        exclude:
          - os: "windows-2022"
            linux_archs: "aarch64"
          # ignored on windows, just avoid to run it multiple times
          - os: "windows-11-arm"
            linux_archs: "aarch64"
          - os: "macos-15"
            linux_archs: "x86_64"
          - os: "ubuntu-22.04"
            linux_archs: "aarch64"
          - os: "ubuntu-22.04-arm"
            linux_archs: "x86_64"
          - os: "windows-2022"
            linux_archs: "riscv64"
          - os: "windows-11-arm"
            linux_archs: "riscv64"
          - os: "macos-15"
            linux_archs: "riscv64"
          - os: "ubuntu-22.04-arm"
            linux_archs: "riscv64"
 
      fail-fast: false
 
    steps:
      - uses: actions/checkout@v7
 
      # See details at https://cibuildwheel.readthedocs.io/en/stable/faq/#emulation
      - name: Set up QEMU
        if: matrix.linux_archs == 'riscv64'
        uses: docker/setup-qemu-action@v4
        with:
          platforms: riscv64
 
      - name: Remove tag-build from pyproject.toml
        # sqlalchemy has `tag-build` set to `dev` in pyproject.toml. It needs to be removed before creating the wheel
        # otherwise it gets tagged with `dev0`
        shell: pwsh
        # This is equivalent to the sed commands:
        # `sed -i '/tag-build="dev"/d' pyproject.toml`
        # `sed -i '/tag-build = "dev"/d' pyproject.toml`
 
        # `-replace` uses a regexp match
        run: |
          (get-content pyproject.toml) | %{$_ -replace 'tag-build.?=.?"dev"',""} | set-content pyproject.toml
 
      - name: Build compiled wheels
        if: ${{ matrix.wheel_mode == 'compiled' }}
        uses: pypa/cibuildwheel@v4.1.0
        env:
          CIBW_ARCHS_LINUX: ${{ matrix.linux_archs }}
          CIBW_BUILD: ${{ matrix.python }}
          # setting it here does not work on linux
          # PYTHONNOUSERSITE: "1"
 
 
      - name: Set up Python for pure-python wheel
        uses: actions/setup-python@v6
        with:
          cache: 'pip'
          python-version: "3.14"
 
      - name: Build pure-python wheel
        if: ${{ matrix.wheel_mode == 'pure-python' && runner.os == 'Linux' }}
        run: |
          python -m pip install --upgrade pip
          pip --version
          pip install build
          pip list
          DISABLE_SQLALCHEMY_CEXT=y python -m build --wheel --outdir ./wheelhouse
 
      # - uses: actions/upload-artifact@v3
      #   with:
      #     path: ./wheelhouse/*.whl
 
      - name: Upload wheels to release
        # upload the generated wheels to the github release
        continue-on-error: true
        uses: sqlalchemyorg/upload-release-assets@sa
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          files: './wheelhouse/*.whl'
 
      - name: Generate attestations
        id: attestations
        continue-on-error: true
        shell: bash
        env:
          PYTHONUTF8: "1"
        run: |
          python -m pip install pypi-attestations
          python -m pypi_attestations sign ./wheelhouse/*
 
      - name: Publish wheel
        shell: bash
        run: |
          python -m pip install "twine>=6.2.0"
          if [[ "${{ steps.attestations.outcome }}" == "success" ]]; then
            python -m twine upload --skip-existing --attestations ./wheelhouse/*
          else
            python -m twine upload --skip-existing ./wheelhouse/*
          fi
 

What changed

3 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 1 job (45 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow