diff --git a/.github/workflows/recipe-security-scanner.yml b/.github/workflows/recipe-security-scanner.yml index 4e8d0b327e53..83d6709061ca 100644 --- a/.github/workflows/recipe-security-scanner.yml +++ b/.github/workflows/recipe-security-scanner.yml @@ -43,9 +43,9 @@ jobs: echo "📝 Synchronize event - checking files changed since previous commit" CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.before }}..${{ github.event.after }}) else - # For opened/reopened, check all files in the PR + # For opened/reopened, check all files in the PR (compare PR head against base) echo "📝 PR opened/reopened - checking all files in PR" - CHANGED_FILES=$(git diff --name-only --diff-filter=AM origin/${{ github.base_ref }}..HEAD) + CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}) fi echo "Changed files in this push:" @@ -78,9 +78,9 @@ jobs: echo "📝 Synchronize event - checking files changed/added since previous commit" CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.before }}..${{ github.event.after }}) else - # For opened/reopened, check all files in the PR (new and modified) + # For opened/reopened, check all files in the PR (compare PR head against base) echo "📝 PR opened/reopened - checking all new/modified files in PR" - CHANGED_FILES=$(git diff --name-only --diff-filter=AM origin/${{ github.base_ref }}..HEAD) + CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}) fi # Filter for recipe files only that were changed or added diff --git a/.github/workflows/send-api-key.yml b/.github/workflows/send-api-key.yml index dfaf6ce7d51c..f40e1e7202c3 100644 --- a/.github/workflows/send-api-key.yml +++ b/.github/workflows/send-api-key.yml @@ -24,15 +24,20 @@ jobs: set -e echo "🔍 Checking if recipe files were added or modified in merged PR..." - # Get the current commit (merge commit) and the previous commit on the base branch - CURRENT_COMMIT=$(git rev-parse HEAD) - PREVIOUS_COMMIT=$(git rev-parse HEAD~1) + # Get the PR merge information + MERGE_COMMIT=$(git rev-parse HEAD) + echo "Merge commit: $MERGE_COMMIT" - echo "Current commit: $CURRENT_COMMIT" - echo "Previous commit: $PREVIOUS_COMMIT" + # For merged PRs, compare the PR's changes against the base branch + # Use the PR information from the event to get the actual changes + BASE_SHA="${{ github.event.pull_request.base.sha }}" + HEAD_SHA="${{ github.event.pull_request.head.sha }}" - # Get the list of files that were added or modified in this merge (not deleted) - CHANGED_FILES=$(git diff --name-only --diff-filter=AM $PREVIOUS_COMMIT..$CURRENT_COMMIT) + echo "PR base SHA: $BASE_SHA" + echo "PR head SHA: $HEAD_SHA" + + # Get the list of files that were added or modified in the PR (not deleted) + CHANGED_FILES=$(git diff --name-only --diff-filter=AM $BASE_SHA..$HEAD_SHA) echo "Files added/modified in merged PR:" echo "$CHANGED_FILES" diff --git a/.github/workflows/validate-recipe-pr.yml b/.github/workflows/validate-recipe-pr.yml index ad412659cf17..04529c7f6348 100644 --- a/.github/workflows/validate-recipe-pr.yml +++ b/.github/workflows/validate-recipe-pr.yml @@ -56,9 +56,9 @@ jobs: echo "📝 Synchronize event - checking files changed since previous commit" CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.before }}..${{ github.event.after }}) else - # For opened/reopened, check all files in the PR + # For opened/reopened, check all files in the PR (compare PR head against base) echo "📝 PR opened/reopened - checking all files in PR" - CHANGED_FILES=$(git diff --name-only --diff-filter=AM origin/${{ github.base_ref }}..HEAD) + CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}) fi echo "Changed files in this push:" @@ -87,13 +87,13 @@ jobs: echo "📝 Synchronize event - checking files changed/added since previous commit" CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.before }}..${{ github.event.after }}) else - # For opened/reopened, check all files in the PR (new and modified) + # For opened/reopened, check all files in the PR (compare PR head against base) echo "📝 PR opened/reopened - checking all new/modified files in PR" - CHANGED_FILES=$(git diff --name-only --diff-filter=AM origin/${{ github.base_ref }}..HEAD) + CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}) fi # Filter for recipe files only that were changed or added - RECIPE_FILES=$(git diff --diff-filter=AM --name-only origin/${{ github.base_ref }}..HEAD | grep "^documentation/src/pages/recipes/data/recipes/" | grep -E "\.(yaml|yml)$" || true) + RECIPE_FILES=$(echo "$CHANGED_FILES" | grep "^documentation/src/pages/recipes/data/recipes/" | grep -E "\.(yaml|yml)$" || true) if [ -z "$RECIPE_FILES" ]; then echo "No changed recipe files found in PR" @@ -159,7 +159,7 @@ jobs: # Check if this is a new file or an update to existing file # Get list of changed files in this PR compared to base branch - CHANGED_FILES=$(git diff --name-only --diff-filter=AM origin/${{ github.event.pull_request.base.ref }}...HEAD | grep "^$RECIPE_FILE$" || true) + CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | grep "^$RECIPE_FILE$" || true) EXISTING_FILES=$(find documentation/src/pages/recipes/data/recipes/ -name "$FILENAME.yaml" -o -name "$FILENAME.yml" | grep -v "^$RECIPE_FILE$" || true) if [ -n "$EXISTING_FILES" ] && [ -z "$CHANGED_FILES" ]; then