fix(ci): sync sample templates across the whole push range, not just the tip commit#655
Open
defangdevs wants to merge 1 commit into
Open
fix(ci): sync sample templates across the whole push range, not just the tip commit#655defangdevs wants to merge 1 commit into
defangdevs wants to merge 1 commit into
Conversation
…the tip
`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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sw7j9FYnbChZJbYArxbhuo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Guarantee that a sample's template repo (
DefangSamples/sample-<name>-template) is republished whenever main moves and touches that sample.Current behavior
publish-sample-template.ymlruns on every push to main (good, no path filter), but the change-detection incheck-modified-samples.shonly diffs the tip commit:git diff --name-only --diff-filter=d HEAD~1..HEAD # + checkout fetch-depth: 2A single push can add multiple commits to main at once — a rebase-merge, or a direct multi-commit push. In those cases only the last commit is inspected, so any sample changed in an earlier commit of the push silently fails to republish. Squash-merges (one commit per push) happen to be safe, which is why it's worked so far.
Fix
Diff the entire push range instead of the tip:
github.event.beforeinto the script asBEFORE_SHA.${BEFORE_SHA}..HEAD.fetch-depth: 0so the before-SHA is reachable.HEAD~1for manual runs or an unknown/first-push before-SHA (empty, all-zeros, or not fetched) — preserves today's behavior in those cases.Two-file change:
scripts/check-modified-samples.shand.github/workflows/publish-sample-template.yml.Verification
Run locally against real history, simulating a push that landed the last 3 commits:
HEAD~1..HEAD(tip only)self-improving-mastraHEAD~3..HEAD(full push)crewai,self-improving-mastraSo the new logic catches
crewai, which the old logic would have dropped. Fallbacks (BEFORE_SHAunset / all-zeros / bogus) all degrade cleanly to the previous single-commit result, exit 0.🤖 Generated with Claude Code