Fix Missing Images workflow (ViggoZ/producthunt-daily-hot)
The Fix Missing Images workflow from ViggoZ/producthunt-daily-hot, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Fix Missing Images workflow from the ViggoZ/producthunt-daily-hot 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: Fix Missing Images
on:
workflow_dispatch:
inputs:
batch_size:
description: '每批处理的文件数量'
required: false
default: '3'
pause:
description: '批次间暂停的秒数'
required: false
default: '120'
jobs:
fix-images:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install requests beautifulsoup4 python-dotenv
- name: Fix missing images
env:
PRODUCTHUNT_DEVELOPER_TOKEN: ${{ secrets.PRODUCTHUNT_DEVELOPER_TOKEN }}
run: |
python scripts/fix_images.py --all --batch-size ${{ github.event.inputs.batch_size || 3 }} --pause ${{ github.event.inputs.pause || 120 }}
- name: Commit files
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "Fixed missing images in Markdown files" || echo "No changes to commit"
- name: Push changes
run: |
git push --force https://${{ secrets.PAT }}@github.com/${{ github.repository_owner }}/producthunt-daily-hot.git HEAD:main 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: Fix Missing Images on: workflow_dispatch: inputs: batch_size: description: '每批处理的文件数量' required: false default: '3' pause: description: '批次间暂停的秒数' required: false default: '120' jobs: fix-images: timeout-minutes: 30 runs-on: latchkey-small steps: - name: Checkout repository uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: cache: 'pip' python-version: '3.x' - name: Install dependencies run: | pip install --upgrade pip pip install requests beautifulsoup4 python-dotenv - name: Fix missing images env: PRODUCTHUNT_DEVELOPER_TOKEN: ${{ secrets.PRODUCTHUNT_DEVELOPER_TOKEN }} run: | python scripts/fix_images.py --all --batch-size ${{ github.event.inputs.batch_size || 3 }} --pause ${{ github.event.inputs.pause || 120 }} - name: Commit files run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git add . git commit -m "Fixed missing images in Markdown files" || echo "No changes to commit" - name: Push changes run: | git push --force https://${{ secrets.PAT }}@github.com/${{ github.repository_owner }}/producthunt-daily-hot.git HEAD:main
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. - 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.
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 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.