Skip to content
Latchkey

Publish to PyPI workflow (OML-Team/open-metric-learning)

The Publish to PyPI workflow from OML-Team/open-metric-learning, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get caching, job timeouts, 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: OML-Team/open-metric-learning.github/workflows/publish-to-pypi.ymlLicense Apache-2.0View source

What it does

This is the Publish to PyPI workflow from the OML-Team/open-metric-learning 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:
  workflow_run:
    workflows:
      - Tests
    types:
      - completed
    branches:
      - main
    workflow_dispatch:

jobs:
  autotag:
    name: Create tag if the commit has new version implemented
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    outputs:
      tagcreated: ${{ steps.autotag.outputs.tagcreated }}
    steps:
      - uses: actions/checkout@v4

      - name: Autotag
        id: autotag
        uses: butlerlogic/action-autotag@1.1.2
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
        with:
          strategy: regex
          root: "oml/__init__.py"
          regex_pattern: >
            ^__version__ = ['"]([^'"]*)['"]
          tag_prefix: "release."

  build_and_publish_to_pypi:
    name: Build and publish Python distribution to PyPI
    needs: autotag
    if: ${{ needs.autotag.outputs.tagcreated == 'yes' }}
    runs-on: ubuntu-24.04
    steps:
    - uses: actions/checkout@v4

    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: "3.10.0"

    - name: Build a binary wheel
      run: |
        make build_wheel

    - name: Publish distribution to PyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        password: ${{ secrets.PYPI_API_TOKEN }}

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: Publish to PyPI
 
on:
  workflow_run:
    workflows:
      - Tests
    types:
      - completed
    branches:
      - main
    workflow_dispatch:
 
jobs:
  autotag:
    timeout-minutes: 30
    name: Create tag if the commit has new version implemented
    runs-on: latchkey-small
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    outputs:
      tagcreated: ${{ steps.autotag.outputs.tagcreated }}
    steps:
      - uses: actions/checkout@v4
 
      - name: Autotag
        id: autotag
        uses: butlerlogic/action-autotag@1.1.2
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
        with:
          strategy: regex
          root: "oml/__init__.py"
          regex_pattern: >
            ^__version__ = ['"]([^'"]*)['"]
          tag_prefix: "release."
 
  build_and_publish_to_pypi:
    timeout-minutes: 30
    name: Build and publish Python distribution to PyPI
    needs: autotag
    if: ${{ needs.autotag.outputs.tagcreated == 'yes' }}
    runs-on: latchkey-small
    steps:
    - uses: actions/checkout@v4
 
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        cache: 'pip'
        python-version: "3.10.0"
 
    - name: Build a binary wheel
      run: |
        make build_wheel
 
    - name: Publish distribution to PyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        password: ${{ secrets.PYPI_API_TOKEN }}
 

What changed

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