Skip to content
Latchkey

languages workflow (pre-commit/pre-commit)

The languages workflow from pre-commit/pre-commit, 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: pre-commit/pre-commit.github/workflows/languages.yamlLicense MITView source

What it does

This is the languages workflow from the pre-commit/pre-commit 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: languages

on:
  push:
    branches: [main, test-me-*]
    tags: '*'
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  vars:
    runs-on: ubuntu-latest
    outputs:
      languages: ${{ steps.vars.outputs.languages }}
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
    - uses: actions/setup-python@v4
      with:
        python-version: '3.10'
    - name: install deps
      run: python -mpip install -e . -r requirements-dev.txt
    - name: vars
      run: testing/languages ${{ github.event_name == 'push' && '--all' || '' }}
      id: vars
  language:
    needs: [vars]
    runs-on: ${{ matrix.os }}
    if: needs.vars.outputs.languages != '[]'
    strategy:
      fail-fast: false
      matrix:
        include: ${{ fromJSON(needs.vars.outputs.languages) }}
    steps:
    - uses: asottile/workflows/.github/actions/fast-checkout@v1.8.1
    - uses: actions/setup-python@v4
      with:
        python-version: '3.10'

    - run: echo "$CONDA\Scripts" >> "$GITHUB_PATH"
      shell: bash
      if: matrix.os == 'windows-latest' && matrix.language == 'conda'
    - run: testing/get-coursier.sh
      shell: bash
      if: matrix.language == 'coursier'
    - run: testing/get-dart.sh
      shell: bash
      if: matrix.language == 'dart'
    - run: |
        sudo apt-get update
        sudo apt-get install -y --no-install-recommends \
          lua5.3 \
          liblua5.3-dev \
          luarocks
      if: matrix.os == 'ubuntu-latest' && matrix.language == 'lua'
    - run: |
        echo 'C:\Strawberry\perl\bin' >> "$GITHUB_PATH"
        echo 'C:\Strawberry\perl\site\bin' >> "$GITHUB_PATH"
        echo 'C:\Strawberry\c\bin' >> "$GITHUB_PATH"
      shell: bash
      if: matrix.os == 'windows-latest' && matrix.language == 'perl'
    - uses: haskell/actions/setup@v2
      if: matrix.language == 'haskell'
    - uses: r-lib/actions/setup-r@v2
      if: matrix.os == 'ubuntu-latest' && matrix.language == 'r'

    - name: install deps
      run: python -mpip install -e . -r requirements-dev.txt
    - name: run tests
      run: coverage run -m pytest tests/languages/${{ matrix.language }}_test.py
    - name: check coverage
      run: coverage report --include pre_commit/languages/${{ matrix.language }}.py,tests/languages/${{ matrix.language }}_test.py
  collector:
    needs: [language]
    if: always()
    runs-on: ubuntu-latest
    steps:
    - name: check for failures
      if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
      run: echo job failed && exit 1

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: languages
 
on:
  push:
    branches: [main, test-me-*]
    tags: '*'
  pull_request:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true
 
jobs:
  vars:
    timeout-minutes: 30
    runs-on: latchkey-small
    outputs:
      languages: ${{ steps.vars.outputs.languages }}
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
    - uses: actions/setup-python@v4
      with:
        cache: 'pip'
        python-version: '3.10'
    - name: install deps
      run: python -mpip install -e . -r requirements-dev.txt
    - name: vars
      run: testing/languages ${{ github.event_name == 'push' && '--all' || '' }}
      id: vars
  language:
    timeout-minutes: 30
    needs: [vars]
    runs-on: ${{ matrix.os }}
    if: needs.vars.outputs.languages != '[]'
    strategy:
      fail-fast: false
      matrix:
        include: ${{ fromJSON(needs.vars.outputs.languages) }}
    steps:
    - uses: asottile/workflows/.github/actions/fast-checkout@v1.8.1
    - uses: actions/setup-python@v4
      with:
        cache: 'pip'
        python-version: '3.10'
 
    - run: echo "$CONDA\Scripts" >> "$GITHUB_PATH"
      shell: bash
      if: matrix.os == 'windows-latest' && matrix.language == 'conda'
    - run: testing/get-coursier.sh
      shell: bash
      if: matrix.language == 'coursier'
    - run: testing/get-dart.sh
      shell: bash
      if: matrix.language == 'dart'
    - run: |
        sudo apt-get update
        sudo apt-get install -y --no-install-recommends \
          lua5.3 \
          liblua5.3-dev \
          luarocks
      if: matrix.os == 'ubuntu-latest' && matrix.language == 'lua'
    - run: |
        echo 'C:\Strawberry\perl\bin' >> "$GITHUB_PATH"
        echo 'C:\Strawberry\perl\site\bin' >> "$GITHUB_PATH"
        echo 'C:\Strawberry\c\bin' >> "$GITHUB_PATH"
      shell: bash
      if: matrix.os == 'windows-latest' && matrix.language == 'perl'
    - uses: haskell/actions/setup@v2
      if: matrix.language == 'haskell'
    - uses: r-lib/actions/setup-r@v2
      if: matrix.os == 'ubuntu-latest' && matrix.language == 'r'
 
    - name: install deps
      run: python -mpip install -e . -r requirements-dev.txt
    - name: run tests
      run: coverage run -m pytest tests/languages/${{ matrix.language }}_test.py
    - name: check coverage
      run: coverage report --include pre_commit/languages/${{ matrix.language }}.py,tests/languages/${{ matrix.language }}_test.py
  collector:
    timeout-minutes: 30
    needs: [language]
    if: always()
    runs-on: latchkey-small
    steps:
    - name: check for failures
      if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
      run: echo job failed && exit 1
 

What changed

3 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.

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