Skip to content
Latchkey

CI workflow (MacHu-GWU/uszipcode-project)

The CI workflow from MacHu-GWU/uszipcode-project, 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: MacHu-GWU/uszipcode-project.github/workflows/main.ymlLicense MITView source

What it does

This is the CI workflow from the MacHu-GWU/uszipcode-project 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)
# comprehensive github action yml reference: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions

---
name: CI

on:
  push: # any push event to master will trigger this
    branches: ["master"]
  pull_request: # any pull request to master will trigger this
    branches: ["master"]
  workflow_dispatch: # allows you to manually trigger run

jobs:
  tests:
    name: "${{ matrix.os }} Python ${{ matrix.python-version }}"
    runs-on: "${{ matrix.os }}" # for all available VM runtime, see this: https://docs.github.com/en/free-pro-team@latest/actions/reference/specifications-for-github-hosted-runners
    env: # define environment variables
      USING_COVERAGE: "3.6,3.7,3.8,3.9,3.10"
    strategy:
      matrix:
#        os: ["ubuntu-latest", "windows-latest"]
        os: ["ubuntu-latest", ] # for debug only
#        python-version: ["3.6", "3.7", "3.8", "3.9"]
        python-version: ["3.10", ] # for debug only
        exclude:
          - os: windows-latest # this is a useless exclude rules for demonstration use only
            python-version: 2.7
    steps:
      - uses: "actions/checkout@v2" # https://github.com/marketplace/actions/checkout
      - uses: "actions/setup-python@v2" # https://github.com/marketplace/actions/setup-python
        with:
          python-version: "${{ matrix.python-version }}"

      - if: matrix.os == 'ubuntu-latest' # for condition steps, you should put if at begin, and use single quote for logical expression
        name: "Install dependencies on MacOS or Linux"
        run: |
          set -xe
          python -VV
          python -m site
          python -m pip install --upgrade pip setuptools wheel virtualenv codecov
          pip install -r requirements.txt
          pip install -r requirements-test.txt
          pip install .
      - if: matrix.os == 'windows-latest'
        name: "Install dependencies on Windows"
        run: |
          python -m site
          python -m pip install --upgrade pip setuptools wheel virtualenv codecov
          pip install -r requirements.txt
          pip install -r requirements-test.txt
          pip install .
      - name: "Run pytest"
        run: "python -m pytest tests --cov=uszipcode"

      - name: "Upload coverage to Codecov"
        if: "contains(env.USING_COVERAGE, matrix.python-version)"
        uses: "codecov/codecov-action@v1" # https://github.com/marketplace/actions/codecov-action
        with:
          fail_ci_if_error: true

The same workflow, on Latchkey

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

# comprehensive github action yml reference: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions
 
---
name: CI
 
on:
  push: # any push event to master will trigger this
    branches: ["master"]
  pull_request: # any pull request to master will trigger this
    branches: ["master"]
  workflow_dispatch: # allows you to manually trigger run
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  tests:
    timeout-minutes: 30
    name: "${{ matrix.os }} Python ${{ matrix.python-version }}"
    runs-on: "${{ matrix.os }}" # for all available VM runtime, see this: https://docs.github.com/en/free-pro-team@latest/actions/reference/specifications-for-github-hosted-runners
    env: # define environment variables
      USING_COVERAGE: "3.6,3.7,3.8,3.9,3.10"
    strategy:
      matrix:
#        os: ["ubuntu-latest", "windows-latest"]
        os: ["ubuntu-latest", ] # for debug only
#        python-version: ["3.6", "3.7", "3.8", "3.9"]
        python-version: ["3.10", ] # for debug only
        exclude:
          - os: windows-latest # this is a useless exclude rules for demonstration use only
            python-version: 2.7
    steps:
      - uses: "actions/checkout@v2" # https://github.com/marketplace/actions/checkout
      - uses: "actions/setup-python@v2" # https://github.com/marketplace/actions/setup-python
        with:
          python-version: "${{ matrix.python-version }}"
 
      - if: matrix.os == 'ubuntu-latest' # for condition steps, you should put if at begin, and use single quote for logical expression
        name: "Install dependencies on MacOS or Linux"
        run: |
          set -xe
          python -VV
          python -m site
          python -m pip install --upgrade pip setuptools wheel virtualenv codecov
          pip install -r requirements.txt
          pip install -r requirements-test.txt
          pip install .
      - if: matrix.os == 'windows-latest'
        name: "Install dependencies on Windows"
        run: |
          python -m site
          python -m pip install --upgrade pip setuptools wheel virtualenv codecov
          pip install -r requirements.txt
          pip install -r requirements-test.txt
          pip install .
      - name: "Run pytest"
        run: "python -m pytest tests --cov=uszipcode"
 
      - name: "Upload coverage to Codecov"
        if: "contains(env.USING_COVERAGE, matrix.python-version)"
        uses: "codecov/codecov-action@v1" # https://github.com/marketplace/actions/codecov-action
        with:
          fail_ci_if_error: true
 
 

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