Skip to content
Latchkey

Upload Package to PyPI workflow (xarray-contrib/pint-xarray)

The Upload Package to PyPI workflow from xarray-contrib/pint-xarray, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get caching, 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/pypi.yamlLicense Apache-2.0View source

What it does

This is the Upload Package to PyPI 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)
name: Upload Package to PyPI

on:
  release:
    types:
      - published
  pull_request:
    branches:
      - main

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

permissions: {}

jobs:
  build-artifacts:
    name: Build packages
    runs-on: ubuntu-latest
    if: |
      github.repository == 'xarray-contrib/pint-xarray'
      && (
        github.event_name == 'release'
        || contains(github.event.pull_request.labels.*.name, 'release')
      )

    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          fetch-depth: 0
          persist-credentials: false

      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        name: Install Python
        with:
          python-version: "3.x"

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install build twine

      - name: Build tarball and wheels
        run: |
          git clean -xdf
          git restore -SW .
          python -m build --outdir dist/ .

      - name: Check built artifacts
        run: |
          python -m twine check --strict dist/*
          pwd
          if [ -f dist/pint-xarray-0.0.0.tar.gz ]; then
            echo "❌ INVALID VERSION NUMBER"
            exit 1
          else
            echo "✅ Looks good"
          fi
      - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: releases
          path: dist

  upload-to-pypi:
    name: Upload to PyPI
    needs: build-artifacts
    if: github.event_name == 'release'
    runs-on: ubuntu-latest

    environment:
      name: pypi
      url: https://pypi.org/p/pint-xarray
    permissions:
      id-token: write # upload packages to pypi

    steps:
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: releases
          path: dist
      - name: Publish package to PyPI
        uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
        with:
          verbose: true

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: Upload Package to PyPI
 
on:
  release:
    types:
      - published
  pull_request:
    branches:
      - main
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
permissions: {}
 
jobs:
  build-artifacts:
    timeout-minutes: 30
    name: Build packages
    runs-on: latchkey-small
    if: |
      github.repository == 'xarray-contrib/pint-xarray'
      && (
        github.event_name == 'release'
        || contains(github.event.pull_request.labels.*.name, 'release')
      )
 
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          fetch-depth: 0
          persist-credentials: false
 
      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        name: Install Python
        with:
          cache: 'pip'
          python-version: "3.x"
 
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install build twine
 
      - name: Build tarball and wheels
        run: |
          git clean -xdf
          git restore -SW .
          python -m build --outdir dist/ .
 
      - name: Check built artifacts
        run: |
          python -m twine check --strict dist/*
          pwd
          if [ -f dist/pint-xarray-0.0.0.tar.gz ]; then
            echo "❌ INVALID VERSION NUMBER"
            exit 1
          else
            echo "✅ Looks good"
          fi
      - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: releases
          path: dist
 
  upload-to-pypi:
    timeout-minutes: 30
    name: Upload to PyPI
    needs: build-artifacts
    if: github.event_name == 'release'
    runs-on: latchkey-small
 
    environment:
      name: pypi
      url: https://pypi.org/p/pint-xarray
    permissions:
      id-token: write # upload packages to pypi
 
    steps:
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: releases
          path: dist
      - name: Publish package to PyPI
        uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
        with:
          verbose: true
 

What changed

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 2 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