janhoy commented on code in PR #5099:
URL: https://github.com/apache/solr/pull/5099#discussion_r4239414264


##########
.github/workflows/validate-changelog.yml:
##########
@@ -31,46 +34,58 @@ jobs:
       )
     runs-on: ubuntu-latest
 
-    steps:
-    - name: Checkout code
-      uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
-      with:
-        fetch-depth: 0
+    permissions:
+      contents: read
+      issues: read         # the PR's labels
+      pull-requests: read  # the PR's changed files
+
+    # This job never executes code from the pull request. It reads the PR as 
data
+    # through the API, writes that data outside the workspace, and the only 
thing
+    # it runs is the validator script as it exists on the base commit.
+    env:
+      GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      REPO: ${{ github.repository }}
+      PR_NUMBER: ${{ github.event.pull_request.number }}
+      HEAD_SHA: ${{ github.event.pull_request.head.sha }}
 
+    steps:
     - name: Check for no-changelog label
       id: check-label
-      env:
-        HAS_NO_CHANGELOG_LABEL: ${{ 
contains(github.event.pull_request.labels.*.name, 'no-changelog') }}
       run: |
-        if [ "$HAS_NO_CHANGELOG_LABEL" = "true" ]; then
-          echo "skip=true" >> "$GITHUB_OUTPUT"
-        else
-          echo "skip=false" >> "$GITHUB_OUTPUT"
+        set -euo pipefail
+        # Ask the API rather than reading github.event.pull_request.labels: a 
re-run
+        # replays the original event payload, which predates the label we care 
about.
+        has_label=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/labels" \
+          --jq '[.[].name] | index("no-changelog") != null')
+        if [ "$has_label" = "true" ]; then
+          echo "::notice::PR#${PR_NUMBER} has the 'no-changelog' label; 
skipping validation"
         fi
+        echo "skip=${has_label}" >> "$GITHUB_OUTPUT"
 
     - name: Check for changelog entry
+      id: entry
       if: steps.check-label.outputs.skip == 'false'
       run: |
-        # Get the list of changed files
-        CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref 
}}...HEAD)
+        set -euo pipefail
+        files="$RUNNER_TEMP/pr-files.tsv"
+        entries="$RUNNER_TEMP/entry-paths.txt"
 
-        # Check if any files were added to changelog/unreleased/
-        if echo "$CHANGED_FILES" | grep -q "^changelog/unreleased/"; then
+        gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" \
+          --jq '.[] | [.status, .filename] | @tsv' > "$files"

Review Comment:
   No need to support this



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to