CI workflow (run-x/opta)
The CI workflow from run-x/opta, explained and optimized by Latchkey.
CI health: F - at risk
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the CI workflow from the run-x/opta 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
# 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: [main, dev]
pull_request:
branches: [main, dev]
jobs:
no-pdb:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: No PDB
run: |
cd scripts
./no_pdb.sh
shell-check:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Install shellcheck
run: |
sudo apt update
sudo apt install shellcheck
- name: Lint
run: |
shellcheck **/*.sh
shell-fmt:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
with:
go-version: '^1.18' # The Go version to download (if necessary) and use.
- name: Install shell fmt
run: |
go install mvdan.cc/sh/v3/cmd/shfmt@latest
- name: Lint
run: |
shfmt -d ./
python-lint:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install python dependencies
run: |
pip install pipenv
pipenv install --deploy --dev
source $(pipenv --venv)/bin/activate
- name: Lint
run: |
source $(pipenv --venv)/bin/activate
export PYTHONPATH=$(pwd)
./scripts/lint.py
security:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install python dependencies
run: |
pip install pipenv
pipenv install --deploy --dev
source $(pipenv --venv)/bin/activate
- name: Security
run: make security_tests
terraform_format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Pin terraform version
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.0.0
terraform_wrapper: false
- name: Run terraform format
run: |
terraform version
terraform fmt -recursive -check ./modules
python:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Pin terraform version
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.0.0
terraform_wrapper: false
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
pip install pipenv
pipenv install --deploy --dev
source $(pipenv --venv)/bin/activate
- name: Test with pytest
run: |
pipenv run pytest --cov=./opta --cov=./modules --cov-report=xml
env:
PYTHONPATH: $(pwd)
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.RUNXC_CODECOV_TOKEN }}
files: ./coverage.xml
directory: ./coverage/reports/
flags: unittests
env_vars: OS,PYTHON
name: codecov-umbrella
fail_ci_if_error: true
path_to_write_report: ./coverage/codecov_report.txt
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: [main, dev] pull_request: branches: [main, dev] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: no-pdb: timeout-minutes: 30 runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: No PDB run: | cd scripts ./no_pdb.sh shell-check: timeout-minutes: 30 runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: Install shellcheck run: | sudo apt update sudo apt install shellcheck - name: Lint run: | shellcheck **/*.sh shell-fmt: timeout-minutes: 30 runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v3 with: go-version: '^1.18' # The Go version to download (if necessary) and use. - name: Install shell fmt run: | go install mvdan.cc/sh/v3/cmd/shfmt@latest - name: Lint run: | shfmt -d ./ python-lint: timeout-minutes: 30 runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v2 with: cache: 'pip' python-version: 3.8 - name: Install python dependencies run: | pip install pipenv pipenv install --deploy --dev source $(pipenv --venv)/bin/activate - name: Lint run: | source $(pipenv --venv)/bin/activate export PYTHONPATH=$(pwd) ./scripts/lint.py security: timeout-minutes: 30 runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v2 with: cache: 'pip' python-version: 3.8 - name: Install python dependencies run: | pip install pipenv pipenv install --deploy --dev source $(pipenv --venv)/bin/activate - name: Security run: make security_tests terraform_format: timeout-minutes: 30 runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: Pin terraform version uses: hashicorp/setup-terraform@v1 with: terraform_version: 1.0.0 terraform_wrapper: false - name: Run terraform format run: | terraform version terraform fmt -recursive -check ./modules python: timeout-minutes: 30 runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - name: Pin terraform version uses: hashicorp/setup-terraform@v1 with: terraform_version: 1.0.0 terraform_wrapper: false - name: Set up Python 3.8 uses: actions/setup-python@v2 with: cache: 'pip' python-version: 3.8 - name: Install dependencies run: | pip install pipenv pipenv install --deploy --dev source $(pipenv --venv)/bin/activate - name: Test with pytest run: | pipenv run pytest --cov=./opta --cov=./modules --cov-report=xml env: PYTHONPATH: $(pwd) - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 with: token: ${{ secrets.RUNXC_CODECOV_TOKEN }} files: ./coverage.xml directory: ./coverage/reports/ flags: unittests env_vars: OS,PYTHON name: codecov-umbrella fail_ci_if_error: true path_to_write_report: ./coverage/codecov_report.txt verbose: true
What changed
- Cancel superseded runs when a branch or PR gets a newer push.
- Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
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:
- Dependency installs
This workflow runs 7 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.