Skip to content

fix(ci): sync sample templates across the whole push range, not just the tip commit#655

Open
defangdevs wants to merge 1 commit into
DefangLabs:mainfrom
defangdevs:fix/template-sync-full-push-range
Open

fix(ci): sync sample templates across the whole push range, not just the tip commit#655
defangdevs wants to merge 1 commit into
DefangLabs:mainfrom
defangdevs:fix/template-sync-full-push-range

Conversation

@defangdevs

Copy link
Copy Markdown
Contributor

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.yml runs on every push to main (good, no path filter), but the change-detection in check-modified-samples.sh only diffs the tip commit:

git diff --name-only --diff-filter=d HEAD~1..HEAD   # + checkout fetch-depth: 2

A 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:

  • Pass github.event.before into the script as BEFORE_SHA.
  • Diff ${BEFORE_SHA}..HEAD.
  • fetch-depth: 0 so the before-SHA is reachable.
  • Fall back to HEAD~1 for 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.sh and .github/workflows/publish-sample-template.yml.

Verification

Run locally against real history, simulating a push that landed the last 3 commits:

Range Samples detected
old HEAD~1..HEAD (tip only) self-improving-mastra
new HEAD~3..HEAD (full push) crewai, self-improving-mastra

So the new logic catches crewai, which the old logic would have dropped. Fallbacks (BEFORE_SHA unset / all-zeros / bogus) all degrade cleanly to the previous single-commit result, exit 0.

🤖 Generated with Claude Code

…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
@lionello
lionello requested a review from raphaeltm July 22, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant