Skip to content
Latchkey

Build workflow (pydata/numexpr)

The Build workflow from pydata/numexpr, explained and optimized by Latchkey.

F

CI health: F - at risk

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: pydata/numexpr.github/workflows/build.ymlLicense MITView source

What it does

This is the Build workflow from the pydata/numexpr 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: Build

on: [push, pull_request]

permissions:
  contents: read

jobs:
  build_wheels:
    name: Build and test on ${{ matrix.os }}${{ matrix.numpy-version && format(' (numpy {0})', matrix.numpy-version) || '' }} for ${{ matrix.arch }}
    runs-on: ${{ matrix.runs-on || matrix.os }}
    permissions:
      contents: write
    env:
      CIBW_ARCHS_LINUX: ${{ matrix.arch }}
      CIBW_ARCHS_MACOS: "x86_64 arm64"
      CIBW_ENABLE: cpython-freethreading

    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux x86_64 (build wheels)
          - os: ubuntu-latest
            arch: x86_64
            artifact_name: "linux-x86_64"
            python-version: "3.x"

          # Linux x86_64 (test numpy 1.26)
          - os: ubuntu-latest
            arch: x86_64
            artifact_name: "linux-x86_64_numpy1_26"
            python-version: "3.12"
            numpy-version: "1.26"

          # Linux ARM64 (build wheels)
          - os: ubuntu-24.04-arm
            arch: aarch64
            artifact_name: "linux-aarch64"
            python-version: "3.x"

          # Windows (build wheels)
          - os: windows-latest
            arch: x86_64
            artifact_name: "windows-x86_64"
            python-version: "3.x"

          # Windows ARM64 (build wheels)
          - os: windows-11-arm
            arch: aarch64
            artifact_name: "windows-arm64"
            python-version: "3.x"

          # macOS (build wheels)
          - os: macos-latest
            arch: x86_64
            artifact_name: "macos-universal2"
            python-version: "3.x"

    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-python@v3
        name: Install Python
        with:
          python-version: ${{ matrix.python-version }}

      # Run tests with specific numpy version
      - name: Install and test with specific numpy version
        if: matrix.numpy-version
        run: |
          pip install "numpy==${{ matrix.numpy-version }}.*"
          pip install -e .
          pip install pytest
          python -m pytest

      # Build wheels only if:
      #   - No numpy version is specified
      #   - Python version is "3.x"
      - name: Build wheels
        if: ${{ !matrix.numpy-version }}
        uses: pypa/cibuildwheel@v3.1.3

      - name: Make sdist
        if: ${{ matrix.os == 'windows-latest' && !matrix.numpy-version }}
        run: |
          python -m pip install build
          python -m build --sdist --outdir wheelhouse .

      - uses: actions/upload-artifact@v4
        if: ${{ !matrix.numpy-version }}
        with:
          name: ${{ matrix.artifact_name }}
          path: ./wheelhouse/*

      - name: Upload to GitHub Release
        if: startsWith(github.ref, 'refs/tags/') && !matrix.numpy-version
        uses: softprops/action-gh-release@v1
        with:
          files: wheelhouse/*

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
 
on: [push, pull_request]
 
permissions:
  contents: read
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build_wheels:
    timeout-minutes: 30
    name: Build and test on ${{ matrix.os }}${{ matrix.numpy-version && format(' (numpy {0})', matrix.numpy-version) || '' }} for ${{ matrix.arch }}
    runs-on: ${{ matrix.runs-on || matrix.os }}
    permissions:
      contents: write
    env:
      CIBW_ARCHS_LINUX: ${{ matrix.arch }}
      CIBW_ARCHS_MACOS: "x86_64 arm64"
      CIBW_ENABLE: cpython-freethreading
 
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux x86_64 (build wheels)
          - os: ubuntu-latest
            arch: x86_64
            artifact_name: "linux-x86_64"
            python-version: "3.x"
 
          # Linux x86_64 (test numpy 1.26)
          - os: ubuntu-latest
            arch: x86_64
            artifact_name: "linux-x86_64_numpy1_26"
            python-version: "3.12"
            numpy-version: "1.26"
 
          # Linux ARM64 (build wheels)
          - os: ubuntu-24.04-arm
            arch: aarch64
            artifact_name: "linux-aarch64"
            python-version: "3.x"
 
          # Windows (build wheels)
          - os: windows-latest
            arch: x86_64
            artifact_name: "windows-x86_64"
            python-version: "3.x"
 
          # Windows ARM64 (build wheels)
          - os: windows-11-arm
            arch: aarch64
            artifact_name: "windows-arm64"
            python-version: "3.x"
 
          # macOS (build wheels)
          - os: macos-latest
            arch: x86_64
            artifact_name: "macos-universal2"
            python-version: "3.x"
 
    steps:
      - uses: actions/checkout@v3
 
      - uses: actions/setup-python@v3
        name: Install Python
        with:
          cache: 'pip'
          python-version: ${{ matrix.python-version }}
 
      # Run tests with specific numpy version
      - name: Install and test with specific numpy version
        if: matrix.numpy-version
        run: |
          pip install "numpy==${{ matrix.numpy-version }}.*"
          pip install -e .
          pip install pytest
          python -m pytest
 
      # Build wheels only if:
      #   - No numpy version is specified
      #   - Python version is "3.x"
      - name: Build wheels
        if: ${{ !matrix.numpy-version }}
        uses: pypa/cibuildwheel@v3.1.3
 
      - name: Make sdist
        if: ${{ matrix.os == 'windows-latest' && !matrix.numpy-version }}
        run: |
          python -m pip install build
          python -m build --sdist --outdir wheelhouse .
 
      - uses: actions/upload-artifact@v4
        if: ${{ !matrix.numpy-version }}
        with:
          name: ${{ matrix.artifact_name }}
          path: ./wheelhouse/*
 
      - name: Upload to GitHub Release
        if: startsWith(github.ref, 'refs/tags/') && !matrix.numpy-version
        uses: softprops/action-gh-release@v1
        with:
          files: wheelhouse/*
 

What changed

2 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 per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow