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 -