mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-09-27 22:05:56 +01:00
Replace the nightly cron and its check-changes job with a debounce. Every push to main starts dev-image-debounce.yml, which waits out the 60-minute wait timer on the dev-image-debounce environment, then dispatches the Docker workflow only if main still points at its commit. A burst of merges now publishes one dev image, an hour after the last merge. The Docker workflow keeps only its tag and workflow_dispatch triggers, so its history holds real builds only. The debounce workflow deletes its own finished runs, so no-op runs don't pile up either. Requires the dev-image-debounce environment with a 60-minute wait timer (Settings → Environments).
52 lines
2.0 KiB
YAML
52 lines
2.0 KiB
YAML
name: Debounce dev image
|
|
# A burst of merges to main should publish one dev image, not one per commit.
|
|
# Each push to main waits out the 60-minute wait timer on the
|
|
# dev-image-debounce environment (Settings → Environments; waiting holds no
|
|
# runner), then dispatches the Docker workflow only if main still points at
|
|
# its commit. So only the last push of a burst builds, and the Docker
|
|
# workflow's history holds real builds only.
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
permissions: {}
|
|
|
|
jobs:
|
|
debounce:
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: dev-image-debounce
|
|
deployment: false
|
|
permissions:
|
|
actions: write # dispatch the build, delete finished debounce runs
|
|
contents: read
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
GH_REPO: ${{ github.repository }}
|
|
steps:
|
|
- name: Dispatch the dev build if main is still at this commit
|
|
env:
|
|
CURRENT_SHA: ${{ github.sha }}
|
|
run: |
|
|
HEAD_SHA=$(gh api "repos/${GH_REPO}/git/ref/heads/main" --jq '.object.sha')
|
|
echo "This run's commit: ${CURRENT_SHA}"
|
|
echo "main HEAD now: ${HEAD_SHA}"
|
|
if [[ "$HEAD_SHA" == "$CURRENT_SHA" ]]; then
|
|
echo "No newer commits on main — dispatching the dev build."
|
|
gh workflow run build-and-publish-docker-image.yml --ref main
|
|
else
|
|
echo "main has moved on — the newer push's run will build it."
|
|
fi
|
|
|
|
# A finished debounce run is noise: it either did nothing or its build
|
|
# run is the record. Best effort, since runs from the same burst race to
|
|
# delete the same runs.
|
|
- name: Delete finished debounce runs
|
|
run: |
|
|
# On an HTTP error gh prints the error body to stdout, so bail out
|
|
# rather than loop over it.
|
|
ids=$(gh api "repos/${GH_REPO}/actions/workflows/dev-image-debounce.yml/runs?status=success&per_page=100" --jq '.workflow_runs[].id') || exit 0
|
|
for id in $ids; do
|
|
gh api -X DELETE "repos/${GH_REPO}/actions/runs/${id}" || true
|
|
done
|