From 2ffb7752664b10f5b029160940cc73317433ede2 Mon Sep 17 00:00:00 2001 From: defangdevs Date: Wed, 22 Jul 2026 08:55:38 -0700 Subject: [PATCH] fix(ci): sync sample templates across the whole push range, not just the tip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `publish-sample-template.yml` already runs on every push to main, but `check-modified-samples.sh` only diffs `HEAD~1..HEAD` (matched by `fetch-depth: 2`). When a push lands more than one commit on main at once — a rebase-merge, or a direct multi-commit push — only the last commit is inspected, so a sample changed in any earlier commit silently fails to republish its template repo. Squash-merges (one commit per push) happen to be safe, which is why it usually works. Diff the full push range instead: pass `github.event.before` as `BEFORE_SHA` and check `${BEFORE_SHA}..HEAD`, with `fetch-depth: 0` so that SHA is reachable. Falls back to `HEAD~1` for manual runs or an unknown/first-push before-SHA (empty, all-zeros, or not fetched). Verified locally against real history: a simulated 3-commit push now detects both `crewai` and `self-improving-mastra`, where the old range saw only the tip commit's `self-improving-mastra`; all fallbacks degrade to the prior single-commit behavior. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Sw7j9FYnbChZJbYArxbhuo --- .github/workflows/publish-sample-template.yml | 9 ++++++-- scripts/check-modified-samples.sh | 22 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish-sample-template.yml b/.github/workflows/publish-sample-template.yml index 47f54194a..1ea094e2a 100644 --- a/.github/workflows/publish-sample-template.yml +++ b/.github/workflows/publish-sample-template.yml @@ -15,11 +15,16 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - # Fetch two to see changes in current commit - fetch-depth: 2 + # Full history so the push's "before" SHA is reachable for the diff + # below (a push can add several commits at once). + fetch-depth: 0 - name: Run Checks id: checks + env: + # Diff the whole push range, not just the tip commit, so every sample + # touched anywhere in the push republishes its template. + BEFORE_SHA: ${{ github.event.before }} run: | ./scripts/check-modified-samples.sh > modified.txt echo "@@ MODIFIED @@" diff --git a/scripts/check-modified-samples.sh b/scripts/check-modified-samples.sh index 0462ce505..f46b35753 100755 --- a/scripts/check-modified-samples.sh +++ b/scripts/check-modified-samples.sh @@ -1,12 +1,24 @@ #!/bin/bash -# This script checks which samples have been created or modified since the last commit and prints a list of them. +# Lists samples created or modified by the commits this push added to the +# branch, so their template repos can be republished. +# +# We diff across the WHOLE push range (github.event.before .. HEAD), not just +# the tip commit: a single push can land several commits at once (rebase-merge, +# or a direct multi-commit push), and every touched sample must sync — not only +# the one in the last commit. Falls back to HEAD~1 for manual runs or an +# unknown/first-push before-SHA (all zeros, or not fetched). + +before="${BEFORE_SHA:-}" +zero="0000000000000000000000000000000000000000" +if [ -z "$before" ] || [ "$before" = "$zero" ] || ! git rev-parse --verify --quiet "${before}^{commit}" > /dev/null 2>&1; then + before="HEAD~1" +fi for dir in samples/*/; do - # Use git diff to check if the directory has been created or modified between the last commit and the commit before it - if git diff --name-only --diff-filter=d HEAD~1..HEAD | grep -q "^${dir}"; then - # If it has, print the name of the directory + # Print the directory if any file under it changed across the push range + # (--diff-filter=d excludes pure deletions, which can't be republished). + if git diff --name-only --diff-filter=d "${before}..HEAD" | grep -q "^${dir}"; then echo "$dir" fi done -