Skip to content
Latchkey

Deployment # Keep the action badge icon short workflow (partcad/partcad)

The Deployment # Keep the action badge icon short workflow from partcad/partcad, explained and optimized by Latchkey.

F

CI health: F - at risk

Point runs-on at Latchkey and get caching, run de-duplication, 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: partcad/partcad.github/workflows/deploy.ymlLicense Apache-2.0View source

What it does

This is the Deployment # Keep the action badge icon short workflow from the partcad/partcad 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)
# Deployment to PyPI
name: Deployment # Keep the action badge icon short

on:
  push:
    branches:
      - "main"
    tags:
      - "**"

permissions:
  contents: write

jobs:
  # Keep the "build" job identical to "python-build.yml".
  # TODO(clairbee): include "python-build.yml" instead
  build:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-24.04]
        python-version: ["3.11"]
    runs-on: ${{ matrix.os }}
    env:
      BIN_DIR: ${{ matrix.os == 'windows-latest' && 'Scripts' || 'bin' }}

    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - uses: actions/cache@v4
        id: cache
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-build-pip-${{ hashFiles('**/requirements.*') }}
          restore-keys: |
            ${{ runner.os }}-build-pip-
      - name: Prepare environments
        run: |
          python -m pip install --upgrade pip build
          mkdir .venv
          python -m venv .venv/build
          (. .venv/build/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
          python -m venv .venv/build-cli
          (. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
          python -m venv .venv/install
          (. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
          sudo apt install --yes libcairo2-dev python3-dev
      - name: Test building and packaging
        run: |
          (. .venv/build/${{ env.BIN_DIR }}/activate && cd partcad && python -m build && cd .. && deactivate)
          (. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad/requirements.txt && deactivate)
          (. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad/dist partcad && deactivate)
          cp README.md partcad-cli
          (. .venv/build-cli/${{ env.BIN_DIR }}/activate && cd partcad-cli && python -m build && cd .. && deactivate)
      - name: Test installation
        run: |
          (. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad/requirements.txt     && deactivate)
          (. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad/dist     partcad && deactivate)
          (. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad-cli/requirements.txt && deactivate)
          (. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad-cli/dist partcad-cli && deactivate)
      # Upload artifact from the selected OS/Python version combination only
      - name: Upload "partcad"
        if: ${{ matrix.os == 'ubuntu-24.04' && matrix.python-version == '3.11' }}
        uses: actions/upload-artifact@v4
        with:
          name: python-package-distributions
          path: partcad/dist/
      - name: Upload "partcad-cli"
        if: ${{ matrix.os == 'ubuntu-24.04' && matrix.python-version == '3.11' }}
        uses: actions/upload-artifact@v4
        with:
          name: python-package-distributions-cli
          path: partcad-cli/dist/

  publish-to-pypi:
    name: Publish to PyPI
    needs:
      - build
    runs-on: ubuntu-24.04
    environment:
      name: pypi

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

      - name: Download lib dists
        uses: actions/download-artifact@v4
        with:
          name: python-package-distributions
          path: dist

      - name: Download cli dists
        uses: actions/download-artifact@v4
        with:
          name: python-package-distributions-cli
          path: dist

      - name: Determine the release tag
        if: github.ref == 'refs/heads/main'
        run: |
          git clone https://github.com/partcad/partcad partcad-git;
          cd partcad-git;
          echo "MERGED_TAG=$(git describe --abbrev=0)" >> "${GITHUB_ENV}"

      - name: Create GitHub Release
        if: github.ref == 'refs/heads/main'
        env:
          GITHUB_TOKEN: ${{ github.token }}
        run: |
          gh release create '${{ env.MERGED_TAG }}' --repo '${{ github.repository }}' --notes "";
          gh release upload '${{ env.MERGED_TAG }}' dist/** --repo '${{ github.repository }}'

      - name: Publish distribution to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          repository-url:
            "${{ github.ref == 'refs/heads/main' && 'https://upload.pypi.org/legacy/' || 'https://test.pypi.org/legacy/'
            }}"
          user: __token__
          password: "${{ github.ref == 'refs/heads/main' &&  secrets.PYPI_KEY || secrets.TEST_PYPI_KEY }}"

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.

# Deployment to PyPI
name: Deployment # Keep the action badge icon short
 
on:
  push:
    branches:
      - "main"
    tags:
      - "**"
 
permissions:
  contents: write
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  # Keep the "build" job identical to "python-build.yml".
  # TODO(clairbee): include "python-build.yml" instead
  build:
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-24.04]
        python-version: ["3.11"]
    runs-on: ${{ matrix.os }}
    env:
      BIN_DIR: ${{ matrix.os == 'windows-latest' && 'Scripts' || 'bin' }}
 
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          cache: 'pip'
          python-version: ${{ matrix.python-version }}
      - uses: actions/cache@v4
        id: cache
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-build-pip-${{ hashFiles('**/requirements.*') }}
          restore-keys: |
            ${{ runner.os }}-build-pip-
      - name: Prepare environments
        run: |
          python -m pip install --upgrade pip build
          mkdir .venv
          python -m venv .venv/build
          (. .venv/build/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
          python -m venv .venv/build-cli
          (. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
          python -m venv .venv/install
          (. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
          sudo apt install --yes libcairo2-dev python3-dev
      - name: Test building and packaging
        run: |
          (. .venv/build/${{ env.BIN_DIR }}/activate && cd partcad && python -m build && cd .. && deactivate)
          (. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad/requirements.txt && deactivate)
          (. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad/dist partcad && deactivate)
          cp README.md partcad-cli
          (. .venv/build-cli/${{ env.BIN_DIR }}/activate && cd partcad-cli && python -m build && cd .. && deactivate)
      - name: Test installation
        run: |
          (. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad/requirements.txt     && deactivate)
          (. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad/dist     partcad && deactivate)
          (. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad-cli/requirements.txt && deactivate)
          (. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad-cli/dist partcad-cli && deactivate)
      # Upload artifact from the selected OS/Python version combination only
      - name: Upload "partcad"
        if: ${{ matrix.os == 'ubuntu-24.04' && matrix.python-version == '3.11' }}
        uses: actions/upload-artifact@v4
        with:
          name: python-package-distributions
          path: partcad/dist/
      - name: Upload "partcad-cli"
        if: ${{ matrix.os == 'ubuntu-24.04' && matrix.python-version == '3.11' }}
        uses: actions/upload-artifact@v4
        with:
          name: python-package-distributions-cli
          path: partcad-cli/dist/
 
  publish-to-pypi:
    timeout-minutes: 30
    name: Publish to PyPI
    needs:
      - build
    runs-on: latchkey-small
    environment:
      name: pypi
 
    steps:
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          cache: 'pip'
          python-version: "3.11"
 
      - name: Download lib dists
        uses: actions/download-artifact@v4
        with:
          name: python-package-distributions
          path: dist
 
      - name: Download cli dists
        uses: actions/download-artifact@v4
        with:
          name: python-package-distributions-cli
          path: dist
 
      - name: Determine the release tag
        if: github.ref == 'refs/heads/main'
        run: |
          git clone https://github.com/partcad/partcad partcad-git;
          cd partcad-git;
          echo "MERGED_TAG=$(git describe --abbrev=0)" >> "${GITHUB_ENV}"
 
      - name: Create GitHub Release
        if: github.ref == 'refs/heads/main'
        env:
          GITHUB_TOKEN: ${{ github.token }}
        run: |
          gh release create '${{ env.MERGED_TAG }}' --repo '${{ github.repository }}' --notes "";
          gh release upload '${{ env.MERGED_TAG }}' dist/** --repo '${{ github.repository }}'
 
      - name: Publish distribution to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          repository-url:
            "${{ github.ref == 'refs/heads/main' && 'https://upload.pypi.org/legacy/' || 'https://test.pypi.org/legacy/'
            }}"
          user: __token__
          password: "${{ github.ref == 'refs/heads/main' &&  secrets.PYPI_KEY || secrets.TEST_PYPI_KEY }}"
 

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