build workflow (vladkens/twscrape)
The build workflow from vladkens/twscrape, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get 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 build workflow from the vladkens/twscrape 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: build
on:
push:
branches: [main]
tags: ["v*"]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v6
- uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
python-version: ${{ matrix.python-version }}
- run: uv sync --frozen
- run: make check
- run: make test
release:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
needs: test
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v6
- uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Check pyproject.toml version matches tag
run: |
TAG="${{ github.ref_name }}"
PKG_VERSION="v$(grep '^version = ' pyproject.toml | cut -d'"' -f2)"
if [ "$TAG" != "$PKG_VERSION" ]; then
echo "Error: tag ${TAG} does not match pyproject.toml version ${PKG_VERSION}"
exit 1
fi
- name: Prepare README for PyPI
run: |
BASE_URL="https://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}"
sed -i "s#src=\"\\.github/#src=\"${BASE_URL}/.github/#g" readme.md
- run: uv build
- name: Extract changelog entry
run: |
VERSION="${{ github.ref_name }}"
NOTES=$(awk "/^## ${VERSION}/{found=1; next} /^## /{found=0} found" changelog.md)
if [ -z "$NOTES" ]; then
echo "Error: no changelog entry found for ${VERSION}"
exit 1
fi
echo "$NOTES" > release_notes.txt
- uses: pypa/gh-action-pypi-publish@release/v1
- run: gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --notes-file release_notes.txt
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: build on: push: branches: [main] tags: ["v*"] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: test: timeout-minutes: 30 runs-on: latchkey-small strategy: fail-fast: false matrix: python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"] steps: - uses: actions/checkout@v6 - uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 with: python-version: ${{ matrix.python-version }} - run: uv sync --frozen - run: make check - run: make test release: timeout-minutes: 30 if: ${{ startsWith(github.ref, 'refs/tags/v') }} runs-on: latchkey-small needs: test permissions: contents: write id-token: write steps: - uses: actions/checkout@v6 - uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 - name: Check pyproject.toml version matches tag run: | TAG="${{ github.ref_name }}" PKG_VERSION="v$(grep '^version = ' pyproject.toml | cut -d'"' -f2)" if [ "$TAG" != "$PKG_VERSION" ]; then echo "Error: tag ${TAG} does not match pyproject.toml version ${PKG_VERSION}" exit 1 fi - name: Prepare README for PyPI run: | BASE_URL="https://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}" sed -i "s#src=\"\\.github/#src=\"${BASE_URL}/.github/#g" readme.md - run: uv build - name: Extract changelog entry run: | VERSION="${{ github.ref_name }}" NOTES=$(awk "/^## ${VERSION}/{found=1; next} /^## /{found=0} found" changelog.md) if [ -z "$NOTES" ]; then echo "Error: no changelog entry found for ${VERSION}" exit 1 fi echo "$NOTES" > release_notes.txt - uses: pypa/gh-action-pypi-publish@release/v1 - run: gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --notes-file release_notes.txt env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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.
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.
This workflow runs 2 jobs (6 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.