Skip to content
Latchkey

CI workflow (massquantity/LibRecommender)

The CI workflow from massquantity/LibRecommender, explained and optimized by Latchkey.

C

CI health: C - fair

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: massquantity/LibRecommender.github/workflows/ci.ymlLicense MITView source

What it does

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

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  # Manual run
  workflow_dispatch:

jobs:
  build:
    name: testing
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-22.04]
        python-version: [3.7, 3.8, 3.9, '3.10', '3.11']

    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'

      - name: Display Python version
        run: python -c "import sys; print(sys.version)"

      - name: Install dependencies
        run: |
          python -m pip install -U pip wheel setuptools
          python -m pip install -r requirements-dev.txt
          python -m pip install -e .

      - name: Lint with flake8
        run: |
          flake8 libreco/ libserving/ tests/ examples/

      - name: Lint with ruff
        run: |
          ruff check libreco/ libserving/ tests/ examples/
        if: matrix.python-version != '3.6'

      - name: Test
        run: |
          python -m pip install pytest
          python -m pytest tests/ --ignore="tests/serving"
        if: matrix.python-version != '3.10'

      - name: Test with coverage
        run: |
          bash tests/serving/setup_coverage.sh
          coverage --version && coverage erase
          coverage run -m pytest tests/ --ignore="tests/serving"
          coverage combine && coverage report
          coverage xml
        if: matrix.python-version == '3.10'

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.xml
          flags: CI
          name: python${{ matrix.python-version }}-test
          token: ${{ secrets.CODECOV_TOKEN }}
          fail_ci_if_error: false
          verbose: true
        if: matrix.python-version == '3.10'

      - name: Upload coverage to Codacy
        uses: codacy/codacy-coverage-reporter-action@v1
        with:
          project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
          coverage-reports: ./coverage.xml
        if: matrix.python-version == '3.10'

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: CI
 
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  # Manual run
  workflow_dispatch:
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  build:
    timeout-minutes: 30
    name: testing
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-22.04]
        python-version: [3.7, 3.8, 3.9, '3.10', '3.11']
 
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'
 
      - name: Display Python version
        run: python -c "import sys; print(sys.version)"
 
      - name: Install dependencies
        run: |
          python -m pip install -U pip wheel setuptools
          python -m pip install -r requirements-dev.txt
          python -m pip install -e .
 
      - name: Lint with flake8
        run: |
          flake8 libreco/ libserving/ tests/ examples/
 
      - name: Lint with ruff
        run: |
          ruff check libreco/ libserving/ tests/ examples/
        if: matrix.python-version != '3.6'
 
      - name: Test
        run: |
          python -m pip install pytest
          python -m pytest tests/ --ignore="tests/serving"
        if: matrix.python-version != '3.10'
 
      - name: Test with coverage
        run: |
          bash tests/serving/setup_coverage.sh
          coverage --version && coverage erase
          coverage run -m pytest tests/ --ignore="tests/serving"
          coverage combine && coverage report
          coverage xml
        if: matrix.python-version == '3.10'
 
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.xml
          flags: CI
          name: python${{ matrix.python-version }}-test
          token: ${{ secrets.CODECOV_TOKEN }}
          fail_ci_if_error: false
          verbose: true
        if: matrix.python-version == '3.10'
 
      - name: Upload coverage to Codacy
        uses: codacy/codacy-coverage-reporter-action@v1
        with:
          project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
          coverage-reports: ./coverage.xml
        if: matrix.python-version == '3.10'
 

What changed

2 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 1 job (5 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