Skip to content
Latchkey

black workflow (rasa/scoop-directory)

The black workflow from rasa/scoop-directory, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get caching, 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: rasa/scoop-directory.github/workflows/black.ymlLicense MITView source

What it does

This is the black workflow from the rasa/scoop-directory 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)
# .github/workflows/black.yml
# From https://github.com/ad-m/github-push-action#example-workflow-file
name: black

on:
  workflow_dispatch:

jobs:
  black:
    runs-on: ubuntu-latest
    steps:
    - name: STEP actions/setup-python@v5
      uses: actions/setup-python@v5
      with:
        python-version: '3.9'

    - name: STEP pip install black
      # if: steps.cache.outputs.cache-hit != 'true'
      run: |
          python -m pip install --upgrade pip
          pip install black

    - name: STEP actions/checkout@v4
      uses: actions/checkout@v4
      with:
        persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
        fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.

    - name: STEP black --check *.py
      id: black
      run: |
        mapfile -t <<<"$(find . -type f -iname "*.py")"
        ((${#MAPFILE[@]})) || { echo ERROR: No .py files found >&2 ; exit 1 ; }
        rv=0
        black --config .github/linters/.python-black --check "${MAPFILE[@]}" || rv=$?
        ((rv==0)) && echo "::set-output name=changes::false" && exit 0
        ((rv==1)) && echo "::set-output name=changes::true" && exit 0
        exit $rv

    - name: STEP black *.py
      if: steps.black.outputs.changes == 'true'
      run: |
        mapfile -t <<<"$(find . -type f -iname "*.py")"
        black --config .github/linters/.python-black "${MAPFILE[@]}"

    - name: STEP git commit -m "black" -a
      if: steps.black.outputs.changes == 'true'
      run: |
        git config --local user.email "action@github.com"
        git config --local user.name "GitHub Action"
        git commit -m "black" -a

    - name: STEP ad-m/github-push-action@master
      if: steps.black.outputs.changes == 'true'
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.ref }}

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.

# .github/workflows/black.yml
# From https://github.com/ad-m/github-push-action#example-workflow-file
name: black
 
on:
  workflow_dispatch:
 
jobs:
  black:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
    - name: STEP actions/setup-python@v5
      uses: actions/setup-python@v5
      with:
        cache: 'pip'
        python-version: '3.9'
 
    - name: STEP pip install black
      # if: steps.cache.outputs.cache-hit != 'true'
      run: |
          python -m pip install --upgrade pip
          pip install black
 
    - name: STEP actions/checkout@v4
      uses: actions/checkout@v4
      with:
        persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
        fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
 
    - name: STEP black --check *.py
      id: black
      run: |
        mapfile -t <<<"$(find . -type f -iname "*.py")"
        ((${#MAPFILE[@]})) || { echo ERROR: No .py files found >&2 ; exit 1 ; }
        rv=0
        black --config .github/linters/.python-black --check "${MAPFILE[@]}" || rv=$?
        ((rv==0)) && echo "::set-output name=changes::false" && exit 0
        ((rv==1)) && echo "::set-output name=changes::true" && exit 0
        exit $rv
 
    - name: STEP black *.py
      if: steps.black.outputs.changes == 'true'
      run: |
        mapfile -t <<<"$(find . -type f -iname "*.py")"
        black --config .github/linters/.python-black "${MAPFILE[@]}"
 
    - name: STEP git commit -m "black" -a
      if: steps.black.outputs.changes == 'true'
      run: |
        git config --local user.email "action@github.com"
        git config --local user.name "GitHub Action"
        git commit -m "black" -a
 
    - name: STEP ad-m/github-push-action@master
      if: steps.black.outputs.changes == 'true'
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.ref }}
 

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 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow