Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/publish-sample-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@"
Expand Down
22 changes: 17 additions & 5 deletions scripts/check-modified-samples.sh
Original file line number Diff line number Diff line change
@@ -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

Loading