Files
time/.github/workflows/refresh.yml
T
teahubxyzandClaude Fable 5.1 822cf891d3
ci / test (push) Successful in 48s
sync / sync (push) Successful in 7s
refresh: land only what the build changed, as a patch on the latest gh-pages, instead of copying a stale checkout over it
A run's source checkout is taken at job start; the gh-pages checkout it commits to is taken minutes later, after
the queue and the build. Copying the whole folder reverted whatever landed in between (it just undid two commits
to Havre). Now the build's own diff is applied to the newest gh-pages, three-way; `from` keeps the whole-folder
landing, which is what it's for.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VAvUH72XsdCitHdh3t7mjr
2026-10-20 03:46:57 +00:00

110 lines
5.4 KiB
YAML

name: refresh
# Refresh a venture that lives on gh-pages and makes some of its own files (fonts, art, screenshots, generated
# code): run ventures/<slug>/tools/build.sh on the runner, in place, then commit what changed to gh-pages in one
# commit and ask Teahub pages to pull. Actions -> refresh -> Run workflow.
# `from` takes the venture's folder from another branch (say, a rework in progress), so the new version is built and
# lands whole instead of file by file. The build runs in a checkout without credentials; only ventures/<slug>/ comes
# back. Chrome for screenshots: CHROME (Playwright's Chromium is installed when the runner has none), with
# CHROME_FLAGS for running as root.
on:
workflow_dispatch:
inputs:
slug:
description: "The venture: ventures/<slug>/ on gh-pages, with a tools/build.sh"
required: true
type: string
from:
description: "Branch to take the venture's folder from (empty: gh-pages itself)"
required: false
type: string
permissions:
contents: write
concurrency:
group: venture # the venture loop and seed write gh-pages too: take turns
cancel-in-progress: false
jobs:
refresh:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: check the inputs
env: # inputs reach the scripts through the environment, never interpolated into them
SLUG: ${{ inputs.slug }}
FROM: ${{ inputs.from }}
run: |
printf '%s' "$SLUG" | grep -Eqx '[a-z0-9]([a-z0-9-]{0,40}[a-z0-9])?' || { echo "::error::bad slug: $SLUG"; exit 1; }
[ -z "$FROM" ] || printf '%s' "$FROM" | grep -Eqx '[A-Za-z0-9._/-]{1,100}' || { echo "::error::bad branch: $FROM"; exit 1; }
- uses: actions/checkout@v5
with:
ref: ${{ inputs.from || 'gh-pages' }}
path: work
fetch-depth: 1
sparse-checkout: ventures/${{ inputs.slug }}
persist-credentials: false # the build that runs next must not find a token in .git/config
- uses: actions/setup-node@v4
with:
node-version: 22
- name: find Chrome, or install Playwright's Chromium
run: |
set -eu
for c in google-chrome google-chrome-stable chromium chromium-browser; do
if command -v "$c" >/dev/null 2>&1; then
echo "CHROME=$(command -v "$c")" >> "$GITHUB_ENV"; echo "using $(command -v "$c")"; exit 0
fi
done
echo "no Chrome on this runner: installing Playwright's Chromium"
npx -y playwright@1.55.0 install --with-deps chromium > /tmp/pw.log 2>&1 || { tail -20 /tmp/pw.log; exit 1; }
c=$(find "$HOME/.cache/ms-playwright" -type f -name chrome -path '*chrome-linux*' | head -1)
[ -n "$c" ] && [ -x "$c" ] || { echo "::error::no Chromium after the install"; exit 1; }
echo "CHROME=$c" >> "$GITHUB_ENV"; echo "using $c"
- name: build
env:
SLUG: ${{ inputs.slug }}
CHROME_FLAGS: "--no-sandbox --disable-dev-shm-usage --disable-gpu"
run: |
set -eu
[ -f "work/ventures/$SLUG/tools/build.sh" ] || { echo "::error::ventures/$SLUG has no tools/build.sh"; exit 1; }
sh "work/ventures/$SLUG/tools/build.sh"
- uses: actions/checkout@v5
with:
ref: gh-pages
path: pages
fetch-depth: 1
- name: commit what changed
env:
SLUG: ${{ inputs.slug }}
FROM: ${{ inputs.from }}
run: |
set -eu
[ -f "pages/ventures/ventures.json" ] || { echo "::error::no ledger on gh-pages"; exit 1; }
find "work/ventures/$SLUG" -name __pycache__ -type d -prune -exec rm -rf {} +
if [ -n "$FROM" ]; then
# a rework from another branch lands whole, in place of what gh-pages has
rm -rf "pages/ventures/$SLUG"
cp -R "work/ventures/$SLUG" "pages/ventures/$SLUG"
cd pages
git add --all "ventures/$SLUG"
else
# the build's own changes only, applied to the newest gh-pages: the source was checked out minutes ago, and
# copying it whole would revert whatever landed since (it did, once)
cd work
git add --all "ventures/$SLUG"
git diff --cached --binary > ../build.patch
cd ../pages
git pull -q --rebase origin gh-pages
if [ -s ../build.patch ]; then
git apply --index --3way ../build.patch || { echo "::error::the build's changes don't apply to gh-pages as it stands now: refresh again"; exit 1; }
fi
fi
if git diff --cached --quiet; then echo "nothing changed in ventures/$SLUG"; exit 0; fi
git diff --cached --stat | tail -25
git -c user.name='github-actions[bot]' -c user.email='github-actions[bot]@users.noreply.teahub.xyz' \
commit -q -m "ventures: refresh $SLUG${FROM:+ from $FROM}"
if ! git push -q origin HEAD:gh-pages; then # gh-pages moved under us: replay this one commit on top
git pull -q --rebase origin gh-pages
git push -q origin HEAD:gh-pages
fi
echo "refreshed: ventures/$SLUG -> https://$SLUG.yolopreneur.lol/"
- name: tell Teahub pages to pull
run: curl -fsS -X POST "https://yolopreneur.lol/_hook/${GITHUB_REPOSITORY}" || echo "pages pulls by itself within five minutes"