push workflow (hellock/icrawler)
The push workflow from hellock/icrawler, 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 push workflow from the hellock/icrawler 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: push
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x
cache: "pip"
- uses: pre-commit/action@v3.0.0
test:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version:
["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install dependencies
run: pip install -r requirements.txt && pip install -e .
- name: Install dependencies for testing
run: pip install pytest pytest-cov
- name: pytest
run: pytest .
release:
if: startsWith(github.event.ref, 'refs/tags/v')
needs: [lint, test]
environment: pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x
cache: "pip"
- name: Install dependencies for building
run: pip install wheel setuptools_scm
- name: build package
run: python setup.py sdist bdist_wheel
- name: create release
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
dist/*
- name: publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
develop:
if: contains(fromJson('["refs/heads/master", "refs/heads/main"]'), github.ref)
needs: [lint, test]
environment: pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: 3.x
cache: "pip"
- name: Install dependencies for building
run: pip install wheel setuptools_scm
- name: build package
run: python setup.py sdist bdist_wheel
- name: create release
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: true
title: "Development Build"
files: |
dist/*
# - name: publish to Test PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository_url: https://test.pypi.org/legacy/
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: push on: [push, pull_request] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: lint: timeout-minutes: 30 runs-on: latchkey-small steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: python-version: 3.x cache: "pip" - uses: pre-commit/action@v3.0.0 test: timeout-minutes: 30 runs-on: latchkey-small strategy: matrix: python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} cache: "pip" - name: Install dependencies run: pip install -r requirements.txt && pip install -e . - name: Install dependencies for testing run: pip install pytest pytest-cov - name: pytest run: pytest . release: timeout-minutes: 30 if: startsWith(github.event.ref, 'refs/tags/v') needs: [lint, test] environment: pypi runs-on: latchkey-small steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: python-version: 3.x cache: "pip" - name: Install dependencies for building run: pip install wheel setuptools_scm - name: build package run: python setup.py sdist bdist_wheel - name: create release uses: "marvinpinto/action-automatic-releases@latest" with: repo_token: "${{ secrets.GITHUB_TOKEN }}" prerelease: false files: | dist/* - name: publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.PYPI_API_TOKEN }} develop: timeout-minutes: 30 if: contains(fromJson('["refs/heads/master", "refs/heads/main"]'), github.ref) needs: [lint, test] environment: pypi runs-on: latchkey-small steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - uses: actions/setup-python@v4 with: python-version: 3.x cache: "pip" - name: Install dependencies for building run: pip install wheel setuptools_scm - name: build package run: python setup.py sdist bdist_wheel - name: create release uses: "marvinpinto/action-automatic-releases@latest" with: repo_token: "${{ secrets.GITHUB_TOKEN }}" automatic_release_tag: "latest" prerelease: true title: "Development Build" files: | dist/* # - name: publish to Test PyPI # uses: pypa/gh-action-pypi-publish@release/v1 # with: # password: ${{ secrets.TEST_PYPI_API_TOKEN }} # repository_url: https://test.pypi.org/legacy/
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.
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 4 jobs (11 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.