From c97e3d505f3b7cfe69304646ab9e2bf45d712f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bot=20of=20Thomas=20G=C3=BCttler?= Date: Tue, 26 May 2026 07:35:18 +0200 Subject: [PATCH] fix: skip deploy when HEAD already successfully deployed (#264) (#265) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - The hourly `deploy.yml` schedule re-deployed the same commit repeatedly because it always diffed `HEAD~1..HEAD` — once a commit touching `lib/`/`pubspec.*` became HEAD, every hourly tick would detect "android changes" and deploy again. - Fix: at the start of the `check-changes` job, query the Forgejo workflow runs API for the last successful `deploy.yml` run. If its `head_sha` matches current HEAD, output `android=false` / `linux=false` immediately, skipping all downstream jobs. - `workflow_dispatch` bypasses this check (always deploys), matching the existing behaviour. ## Test plan - [ ] Verify the `check-changes` job exits early on the next scheduled run after a successful deploy of the same commit - [ ] Verify a new commit still triggers deployment normally - [ ] Verify `workflow_dispatch` still deploys unconditionally 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Thomas SharedInbox Reviewed-on: https://codeberg.org/guettli/sharedinbox/pulls/265 --- .forgejo/workflows/deploy.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 7abb008..3ad7b15 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -22,6 +22,8 @@ jobs: - name: Detect Android and Linux changes id: diff shell: bash + env: + FORGEJO_TOKEN: ${{ github.token }} run: | # On workflow_dispatch always build everything if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then @@ -30,6 +32,38 @@ jobs: exit 0 fi + HEAD_SHA=$(git rev-parse HEAD) + + # Skip if this exact commit was already successfully deployed (prevents + # hourly schedule from redeploying the same commit on every tick). + LAST_DEPLOYED_SHA=$(python3 - << 'PYEOF' + import json, os, sys, urllib.request + token = os.environ.get("FORGEJO_TOKEN", "") + server = os.environ.get("GITHUB_SERVER_URL", "").rstrip("/") + repo = os.environ.get("GITHUB_REPOSITORY", "") + url = f"{server}/api/v1/repos/{repo}/actions/runs?workflow_id=deploy.yml&status=success&limit=5" + req = urllib.request.Request(url, headers={"Authorization": f"token {token}"}) + try: + with urllib.request.urlopen(req) as r: + data = json.loads(r.read()) + runs = [ + r for r in data.get("workflow_runs", []) + if r.get("workflow_id") == "deploy.yml" and r.get("status") == "success" + ] + print(runs[0]["head_sha"] if runs else "") + except Exception as e: + print(f"API check failed: {e}", file=sys.stderr) + print("") + PYEOF + ) + + if [ -n "$LAST_DEPLOYED_SHA" ] && [ "$HEAD_SHA" = "$LAST_DEPLOYED_SHA" ]; then + echo "HEAD $HEAD_SHA already successfully deployed — skipping" + echo "android=false" >> "$GITHUB_OUTPUT" + echo "linux=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + # Diff the HEAD commit against its parent; fall back to listing HEAD's files # when the parent is unavailable (initial commit, shallow clone). CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null \