CI workflow (xarray-contrib/pint-xarray)
The CI workflow from xarray-contrib/pint-xarray, explained and optimized by Latchkey.
A
CI health: A - excellent
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the CI workflow from the xarray-contrib/pint-xarray 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)
# adapted from xarray's ci
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: {}
jobs:
detect-skip-ci-trigger:
name: "Detect CI Trigger: [skip-ci]"
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-slim
outputs:
triggered: ${{ steps.detect-trigger.outputs.trigger-found }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 2
persist-credentials: false
- uses: xarray-contrib/ci-trigger@10cd2bfec3484946a4058a421ddf9cfad101e715 # v1.2.1
id: detect-trigger
with:
keyword: "[skip-ci]"
cache-pixi-lock:
name: "Cache pixi lock"
needs: detect-skip-ci-trigger
runs-on: ubuntu-slim
if: |
always()
&& github.repository == 'xarray-contrib/pint-xarray'
&& (
github.event_name == 'workflow_dispatch' || github.event_name == 'push'
|| (
github.event_name == 'pull_request'
&& (
needs.detect-skip-ci-trigger.outputs.triggered == 'false'
&& !contains(github.event.pull_request.labels.*.name, 'skip-ci')
)
)
)
outputs:
cache-key: ${{ steps.pixi-lock.outputs.cache-key }}
pixi-version: ${{ steps.pixi-lock.outputs.pixi-version }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- uses: Parcels-code/pixi-lock/create-and-cache@38495788b79a5ff26009aecc15daa9a8310b8832 # v0.1.0
id: pixi-lock
ci:
name: ${{ matrix.os }} ${{ matrix.env }}
runs-on: ${{ matrix.os }}
needs: cache-pixi-lock
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
env: ["ci-py311", "ci-py313", "ci-py314"]
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
env:
FORCE_COLOR: 3
ENV: ${{ matrix.env }}
RUNNER_OS: ${{ matrix.os }}
steps:
- name: checkout the repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
# need to fetch all tags to get a correct version
fetch-depth: 0 # fetch all branches and tags
persist-credentials: false
- uses: Parcels-code/pixi-lock/restore@38495788b79a5ff26009aecc15daa9a8310b8832 # v0.1.0
with:
cache-key: ${{ needs.cache-pixi-lock.outputs.cache-key }}
- name: setup environment
uses: prefix-dev/setup-pixi@5185adfbffb4bd703da3010310260805d89ebb11 # v0.9.6
with:
pixi-version: "${{ needs.cache-pixi-lock.outputs.pixi-version }}"
frozen: true
cache: true
environments: "${{ matrix.env }}"
- name: investigate env variables
run: |
echo PYTHON_VERSION=$(pixi run -e $ENV python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') >> $GITHUB_ENV
- name: import pint-xarray
run: |
pixi run -e $ENV python -c 'import pint_xarray'
- name: run tests
if: success()
id: status
run: |
pixi run -e $ENV tests --cov-report=xml
- name: Upload code coverage to Codecov
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
token: "${{ secrets.CODECOV_TOKEN }}" # zizmor: ignore[secrets-outside-env] codecov token
files: ./coverage.xml
flags: unittests
env_vars: RUNNER_OS,PYTHON_VERSION
name: codecov-umbrella
fail_ci_if_error: false
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
# adapted from xarray's ci name: CI on: push: branches: [main] pull_request: branches: [main] workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true permissions: {} jobs: detect-skip-ci-trigger: timeout-minutes: 30 name: "Detect CI Trigger: [skip-ci]" if: github.event_name == 'push' || github.event_name == 'pull_request' runs-on: ubuntu-slim outputs: triggered: ${{ steps.detect-trigger.outputs.trigger-found }} steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: fetch-depth: 2 persist-credentials: false - uses: xarray-contrib/ci-trigger@10cd2bfec3484946a4058a421ddf9cfad101e715 # v1.2.1 id: detect-trigger with: keyword: "[skip-ci]" cache-pixi-lock: timeout-minutes: 30 name: "Cache pixi lock" needs: detect-skip-ci-trigger runs-on: ubuntu-slim if: | always() && github.repository == 'xarray-contrib/pint-xarray' && ( github.event_name == 'workflow_dispatch' || github.event_name == 'push' || ( github.event_name == 'pull_request' && ( needs.detect-skip-ci-trigger.outputs.triggered == 'false' && !contains(github.event.pull_request.labels.*.name, 'skip-ci') ) ) ) outputs: cache-key: ${{ steps.pixi-lock.outputs.cache-key }} pixi-version: ${{ steps.pixi-lock.outputs.pixi-version }} steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: persist-credentials: false - uses: Parcels-code/pixi-lock/create-and-cache@38495788b79a5ff26009aecc15daa9a8310b8832 # v0.1.0 id: pixi-lock ci: timeout-minutes: 30 name: ${{ matrix.os }} ${{ matrix.env }} runs-on: ${{ matrix.os }} needs: cache-pixi-lock defaults: run: shell: bash -l {0} strategy: fail-fast: false matrix: env: ["ci-py311", "ci-py313", "ci-py314"] os: ["ubuntu-latest", "macos-latest", "windows-latest"] env: FORCE_COLOR: 3 ENV: ${{ matrix.env }} RUNNER_OS: ${{ matrix.os }} steps: - name: checkout the repository uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: # need to fetch all tags to get a correct version fetch-depth: 0 # fetch all branches and tags persist-credentials: false - uses: Parcels-code/pixi-lock/restore@38495788b79a5ff26009aecc15daa9a8310b8832 # v0.1.0 with: cache-key: ${{ needs.cache-pixi-lock.outputs.cache-key }} - name: setup environment uses: prefix-dev/setup-pixi@5185adfbffb4bd703da3010310260805d89ebb11 # v0.9.6 with: pixi-version: "${{ needs.cache-pixi-lock.outputs.pixi-version }}" frozen: true cache: true environments: "${{ matrix.env }}" - name: investigate env variables run: | echo PYTHON_VERSION=$(pixi run -e $ENV python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') >> $GITHUB_ENV - name: import pint-xarray run: | pixi run -e $ENV python -c 'import pint_xarray' - name: run tests if: success() id: status run: | pixi run -e $ENV tests --cov-report=xml - name: Upload code coverage to Codecov uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 with: token: "${{ secrets.CODECOV_TOKEN }}" # zizmor: ignore[secrets-outside-env] codecov token files: ./coverage.xml flags: unittests env_vars: RUNNER_OS,PYTHON_VERSION name: codecov-umbrella fail_ci_if_error: false
What changed
- Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 3 jobs (11 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.