CI workflow (ZeroIntensity/pointers.py)
The CI workflow from ZeroIntensity/pointers.py, explained and optimized by Latchkey.
CI health: B - good
Point runs-on at Latchkey and get job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the CI workflow from the ZeroIntensity/pointers.py 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
name: CI
on:
push:
tags:
- v*
pull_request:
branches:
- master
concurrency:
group: build-${{ github.head_ref }}
cancel-in-progress: true
env:
CIBW_SKIP: >
pp*
jobs:
binary-wheels-standard:
name: Binary wheels for ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
with:
# Fetch all tags
fetch-depth: 0
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_ARCHS_MACOS: x86_64
HATCH_BUILD_HOOKS_ENABLE: "true"
- uses: actions/upload-artifact@v2
with:
name: artifacts
path: wheelhouse/*.whl
if-no-files-found: error
binary-wheels-arm:
name: Build Linux wheels for ARM
runs-on: ubuntu-latest
# Very slow, no need to run on PRs
if: >
github.event_name == 'push'
&&
(github.ref == 'refs/heads/master' || startsWith(github.event.ref, 'refs/tags'))
steps:
- uses: actions/checkout@v2
with:
# Fetch all tags
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: arm64
- name: Build wheels
uses: pypa/cibuildwheel@v2.15.0
env:
CIBW_ARCHS_LINUX: aarch64
HATCH_BUILD_HOOKS_ENABLE: "true"
- uses: actions/upload-artifact@v2
with:
name: artifacts
path: wheelhouse/*.whl
if-no-files-found: error
publish:
name: Publish release
needs:
- binary-wheels-standard
- binary-wheels-arm
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
steps:
- uses: actions/download-artifact@v2
with:
name: artifacts
path: dist
- name: Push build artifacts to PyPI
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
skip_existing: true
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: CI on: push: tags: - v* pull_request: branches: - master concurrency: group: build-${{ github.head_ref }} cancel-in-progress: true env: CIBW_SKIP: > pp* jobs: binary-wheels-standard: timeout-minutes: 30 name: Binary wheels for ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v2 with: # Fetch all tags fetch-depth: 0 - name: Build wheels uses: pypa/cibuildwheel@v2.16.5 env: CIBW_ARCHS_MACOS: x86_64 HATCH_BUILD_HOOKS_ENABLE: "true" - uses: actions/upload-artifact@v2 with: name: artifacts path: wheelhouse/*.whl if-no-files-found: error binary-wheels-arm: timeout-minutes: 30 name: Build Linux wheels for ARM runs-on: latchkey-small # Very slow, no need to run on PRs if: > github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.event.ref, 'refs/tags')) steps: - uses: actions/checkout@v2 with: # Fetch all tags fetch-depth: 0 - name: Set up QEMU uses: docker/setup-qemu-action@v1 with: platforms: arm64 - name: Build wheels uses: pypa/cibuildwheel@v2.15.0 env: CIBW_ARCHS_LINUX: aarch64 HATCH_BUILD_HOOKS_ENABLE: "true" - uses: actions/upload-artifact@v2 with: name: artifacts path: wheelhouse/*.whl if-no-files-found: error publish: timeout-minutes: 30 name: Publish release needs: - binary-wheels-standard - binary-wheels-arm runs-on: latchkey-small if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') steps: - uses: actions/download-artifact@v2 with: name: artifacts path: dist - name: Push build artifacts to PyPI uses: pypa/gh-action-pypi-publish@v1.4.2 with: skip_existing: true user: __token__ password: ${{ secrets.PYPI_API_TOKEN }}
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. - Add a job timeout so a hung step cannot burn hours of runner time.
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.
This workflow runs 3 jobs (5 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.