Skip to content
Latchkey

Nightly CI workflow (xarray-contrib/pint-xarray)

The Nightly CI workflow from xarray-contrib/pint-xarray, explained and optimized by Latchkey.

A

CI health: A - excellent

Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: xarray-contrib/pint-xarray.github/workflows/nightly.ymlLicense Apache-2.0View source

What it does

This is the Nightly 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 nightly CI
name: Nightly CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  schedule:
    - cron: "0 0 * * *" # Daily "At 00:00" UTC
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions: {}

jobs:
  detect-test-upstream-trigger:
    name: "Detect CI Trigger: [test-upstream]"
    if: |
      github.repository_owner == 'xarray-contrib'
      && (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: "[test-upstream]"

  upstream-dev:
    name: upstream-dev
    runs-on: ubuntu-latest
    needs: detect-test-upstream-trigger

    if: |
      always()
      && github.repository_owner == 'xarray-contrib'
      && (
        (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
        || needs.detect-test-upstream-trigger.outputs.triggered == 'true'
        || (
          github.event_name == 'pull_request'
          && contains(github.event.pull_request.labels.*.name, 'run-upstream')
        )
      )

    outputs:
      artifacts_availability: ${{ steps.status.outputs.ARTIFACTS_AVAILABLE }}

    env:
      FORCE_COLOR: 3

    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

      - name: setup environment
        uses: prefix-dev/setup-pixi@5185adfbffb4bd703da3010310260805d89ebb11 # v0.9.6
        with:
          environments: "nightly"
          locked: false
          frozen: false
          cache: false

      - name: import pint-xarray
        run: |
          pixi run -e nightly python -c 'import pint_xarray'

      - name: run tests
        if: success()
        id: status
        run: |
          pixi run -e nightly tests -rf --report-log=pytest-log.jsonl

      - name: upload the log file
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: log file
          path: pytest-log.jsonl

  create-issue:
    name: Report failures
    runs-on: ubuntu-latest
    needs: upstream-dev

    if: |
      always()
      && needs.upstream-dev.result == 'failure'
      && github.repository == 'xarray-contrib/pint-xarray'
      && github.event_name == 'schedule'

    permissions:
      issues: write # open issues if the tests failed

    steps:
      - name: download log file
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: log file

      - name: report failures
        uses: scientific-python/issue-from-pytest-log@8e905db353437cda1d6a773de245343fbfc940dd # v1.5.0
        with:
          log-path: pytest-log.jsonl

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

# adapted from xarray's nightly CI
name: Nightly CI
 
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  schedule:
    - cron: "0 0 * * *" # Daily "At 00:00" UTC
  workflow_dispatch:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
permissions: {}
 
jobs:
  detect-test-upstream-trigger:
    timeout-minutes: 30
    name: "Detect CI Trigger: [test-upstream]"
    if: |
      github.repository_owner == 'xarray-contrib'
      && (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: "[test-upstream]"
 
  upstream-dev:
    timeout-minutes: 30
    name: upstream-dev
    runs-on: latchkey-small
    needs: detect-test-upstream-trigger
 
    if: |
      always()
      && github.repository_owner == 'xarray-contrib'
      && (
        (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
        || needs.detect-test-upstream-trigger.outputs.triggered == 'true'
        || (
          github.event_name == 'pull_request'
          && contains(github.event.pull_request.labels.*.name, 'run-upstream')
        )
      )
 
    outputs:
      artifacts_availability: ${{ steps.status.outputs.ARTIFACTS_AVAILABLE }}
 
    env:
      FORCE_COLOR: 3
 
    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
 
      - name: setup environment
        uses: prefix-dev/setup-pixi@5185adfbffb4bd703da3010310260805d89ebb11 # v0.9.6
        with:
          environments: "nightly"
          locked: false
          frozen: false
          cache: false
 
      - name: import pint-xarray
        run: |
          pixi run -e nightly python -c 'import pint_xarray'
 
      - name: run tests
        if: success()
        id: status
        run: |
          pixi run -e nightly tests -rf --report-log=pytest-log.jsonl
 
      - name: upload the log file
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: log file
          path: pytest-log.jsonl
 
  create-issue:
    timeout-minutes: 30
    name: Report failures
    runs-on: latchkey-small
    needs: upstream-dev
 
    if: |
      always()
      && needs.upstream-dev.result == 'failure'
      && github.repository == 'xarray-contrib/pint-xarray'
      && github.event_name == 'schedule'
 
    permissions:
      issues: write # open issues if the tests failed
 
    steps:
      - name: download log file
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: log file
 
      - name: report failures
        uses: scientific-python/issue-from-pytest-log@8e905db353437cda1d6a773de245343fbfc940dd # v1.5.0
        with:
          log-path: pytest-log.jsonl
 

What changed

This workflow runs 3 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