Skip to content
Latchkey

CI workflow (quarkfin/qf-lib)

The CI workflow from quarkfin/qf-lib, 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: quarkfin/qf-lib.github/workflows/tests.ymlLicense Apache-2.0View source

What it does

This is the CI workflow from the quarkfin/qf-lib repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: CI

on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master
    - 'feature/**'

jobs:
  style_check:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Set up Python 3.11
      uses: actions/setup-python@v3
      with:
        python-version: "3.11"
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install flake8==5.0.4 pyflakes==2.5.0 pytest
    - name: Style check
      run: flake8 .

  unit_tests:
    runs-on: ubuntu-latest
    needs: style_check
    steps:
    - uses: actions/checkout@v3
    - name: Set up Python 3.11
      uses: actions/setup-python@v3
      with:
        python-version: "3.11"
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -e ".[blpapi]" --extra-index-url https://blpapi.bloomberg.com/repository/releases/python/simple
        pip install -e ".[yfinance]"
        pip install -e ".[detailed_analysis]"
        pip install -e ".[alpaca]"
        pip install -e ".[bloomberg_dl]"
        pip install flake8==5.0.4 pyflakes==2.5.0 pytest
        pip install coverage
    - name: Unit tests
      env:
        QUANTFIN_SECRET: ${{ secrets.QUANTFIN_SECRET }}
      run: |
        coverage run -m pytest qf_lib/tests/unit_tests
        coverage xml -o unit_tests.xml
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: unit_tests
        path: unit_tests.xml
  backtesting_tests:
    runs-on: ubuntu-latest
    needs: style_check
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          python-version: "3.11"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e ".[blpapi]" --extra-index-url https://blpapi.bloomberg.com/repository/releases/python/simple
          pip install -e ".[yfinance]"
          pip install -e ".[detailed_analysis]"
          pip install -e ".[alpaca]"
          pip install -e ".[bloomberg_dl]"
          pip install flake8==5.0.4 pyflakes==2.5.0 pytest
          pip install coverage
      - name: Integration tests
        env:
          QUANTFIN_SECRET: ${{ secrets.QUANTFIN_SECRET }}
        run: |
          coverage run -a -m pytest qf_lib/tests/integration_tests/backtesting
          coverage xml -o backtesting_tests.xml
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: backtesting_tests
          path: backtesting_tests.xml

  data_providers_tests:
    runs-on: ubuntu-latest
    needs: style_check
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          python-version: "3.11"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e ".[blpapi]" --extra-index-url https://blpapi.bloomberg.com/repository/releases/python/simple
          pip install -e ".[yfinance]"
          pip install -e ".[detailed_analysis]"
          pip install -e ".[alpaca]"
          pip install -e ".[bloomberg_dl]"
          pip install flake8==5.0.4 pyflakes==2.5.0 pytest
          pip install coverage
      - name: Integration tests
        env:
          QUANTFIN_SECRET: ${{ secrets.QUANTFIN_SECRET }}
        run: |
          coverage run -a -m pytest qf_lib/tests/integration_tests/data_providers
          coverage xml -o data_providers_tests.xml
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: data_providers_tests
          path: data_providers_tests.xml
  codecov_upload:
    runs-on: ubuntu-latest
    needs: [unit_tests, data_providers_tests, backtesting_tests]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Download unit_tests artifacts
        uses: actions/download-artifact@v4
        with:
          name: unit_tests
      - name: Download artifacts data_providers_tests
        uses: actions/download-artifact@v4
        with:
          name: data_providers_tests
      - name: Download backtesting_tests artifacts
        uses: actions/download-artifact@v4
        with:
          name: backtesting_tests
      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          python-version: "3.11"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install flake8==5.0.4 pyflakes==2.5.0 pytest
          pip install coverage
      - name: Upload to Codecov
        uses: codecov/codecov-action@v4
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
        with:
          files: ./unit_tests.xml, ./data_providers_tests.xml, ./backtesting_tests.xml
          fail_ci_if_error: true
          name: qf-lib-codecov
          verbose: true

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.

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
 
name: CI
 
on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master
    - 'feature/**'
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  style_check:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
    - uses: actions/checkout@v3
    - name: Set up Python 3.11
      uses: actions/setup-python@v3
      with:
        cache: 'pip'
        python-version: "3.11"
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install flake8==5.0.4 pyflakes==2.5.0 pytest
    - name: Style check
      run: flake8 .
 
  unit_tests:
    timeout-minutes: 30
    runs-on: latchkey-small
    needs: style_check
    steps:
    - uses: actions/checkout@v3
    - name: Set up Python 3.11
      uses: actions/setup-python@v3
      with:
        cache: 'pip'
        python-version: "3.11"
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -e ".[blpapi]" --extra-index-url https://blpapi.bloomberg.com/repository/releases/python/simple
        pip install -e ".[yfinance]"
        pip install -e ".[detailed_analysis]"
        pip install -e ".[alpaca]"
        pip install -e ".[bloomberg_dl]"
        pip install flake8==5.0.4 pyflakes==2.5.0 pytest
        pip install coverage
    - name: Unit tests
      env:
        QUANTFIN_SECRET: ${{ secrets.QUANTFIN_SECRET }}
      run: |
        coverage run -m pytest qf_lib/tests/unit_tests
        coverage xml -o unit_tests.xml
    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: unit_tests
        path: unit_tests.xml
  backtesting_tests:
    timeout-minutes: 30
    runs-on: latchkey-small
    needs: style_check
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          cache: 'pip'
          python-version: "3.11"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e ".[blpapi]" --extra-index-url https://blpapi.bloomberg.com/repository/releases/python/simple
          pip install -e ".[yfinance]"
          pip install -e ".[detailed_analysis]"
          pip install -e ".[alpaca]"
          pip install -e ".[bloomberg_dl]"
          pip install flake8==5.0.4 pyflakes==2.5.0 pytest
          pip install coverage
      - name: Integration tests
        env:
          QUANTFIN_SECRET: ${{ secrets.QUANTFIN_SECRET }}
        run: |
          coverage run -a -m pytest qf_lib/tests/integration_tests/backtesting
          coverage xml -o backtesting_tests.xml
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: backtesting_tests
          path: backtesting_tests.xml
 
  data_providers_tests:
    timeout-minutes: 30
    runs-on: latchkey-small
    needs: style_check
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          cache: 'pip'
          python-version: "3.11"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e ".[blpapi]" --extra-index-url https://blpapi.bloomberg.com/repository/releases/python/simple
          pip install -e ".[yfinance]"
          pip install -e ".[detailed_analysis]"
          pip install -e ".[alpaca]"
          pip install -e ".[bloomberg_dl]"
          pip install flake8==5.0.4 pyflakes==2.5.0 pytest
          pip install coverage
      - name: Integration tests
        env:
          QUANTFIN_SECRET: ${{ secrets.QUANTFIN_SECRET }}
        run: |
          coverage run -a -m pytest qf_lib/tests/integration_tests/data_providers
          coverage xml -o data_providers_tests.xml
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: data_providers_tests
          path: data_providers_tests.xml
  codecov_upload:
    timeout-minutes: 30
    runs-on: latchkey-small
    needs: [unit_tests, data_providers_tests, backtesting_tests]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Download unit_tests artifacts
        uses: actions/download-artifact@v4
        with:
          name: unit_tests
      - name: Download artifacts data_providers_tests
        uses: actions/download-artifact@v4
        with:
          name: data_providers_tests
      - name: Download backtesting_tests artifacts
        uses: actions/download-artifact@v4
        with:
          name: backtesting_tests
      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          cache: 'pip'
          python-version: "3.11"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install flake8==5.0.4 pyflakes==2.5.0 pytest
          pip install coverage
      - name: Upload to Codecov
        uses: codecov/codecov-action@v4
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
        with:
          files: ./unit_tests.xml, ./data_providers_tests.xml, ./backtesting_tests.xml
          fail_ci_if_error: true
          name: qf-lib-codecov
          verbose: true
 

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