Skip to content
Latchkey

CI - Unit Test workflow (Nya-Foundation/NyaProxy)

The CI - Unit Test workflow from Nya-Foundation/NyaProxy, explained and optimized by Latchkey.

B

CI health: B - good

Point runs-on at Latchkey and get 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: Nya-Foundation/NyaProxy.github/workflows/test.ymlLicense MITView source

What it does

This is the CI - Unit Test workflow from the Nya-Foundation/NyaProxy 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)
# .github/workflows/test.yml
name: CI - Unit Test

on:
  push:
    branches:
      - dev
    paths:
      - 'nya/**'
      - 'tests/**'
  pull_request:
    branches: ["dev", "staging"]
    paths:
      - 'nya/**'
      - 'tests/**'

  workflow_dispatch:

# Concurrency settings:
# - For PRs: Cancel older runs for the same PR.
# - For pushes: Cancel older runs for the same branch.
# - workflow_dispatch runs will run independently.
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.11', '3.12', '3.13']
      fail-fast: false # Ensure all Python versions are tested
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
      # fetch-depth: 0 # Usually not needed for tests unless testing git history itself

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
        cache: 'pip'
        cache-dependency-path: |
          pyproject.toml
          setup.py
          # Add requirements*.txt if relevant

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -e ".[dev,lint]"

    - name: Type check (mypy ratchet)
      # Checks only the type-clean module set in pyproject [tool.mypy].
      run: |
        mypy

    - name: Run tests with coverage
      # --cov-fail-under is a ratchet: it must never drop. Raise it as
      # coverage improves (next milestones: 45, then 60).
      run: |
        pytest --cov=nya tests/ --cov-report=xml --cov-fail-under=42

    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v5
      with:
        files: ./reports/coverage.xml
        token: ${{ secrets.CODECOV_TOKEN }} 
        fail_ci_if_error: true # Recommended to fail the build if Codecov upload fails
        name: codecov-${{ matrix.python-version }} # Optional: name the report based on Python version
        flags: unittests
        verbose: true
      # Only upload coverage for one Python version to avoid duplicate reports (optional, but common)
      # if: matrix.python-version == '3.12' # Or your primary test version

The same workflow, on Latchkey

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

# .github/workflows/test.yml
name: CI - Unit Test
 
on:
  push:
    branches:
      - dev
    paths:
      - 'nya/**'
      - 'tests/**'
  pull_request:
    branches: ["dev", "staging"]
    paths:
      - 'nya/**'
      - 'tests/**'
 
  workflow_dispatch:
 
# Concurrency settings:
# - For PRs: Cancel older runs for the same PR.
# - For pushes: Cancel older runs for the same branch.
# - workflow_dispatch runs will run independently.
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
 
jobs:
  test:
    timeout-minutes: 30
    runs-on: latchkey-small
    strategy:
      matrix:
        python-version: ['3.11', '3.12', '3.13']
      fail-fast: false # Ensure all Python versions are tested
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
      # fetch-depth: 0 # Usually not needed for tests unless testing git history itself
 
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
        cache: 'pip'
        cache-dependency-path: |
          pyproject.toml
          setup.py
          # Add requirements*.txt if relevant
 
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -e ".[dev,lint]"
 
    - name: Type check (mypy ratchet)
      # Checks only the type-clean module set in pyproject [tool.mypy].
      run: |
        mypy
 
    - name: Run tests with coverage
      # --cov-fail-under is a ratchet: it must never drop. Raise it as
      # coverage improves (next milestones: 45, then 60).
      run: |
        pytest --cov=nya tests/ --cov-report=xml --cov-fail-under=42
 
    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v5
      with:
        files: ./reports/coverage.xml
        token: ${{ secrets.CODECOV_TOKEN }} 
        fail_ci_if_error: true # Recommended to fail the build if Codecov upload fails
        name: codecov-${{ matrix.python-version }} # Optional: name the report based on Python version
        flags: unittests
        verbose: true
      # Only upload coverage for one Python version to avoid duplicate reports (optional, but common)
      # if: matrix.python-version == '3.12' # Or your primary test version

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