Skip to content
Latchkey

CI workflow (google/langfun)

The CI workflow from google/langfun, explained and optimized by Latchkey.

F

CI health: F - at risk

Run this on Latchkey for self-healing, caching, and up to 58% lower cost.

Grade your own workflow free or run it on Latchkey →
Source: google/langfun.github/workflows/ci.yamlLicense Apache-2.0View source

What it does

This is the CI workflow from the google/langfun 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: CI

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main

jobs:
  test-ubuntu:
    name: "pytest on ${{ matrix.python-version }} on ${{ matrix.os }}"
    runs-on: "${{ matrix.os }}"
    strategy:
      matrix:
        python-version: ["3.11", "3.12", "3.13", "3.14"]
        os: [ubuntu-latest]
    env:
      PYTHONPATH: ${{ github.workspace }}
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        pip install pytest
        pip install pytest-xdist
        pip install pytest-cov
        pip install -r requirements.txt
    - name: Test with pytest and generate coverage report
      run: |
        pytest -n auto -p no:threadexception --cov=langfun --cov-report=xml -vv
      timeout-minutes: 10
    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v2
      with:
        file: ./coverage.xml
        token: ${{ secrets.CODECOV_TOKEN }}
        verbose: true
    # The below step just reports the success or failure of tests as a "commit status".
    # This is needed for copybara integration.
    - name: Report success or failure as github status
      if: always()
      shell: bash
      run: |
        status="${{ job.status }}"
        lowercase_status=$(echo $status | tr '[:upper:]' '[:lower:]')
        curl -sS --request POST \
        --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
        --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
        --header 'content-type: application/json' \
        --data '{
           "state": "'$lowercase_status'",
           "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
           "description": "'$status'",
           "context": "github-actions/Build"
           }'

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: CI
 
on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  test-ubuntu:
    timeout-minutes: 30
    name: "pytest on ${{ matrix.python-version }} on ${{ matrix.os }}"
    runs-on: "${{ matrix.os }}"
    strategy:
      matrix:
        python-version: ["3.11", "3.12", "3.13", "3.14"]
        os: [ubuntu-latest]
    env:
      PYTHONPATH: ${{ github.workspace }}
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        cache: 'pip'
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        pip install pytest
        pip install pytest-xdist
        pip install pytest-cov
        pip install -r requirements.txt
    - name: Test with pytest and generate coverage report
      run: |
        pytest -n auto -p no:threadexception --cov=langfun --cov-report=xml -vv
      timeout-minutes: 10
    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v2
      with:
        file: ./coverage.xml
        token: ${{ secrets.CODECOV_TOKEN }}
        verbose: true
    # The below step just reports the success or failure of tests as a "commit status".
    # This is needed for copybara integration.
    - name: Report success or failure as github status
      if: always()
      shell: bash
      run: |
        status="${{ job.status }}"
        lowercase_status=$(echo $status | tr '[:upper:]' '[:lower:]')
        curl -sS --request POST \
        --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
        --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
        --header 'content-type: application/json' \
        --data '{
           "state": "'$lowercase_status'",
           "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
           "description": "'$status'",
           "context": "github-actions/Build"
           }'

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 1 job (4 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