Skip to content
Latchkey

Build workflow (powerapi-ng/powerapi)

The Build workflow from powerapi-ng/powerapi, explained and optimized by Latchkey.

D

CI health: D - needs work

Point runs-on at Latchkey and get caching, run de-duplication, 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: powerapi-ng/powerapi.github/workflows/build.ymlLicense BSD-3-ClauseView source

What it does

This is the Build workflow from the powerapi-ng/powerapi repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.

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

The workflow

workflow (.yml)
name: Build

on:
  push:
    branches: ["master"]
  pull_request:
    branches: ["master"]

permissions:
  contents: read

jobs:
  run-tests:
    name: Run linters and unit tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.12", "3.x"]

    steps:
    - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install uv
      uses: astral-sh/setup-uv@d31148d669074a8d0a63714ba94f3201e7020bc3 # v8.3.0

    - name: Install dependencies
      run: |
        uv sync --extra everything --dev

    - name: Run ruff
      run: |
        uv run ruff check --output-format=github src/ tests/

    - name: Run unit tests with coverage
      run: |
        uv run pytest --cov=powerapi --cov-report=term --cov-report=xml tests/unit

    - name: Upload coverage reports to Codecov
      uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
      with:
        token: ${{ secrets.CODECOV_TOKEN }}

  build-container-image:
    name: Build container image
    runs-on: ubuntu-latest

    steps:
      - name: Setup Docker buildx
        uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0

      - name: Build image
        uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
        with:
          push: false
          provenance: false
          load: true
          tags: localbuild/powerapi:sha-${{ github.sha }}
          build-args: |
            POWERAPI_INSTALL_METHOD=local

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: Build
 
on:
  push:
    branches: ["master"]
  pull_request:
    branches: ["master"]
 
permissions:
  contents: read
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  run-tests:
    timeout-minutes: 30
    name: Run linters and unit tests
    runs-on: latchkey-small
    strategy:
      matrix:
        python-version: ["3.12", "3.x"]
 
    steps:
    - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
 
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
      with:
        cache: 'pip'
        python-version: ${{ matrix.python-version }}
 
    - name: Install uv
      uses: astral-sh/setup-uv@d31148d669074a8d0a63714ba94f3201e7020bc3 # v8.3.0
 
    - name: Install dependencies
      run: |
        uv sync --extra everything --dev
 
    - name: Run ruff
      run: |
        uv run ruff check --output-format=github src/ tests/
 
    - name: Run unit tests with coverage
      run: |
        uv run pytest --cov=powerapi --cov-report=term --cov-report=xml tests/unit
 
    - name: Upload coverage reports to Codecov
      uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
 
  build-container-image:
    timeout-minutes: 30
    name: Build container image
    runs-on: latchkey-small
 
    steps:
      - name: Setup Docker buildx
        uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
 
      - name: Build image
        uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
        with:
          push: false
          provenance: false
          load: true
          tags: localbuild/powerapi:sha-${{ github.sha }}
          build-args: |
            POWERAPI_INSTALL_METHOD=local
 

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 (3 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow