Skip to content
Latchkey

Release workflow (johnhuang316/code-index-mcp)

The Release workflow from johnhuang316/code-index-mcp, 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: johnhuang316/code-index-mcp.github/workflows/publish-to-pypi.ymlLicense MITView source

What it does

This is the Release workflow from the johnhuang316/code-index-mcp repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Release

on:
  release:
    types: [published]
  workflow_dispatch:
    inputs:
      tag:
        description: 'Release tag (vX.Y.Z) to re-run publish flow'
        required: true
        type: string

concurrency:
  group: release-${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', github.event.inputs.tag) || github.ref }}
  cancel-in-progress: false

jobs:
  verify-and-build:
    runs-on: ubuntu-latest
    env:
      RELEASE_REF: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', github.event.inputs.tag) || github.ref }}
      RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          ref: ${{ env.RELEASE_REF }}

      - name: Ensure tag points to default branch
        run: |
          git fetch origin
          TARGET_BRANCH=$(git remote show origin | awk '/HEAD branch/ {print $NF}')
          if [ -z "$TARGET_BRANCH" ]; then
            TARGET_BRANCH=master
          fi
          if ! git merge-base --is-ancestor "$(git rev-parse HEAD)" "origin/${TARGET_BRANCH}"; then
            echo "::error::Release tag must point to a commit reachable from ${TARGET_BRANCH}"
            exit 1
          fi

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.10'

      - name: Install uv
        run: python -m pip install --upgrade pip uv

      - name: Cache uv environments
        uses: actions/cache@v4
        with:
          path: |
            .venv
            .uv-cache
          key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
          restore-keys: |
            uv-${{ runner.os }}-

      - name: Install dependencies
        run: uv sync --frozen

      - name: Install build tooling
        run: uv pip install build twine

      - name: Build distributions
        run: uv run python -m build

      - name: Twine check
        run: uv run twine check dist/*

      - name: Upload dist artifacts
        uses: actions/upload-artifact@v4
        with:
          name: dist-${{ env.RELEASE_TAG }}
          path: dist/*
          retention-days: 7

  publish:
    needs: verify-and-build
    runs-on: ubuntu-latest
    environment:
      name: production
    env:
      RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
    steps:
      - name: Download build artifacts
        uses: actions/download-artifact@v4
        with:
          name: dist-${{ env.RELEASE_TAG }}
          path: dist

      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          packages-dir: dist
          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: Release
 
on:
  release:
    types: [published]
  workflow_dispatch:
    inputs:
      tag:
        description: 'Release tag (vX.Y.Z) to re-run publish flow'
        required: true
        type: string
 
concurrency:
  group: release-${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', github.event.inputs.tag) || github.ref }}
  cancel-in-progress: false
 
jobs:
  verify-and-build:
    timeout-minutes: 30
    runs-on: latchkey-small
    env:
      RELEASE_REF: ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', github.event.inputs.tag) || github.ref }}
      RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          ref: ${{ env.RELEASE_REF }}
 
      - name: Ensure tag points to default branch
        run: |
          git fetch origin
          TARGET_BRANCH=$(git remote show origin | awk '/HEAD branch/ {print $NF}')
          if [ -z "$TARGET_BRANCH" ]; then
            TARGET_BRANCH=master
          fi
          if ! git merge-base --is-ancestor "$(git rev-parse HEAD)" "origin/${TARGET_BRANCH}"; then
            echo "::error::Release tag must point to a commit reachable from ${TARGET_BRANCH}"
            exit 1
          fi
 
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          cache: 'pip'
          python-version: '3.10'
 
      - name: Install uv
        run: python -m pip install --upgrade pip uv
 
      - name: Cache uv environments
        uses: actions/cache@v4
        with:
          path: |
            .venv
            .uv-cache
          key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
          restore-keys: |
            uv-${{ runner.os }}-
 
      - name: Install dependencies
        run: uv sync --frozen
 
      - name: Install build tooling
        run: uv pip install build twine
 
      - name: Build distributions
        run: uv run python -m build
 
      - name: Twine check
        run: uv run twine check dist/*
 
      - name: Upload dist artifacts
        uses: actions/upload-artifact@v4
        with:
          name: dist-${{ env.RELEASE_TAG }}
          path: dist/*
          retention-days: 7
 
  publish:
    timeout-minutes: 30
    needs: verify-and-build
    runs-on: latchkey-small
    environment:
      name: production
    env:
      RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
    steps:
      - name: Download build artifacts
        uses: actions/download-artifact@v4
        with:
          name: dist-${{ env.RELEASE_TAG }}
          path: dist
 
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          packages-dir: dist
          password: ${{ secrets.PYPI_API_TOKEN }}
 

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.

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