Skip to content
Latchkey

conda-build workflow (QuantEcon/QuantEcon.py)

The conda-build workflow from QuantEcon/QuantEcon.py, explained and optimized by Latchkey.

F

CI health: F - at risk

Point runs-on at Latchkey and get caching, run de-duplication, 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: QuantEcon/QuantEcon.py.github/workflows/ci.ymlLicense MITView source

What it does

This is the conda-build workflow from the QuantEcon/QuantEcon.py 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: conda-build

on:
  push:
    branches:
      - main
    tags:
      - 'v*'
  pull_request:
    branches:
      - main


jobs:
  tests:
    runs-on: ${{ matrix.os }}
    strategy:
      # one failing job shouldn't cancel the rest of the matrix
      fail-fast: false
      matrix:
        os: [windows-latest, ubuntu-latest, macos-latest]
        # quoted as strings (bare 3.10 would parse as float 3.1)
        python-version: ["3.12", "3.13", "3.14"]
    steps:
    - uses: actions/checkout@v7
      with:
        fetch-depth: 0
    - name: Cache conda
      uses: actions/cache@v6
      env:
        CACHE_NUMBER: 0
      with:
        path: ~/conda_pkgs_dir
        key:
          ${{ runner.os }}-${{ matrix.python-version }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.yml') }}
    - uses: conda-incubator/setup-miniconda@v4
      with:
        auto-update-conda: true
        miniforge-version: latest
        environment-file: environment.yml
        python-version: ${{ matrix.python-version }}
        auto-activate-base: false
        use-only-tar-bz2: true
        activate-environment: qe
    - name: Conda info
      shell: bash -l {0}
      run: |
        conda info
        conda list
    - name: flake8 Tests
      shell: bash -l {0}
      run: |
        flake8 --select=F401,F405,E231 quantecon
    - name: Run Tests (pytest)
      shell: bash -l {0}
      run: |
        coverage run -m pytest quantecon
        coverage lcov
    - name: Coveralls
      uses: coverallsapp/github-action@v2
      # upload from one Linux job only (avoids the Coveralls parallel-build 422
      # race); continue-on-error so an upload hiccup can't fail CI
      if: runner.os == 'Linux' && matrix.python-version == '3.13'
      continue-on-error: true
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        # `file` (not the deprecated `path-to-lcov`) is the v2 input
        file: coverage.lcov
        format: lcov

  publish:

    name: Publish to PyPi
    needs: [tests]
    if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source
        uses: actions/checkout@v7
      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.x"
      - name: Install flit
        run: |
          pip install flit~=3.6
      - name: Build and publish
        run: |
          flit publish
        env:
          FLIT_USERNAME: __token__
          FLIT_PASSWORD: ${{ secrets.PYPI_TOKEN }}

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: conda-build
 
on:
  push:
    branches:
      - main
    tags:
      - 'v*'
  pull_request:
    branches:
      - main
 
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  tests:
    timeout-minutes: 30
    runs-on: ${{ matrix.os }}
    strategy:
      # one failing job shouldn't cancel the rest of the matrix
      fail-fast: false
      matrix:
        os: [windows-latest, ubuntu-latest, macos-latest]
        # quoted as strings (bare 3.10 would parse as float 3.1)
        python-version: ["3.12", "3.13", "3.14"]
    steps:
    - uses: actions/checkout@v7
      with:
        fetch-depth: 0
    - name: Cache conda
      uses: actions/cache@v6
      env:
        CACHE_NUMBER: 0
      with:
        path: ~/conda_pkgs_dir
        key:
          ${{ runner.os }}-${{ matrix.python-version }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.yml') }}
    - uses: conda-incubator/setup-miniconda@v4
      with:
        auto-update-conda: true
        miniforge-version: latest
        environment-file: environment.yml
        python-version: ${{ matrix.python-version }}
        auto-activate-base: false
        use-only-tar-bz2: true
        activate-environment: qe
    - name: Conda info
      shell: bash -l {0}
      run: |
        conda info
        conda list
    - name: flake8 Tests
      shell: bash -l {0}
      run: |
        flake8 --select=F401,F405,E231 quantecon
    - name: Run Tests (pytest)
      shell: bash -l {0}
      run: |
        coverage run -m pytest quantecon
        coverage lcov
    - name: Coveralls
      uses: coverallsapp/github-action@v2
      # upload from one Linux job only (avoids the Coveralls parallel-build 422
      # race); continue-on-error so an upload hiccup can't fail CI
      if: runner.os == 'Linux' && matrix.python-version == '3.13'
      continue-on-error: true
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        # `file` (not the deprecated `path-to-lcov`) is the v2 input
        file: coverage.lcov
        format: lcov
 
  publish:
    timeout-minutes: 30
 
    name: Publish to PyPi
    needs: [tests]
    if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
    runs-on: latchkey-small
    steps:
      - name: Checkout source
        uses: actions/checkout@v7
      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          cache: 'pip'
          python-version: "3.x"
      - name: Install flit
        run: |
          pip install flit~=3.6
      - name: Build and publish
        run: |
          flit publish
        env:
          FLIT_USERNAME: __token__
          FLIT_PASSWORD: ${{ secrets.PYPI_TOKEN }}
 

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 2 jobs (10 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