Test workflow (BrikerMan/Kashgari)
The Test workflow from BrikerMan/Kashgari, explained and optimized by Latchkey.
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.
What it does
This is the Test workflow from the BrikerMan/Kashgari 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
name: Test
on:
push:
branches:
- v2-main
- v2-dev
- v2/github-actions
pull_request:
types: [opened, synchronize, reopened]
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install deps
run: |
python -m pip install --upgrade pip
python scripts/install_tf.py 2.2
python scripts/install_addons.py 2.2
pip install -r requirements.dev.txt
pip install -r requirements.txt
- name: Run lint script
run: sh ./scripts/lint.sh
test:
if: always()
name: "Test with TF ${{ matrix.tensorflow_version }} - ${{ matrix.group }}"
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
group: [ 1, 2, 3 ]
tensorflow_version: [2.2, 2.3, 2.4, 2.5]
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install deps
run: |
python -m pip install --upgrade pip
python scripts/install_tf.py '${{ matrix.tensorflow_version }}'
python scripts/install_addons.py '${{ matrix.tensorflow_version }}'
pip install -r requirements.dev.txt
pip install -r requirements.txt
- name: Run pytest
run: 'pytest
--doctest-modules
--junitxml=test-reports/junit-${{ matrix.tensorflow_version }}-${{ matrix.group }}.xml
--cov=kashgari
--cov-report=xml:cov-reports/coverage-${{ matrix.tensorflow_version }}-${{ matrix.group }}.xml
--cov-report term
--cov-config .coveragerc
--cov
--splits 3
--group ${{ matrix.group }}
tests/'
- name: Upload unit test
uses: actions/upload-artifact@v2
with:
name: junitxml-${{ matrix.tensorflow_version }}-${{ matrix.group }}
path: test-reports
- name: Upload coverage
uses: actions/upload-artifact@v2
with:
name: coverage-${{ matrix.tensorflow_version }}-${{ matrix.group }}
path: cov-reports
sonarcloud:
if: "!contains(github.event.head_commit.message, 'skip ci')"
name: SonarCloud
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: actions/download-artifact@v2
with:
path: artifacts
- name: Display structure of downloaded files
run: ls -R
- name: Copy Artifacts to target file
run: |
mkdir -p test-reports && cp artifacts/junit*/* test-reports
mkdir -p cov-reports && cp artifacts/cov*/* cov-reports
- name: Display structure of downloaded files
run: ls -R
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# - name: Publish Unit Test Results
# uses: EnricoMi/publish-unit-test-result-action@v1.3
# if: always()
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# check_name: Unit Test Results
# files: test-results/*.xml
# report_individual_runs: true
# deduplicate_classes_by_file_name: false
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: Test on: push: branches: - v2-main - v2-dev - v2/github-actions pull_request: types: [opened, synchronize, reopened] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: lint: timeout-minutes: 30 name: Lint runs-on: latchkey-small steps: - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v1 with: cache: 'pip' python-version: 3.8 - name: Install deps run: | python -m pip install --upgrade pip python scripts/install_tf.py 2.2 python scripts/install_addons.py 2.2 pip install -r requirements.dev.txt pip install -r requirements.txt - name: Run lint script run: sh ./scripts/lint.sh test: timeout-minutes: 30 if: always() name: "Test with TF ${{ matrix.tensorflow_version }} - ${{ matrix.group }}" needs: lint runs-on: latchkey-small strategy: matrix: group: [ 1, 2, 3 ] tensorflow_version: [2.2, 2.3, 2.4, 2.5] steps: - uses: actions/checkout@v2 - name: Set up Python 3.8 uses: actions/setup-python@v1 with: cache: 'pip' python-version: 3.8 - name: Install deps run: | python -m pip install --upgrade pip python scripts/install_tf.py '${{ matrix.tensorflow_version }}' python scripts/install_addons.py '${{ matrix.tensorflow_version }}' pip install -r requirements.dev.txt pip install -r requirements.txt - name: Run pytest run: 'pytest --doctest-modules --junitxml=test-reports/junit-${{ matrix.tensorflow_version }}-${{ matrix.group }}.xml --cov=kashgari --cov-report=xml:cov-reports/coverage-${{ matrix.tensorflow_version }}-${{ matrix.group }}.xml --cov-report term --cov-config .coveragerc --cov --splits 3 --group ${{ matrix.group }} tests/' - name: Upload unit test uses: actions/upload-artifact@v2 with: name: junitxml-${{ matrix.tensorflow_version }}-${{ matrix.group }} path: test-reports - name: Upload coverage uses: actions/upload-artifact@v2 with: name: coverage-${{ matrix.tensorflow_version }}-${{ matrix.group }} path: cov-reports sonarcloud: timeout-minutes: 30 if: "!contains(github.event.head_commit.message, 'skip ci')" name: SonarCloud runs-on: latchkey-small needs: test steps: - uses: actions/checkout@v2 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - uses: actions/download-artifact@v2 with: path: artifacts - name: Display structure of downloaded files run: ls -R - name: Copy Artifacts to target file run: | mkdir -p test-reports && cp artifacts/junit*/* test-reports mkdir -p cov-reports && cp artifacts/cov*/* cov-reports - name: Display structure of downloaded files run: ls -R - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # - name: Publish Unit Test Results # uses: EnricoMi/publish-unit-test-result-action@v1.3 # if: always() # with: # github_token: ${{ secrets.GITHUB_TOKEN }} # check_name: Unit Test Results # files: test-results/*.xml # report_individual_runs: true # deduplicate_classes_by_file_name: false
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.
- 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 3 jobs (14 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.