Skip to content
Latchkey

Publish to PyPI workflow (neuralgcm/neuralgcm)

The Publish to PyPI workflow from neuralgcm/neuralgcm, explained and optimized by Latchkey.

B

CI health: B - good

Point runs-on at Latchkey and get run de-duplication, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: neuralgcm/neuralgcm.github/workflows/publish-job.ymlLicense Apache-2.0View source

What it does

This is the Publish to PyPI workflow from the neuralgcm/neuralgcm 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: Publish to PyPI

on:
  # Triggers when commits are pushed to the main branch, e.g., by merging a PR
  push:
    branches: [ main ]
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  # Auto-publish when version is increased
  publish-job:
    # Only try to publish if:
    # * Repo is self (prevents running from forks)
    # * Branch is `main`
    if: |
      github.repository == 'neuralgcm/neuralgcm'
      && github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    permissions:
      contents: write
    timeout-minutes: 30

    steps:
    # Publish the package (if local `__version__` > pip version)
    - uses: etils-actions/pypi-auto-publish@v1
      with:
        pypi-token: ${{ secrets.PYPI_API_TOKEN }}
        gh-token: ${{ secrets.GITHUB_TOKEN }}
        parse-changelog: false

The same workflow, on Latchkey

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

name: Publish to PyPI
 
on:
  # Triggers when commits are pushed to the main branch, e.g., by merging a PR
  push:
    branches: [ main ]
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  # Auto-publish when version is increased
  publish-job:
    # Only try to publish if:
    # * Repo is self (prevents running from forks)
    # * Branch is `main`
    if: |
      github.repository == 'neuralgcm/neuralgcm'
      && github.ref == 'refs/heads/main'
    runs-on: latchkey-small
    permissions:
      contents: write
    timeout-minutes: 30
 
    steps:
    # Publish the package (if local `__version__` > pip version)
    - uses: etils-actions/pypi-auto-publish@v1
      with:
        pypi-token: ${{ secrets.PYPI_API_TOKEN }}
        gh-token: ${{ secrets.GITHUB_TOKEN }}
        parse-changelog: false
 

What changed

1 third-party action is referenced by a movable tag. Pin it to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.