GitHub Actions workflow (BayesWitnesses/m2cgen)
The GitHub Actions workflow from BayesWitnesses/m2cgen, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the GitHub Actions workflow from the BayesWitnesses/m2cgen 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
name: GitHub Actions
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test:
name: "Python ${{ matrix.python }}, Test: ${{ matrix.lang }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
lang:
- "API"
- "c_lang or python or java or go_lang or javascript or php or haskell or ruby or rust"
- "c_sharp or visual_basic or f_sharp"
- "r_lang"
- "elixir"
- "dart or powershell"
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 5
- name: Build Docker image
run: docker build . --file Dockerfile -t m2cgen-docker --build-arg python=${{ matrix.python }}
- name: Run tests
run: |
if [[ "${{ matrix.lang }}" == "API" ]]; then
export TEST="API";
else
export TEST="E2E";
fi
docker run \
--ulimit stack=-1 \
-v "$GITHUB_WORKSPACE":"/m2cgen" \
-e TEST \
-e LANG="${{ matrix.lang }}" \
-e GITHUB_ACTIONS \
-e GITHUB_WORKFLOW \
-e GITHUB_RUN_ID \
-e GITHUB_SHA \
-e GITHUB_REF \
-e GITHUB_HEAD_REF \
-e GITHUB_REPOSITORY \
-e GITHUB_SERVER_URL \
-e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} \
m2cgen-docker \
bash /m2cgen/.ci/test.sh
- name: Generate artifact with code examples
if: matrix.python == '3.10' && matrix.lang == 'API'
uses: actions/upload-artifact@v3
with:
name: code_examples
path: ${{ github.workspace }}/generated_code_examples/
if-no-files-found: error
all-successful:
# https://github.community/t/is-it-possible-to-require-all-github-actions-tasks-to-pass-without-enumerating-them/117957/4?u=graingert
runs-on: ubuntu-latest
needs: test
steps:
- name: Note that all tests succeeded
run: echo "🎉"
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: GitHub Actions on: push: branches: - master pull_request: branches: - master concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: test: timeout-minutes: 30 name: "Python ${{ matrix.python }}, Test: ${{ matrix.lang }}" runs-on: latchkey-small strategy: fail-fast: false matrix: python: - "3.7" - "3.8" - "3.9" - "3.10" lang: - "API" - "c_lang or python or java or go_lang or javascript or php or haskell or ruby or rust" - "c_sharp or visual_basic or f_sharp" - "r_lang" - "elixir" - "dart or powershell" steps: - name: Checkout repository uses: actions/checkout@v2 with: fetch-depth: 5 - name: Build Docker image run: docker build . --file Dockerfile -t m2cgen-docker --build-arg python=${{ matrix.python }} - name: Run tests run: | if [[ "${{ matrix.lang }}" == "API" ]]; then export TEST="API"; else export TEST="E2E"; fi docker run \ --ulimit stack=-1 \ -v "$GITHUB_WORKSPACE":"/m2cgen" \ -e TEST \ -e LANG="${{ matrix.lang }}" \ -e GITHUB_ACTIONS \ -e GITHUB_WORKFLOW \ -e GITHUB_RUN_ID \ -e GITHUB_SHA \ -e GITHUB_REF \ -e GITHUB_HEAD_REF \ -e GITHUB_REPOSITORY \ -e GITHUB_SERVER_URL \ -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} \ m2cgen-docker \ bash /m2cgen/.ci/test.sh - name: Generate artifact with code examples if: matrix.python == '3.10' && matrix.lang == 'API' uses: actions/upload-artifact@v3 with: name: code_examples path: ${{ github.workspace }}/generated_code_examples/ if-no-files-found: error all-successful: timeout-minutes: 30 # https://github.community/t/is-it-possible-to-require-all-github-actions-tasks-to-pass-without-enumerating-them/117957/4?u=graingert runs-on: latchkey-small needs: test steps: - name: Note that all tests succeeded run: echo "🎉"
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Add a job timeout so a hung step cannot burn hours of runner time.
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:
- Container pulls and builds
- End-to-end and browser tests
This workflow runs 2 jobs (25 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.