From abf304d875c82a7a14af4671ab1916d3eacf570e Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Fri, 25 Apr 2025 12:02:36 +0530 Subject: [PATCH 1/7] Fix next changelog task --- .github/workflows/checkNextChangelog.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/checkNextChangelog.yml b/.github/workflows/checkNextChangelog.yml index 5f22510069..3716c304b1 100644 --- a/.github/workflows/checkNextChangelog.yml +++ b/.github/workflows/checkNextChangelog.yml @@ -33,10 +33,11 @@ jobs: id: verify-changelog run: | PR_BODY="${{ github.event.pull_request.body }}" - echo "PR body: $PR_BODY" + echo 'PR body:' "$PR_BODY" if ! echo "$MODIFIED_FILES" | grep -q "NEXT_CHANGELOG.md"; then - if echo "$PR_BODY" | grep -q "NO_CHANGELOG=true"; then + NO_CHANGELOG_FLAG=$(echo "$PR_BODY" | grep -c "NO_CHANGELOG=true" || true) + if [ "$NO_CHANGELOG_FLAG" -gt 0 ]; then echo "NO_CHANGELOG=true found in PR body." echo "CHANGELOG_NEEDED=false" >> $GITHUB_ENV exit 0 From 35506640829b618f3eaf462fe5798bdced05803d Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Fri, 25 Apr 2025 12:10:53 +0530 Subject: [PATCH 2/7] Fix next changelog task --- .github/workflows/checkNextChangelog.yml | 50 +++++++++++++++--------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/.github/workflows/checkNextChangelog.yml b/.github/workflows/checkNextChangelog.yml index 3716c304b1..d73da76f07 100644 --- a/.github/workflows/checkNextChangelog.yml +++ b/.github/workflows/checkNextChangelog.yml @@ -31,25 +31,37 @@ jobs: - name: Verify NEXT_CHANGELOG.md was modified or PR message contains NO_CHANGELOG=true id: verify-changelog - run: | - PR_BODY="${{ github.event.pull_request.body }}" - echo 'PR body:' "$PR_BODY" - - if ! echo "$MODIFIED_FILES" | grep -q "NEXT_CHANGELOG.md"; then - NO_CHANGELOG_FLAG=$(echo "$PR_BODY" | grep -c "NO_CHANGELOG=true" || true) - if [ "$NO_CHANGELOG_FLAG" -gt 0 ]; then - echo "NO_CHANGELOG=true found in PR body." - echo "CHANGELOG_NEEDED=false" >> $GITHUB_ENV - exit 0 - else - echo "ERROR: NEXT_CHANGELOG.md not modified and NO_CHANGELOG=true not present." - echo "CHANGELOG_NEEDED=true" >> $GITHUB_ENV - exit 1 - fi - else - echo "✅ NEXT_CHANGELOG.md was updated." - echo "CHANGELOG_NEEDED=false" >> $GITHUB_ENV - fi + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + // Get the latest PR data, including the body + const { data: pullRequest } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + }); + + const PR_BODY = pullRequest.body || ''; + console.log('Latest PR body:', PR_BODY); + + // Check if NEXT_CHANGELOG.md is modified + const modifiedFiles = process.env.MODIFIED_FILES || ''; + const changelogModified = modifiedFiles.includes('NEXT_CHANGELOG.md'); + + if (!changelogModified) { + if (PR_BODY.includes('NO_CHANGELOG=true')) { + console.log("NO_CHANGELOG=true found in PR body."); + core.exportVariable('CHANGELOG_NEEDED', 'false'); + } else { + console.log("ERROR: NEXT_CHANGELOG.md not modified and NO_CHANGELOG=true not present."); + core.exportVariable('CHANGELOG_NEEDED', 'true'); + core.setFailed("NEXT_CHANGELOG.md not modified and NO_CHANGELOG=true not present in PR body."); + } + } else { + console.log("✅ NEXT_CHANGELOG.md was updated."); + core.exportVariable('CHANGELOG_NEEDED', 'false'); + } - name: Comment on PR with instructions if needed if: failure() && env.CHANGELOG_NEEDED == 'true' From 783e158cfe14c906de3db97fe0a660bb293208ed Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Fri, 25 Apr 2025 12:14:43 +0530 Subject: [PATCH 3/7] Fix next changelog task --- .github/workflows/checkNextChangelog.yml | 175 ++++++++++------------- 1 file changed, 79 insertions(+), 96 deletions(-) diff --git a/.github/workflows/checkNextChangelog.yml b/.github/workflows/checkNextChangelog.yml index d73da76f07..ae4be650f3 100644 --- a/.github/workflows/checkNextChangelog.yml +++ b/.github/workflows/checkNextChangelog.yml @@ -23,106 +23,89 @@ jobs: - name: Fetch list of changed files id: changed-files + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - files=$(git diff --name-only HEAD^ HEAD || git diff --name-only origin/main HEAD) - echo "MODIFIED_FILES<> $GITHUB_ENV - echo "$files" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV + # Use the GitHub API to fetch changed files + files=$(gh pr view ${{ github.event.pull_request.number }} --json files -q '.files[].path') + + # Sanitize to avoid code injection + sanitized_files=$(echo "$files" | sed 's/[^a-zA-Z0-9._/-]/_/g') + + # Store the sanitized list of files in a temporary file to avoid env variable issues + echo "$sanitized_files" > modified_files.txt + + - name: Fetch PR message + id: pr-message + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Use the GitHub API to fetch the PR message + pr_message=$(gh pr view ${{ github.event.pull_request.number }} --json body -q '.body') + + # Sanitize the PR message to avoid code injection, keeping the equal sign + sanitized_pr_message=$(echo "$pr_message" | sed 's/[^a-zA-Z0-9._/-=]/_/g') + + # Store the sanitized PR message + echo "$sanitized_pr_message" > pr_message.txt - name: Verify NEXT_CHANGELOG.md was modified or PR message contains NO_CHANGELOG=true - id: verify-changelog - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - // Get the latest PR data, including the body - const { data: pullRequest } = await github.rest.pulls.get({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.issue.number, - }); - - const PR_BODY = pullRequest.body || ''; - console.log('Latest PR body:', PR_BODY); - - // Check if NEXT_CHANGELOG.md is modified - const modifiedFiles = process.env.MODIFIED_FILES || ''; - const changelogModified = modifiedFiles.includes('NEXT_CHANGELOG.md'); - - if (!changelogModified) { - if (PR_BODY.includes('NO_CHANGELOG=true')) { - console.log("NO_CHANGELOG=true found in PR body."); - core.exportVariable('CHANGELOG_NEEDED', 'false'); - } else { - console.log("ERROR: NEXT_CHANGELOG.md not modified and NO_CHANGELOG=true not present."); - core.exportVariable('CHANGELOG_NEEDED', 'true'); - core.setFailed("NEXT_CHANGELOG.md not modified and NO_CHANGELOG=true not present in PR body."); - } - } else { - console.log("✅ NEXT_CHANGELOG.md was updated."); - core.exportVariable('CHANGELOG_NEEDED', 'false'); - } + run: | + # Read the sanitized files and PR message from the temporary files + modified_files=$(cat modified_files.txt) + pr_message=$(cat pr_message.txt) + + # Check if NEXT_CHANGELOG.md exists in the list of changed files + echo "Changed files: $modified_files" + if ! echo "$modified_files" | grep -q "NEXT_CHANGELOG.md"; then + echo "NEXT_CHANGELOG.md not modified." + + # Check if PR message contains NO_CHANGELOG=true + if echo "$pr_message" | grep -q "NO_CHANGELOG=true"; then + echo "NO_CHANGELOG=true found in PR message. Skipping changelog check." + exit 0 + else + echo "WARNING: file NEXT_CHANGELOG.md not changed. If this is expected, add NO_CHANGELOG=true to the PR message." + exit 1 + fi + fi - name: Comment on PR with instructions if needed - if: failure() && env.CHANGELOG_NEEDED == 'true' - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { owner, repo } = context.repo; - const issue_number = context.issue.number; - - // Check if we've already commented - const comments = await github.rest.issues.listComments({ - owner, - repo, - issue_number - }); - - const existingComment = comments.data.find(comment => - comment.body.includes('') - ); - - if (!existingComment) { - await github.rest.issues.createComment({ - owner, - repo, - issue_number, - body: ` - Please ensure that the \`NEXT_CHANGELOG.md\` file is updated with any relevant changes. - If this is not necessary for your PR, include this in the PR body: - - \`\`\` - NO_CHANGELOG=true - \`\`\` - - and rerun the workflow.` - }); - } + if: failure() # This step will only run if the previous step fails (i.e., if NEXT_CHANGELOG.md was not modified and NO_CHANGELOG=true was not in the PR message) + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Check if a comment exists with the instructions + previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ + --jq '.[] | select(.body | startswith("")) | .id') + echo "Previous comment IDs: $previous_comment_ids" + + # If no previous comment exists, add one with instructions + if [ -z "$previous_comment_ids" ]; then + echo "Adding instructions comment." + gh pr comment ${{ github.event.pull_request.number }} --body \ + " + Please ensure that the NEXT_CHANGELOG.md file is updated with any relevant changes. + If this is not necessary for your PR, please include the following in your PR description: + NO_CHANGELOG=true + and rerun the job." + fi - name: Delete instructions comment on success - if: success() && env.CHANGELOG_NEEDED == 'false' - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { owner, repo } = context.repo; - const issue_number = context.issue.number; - - const comments = await github.rest.issues.listComments({ - owner, - repo, - issue_number - }); - - const existingComments = comments.data.filter(comment => - comment.body.includes('') - ); - - for (const comment of existingComments) { - await github.rest.issues.deleteComment({ - owner, - repo, - comment_id: comment.id - }); - } \ No newline at end of file + if: success() # This step will only run if the previous check passed (i.e., if NEXT_CHANGELOG.md was modified or NO_CHANGELOG=true is in the PR message) + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Check if there is a previous instructions comment + previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \ + --jq '.[] | select(.body | startswith("")) | .id') + + # If a comment exists, delete it + if [ -n "$previous_comment_ids" ]; then + echo "Deleting previous instructions comment." + for comment_id in $previous_comment_ids; do + gh api "repos/${{ github.repository }}/issues/comments/$comment_id" --method DELETE + done + else + echo "No instructions comment found to delete." + fi \ No newline at end of file From acf7d22fda06cc64496a068a6a82d6c94a298f4d Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Fri, 25 Apr 2025 12:17:03 +0530 Subject: [PATCH 4/7] test --- .github/workflows/checkNextChangelog.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkNextChangelog.yml b/.github/workflows/checkNextChangelog.yml index ae4be650f3..99788ee46a 100644 --- a/.github/workflows/checkNextChangelog.yml +++ b/.github/workflows/checkNextChangelog.yml @@ -2,7 +2,7 @@ name: Check for NEXT_CHANGELOG.md Changes on: pull_request_target: - branches: [ main ] + # branches: [ main ] permissions: contents: read From b851a47b0b99c4d98fd2724734e2706743d45e59 Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Fri, 25 Apr 2025 12:25:50 +0530 Subject: [PATCH 5/7] test --- .github/workflows/checkNextChangelog.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/checkNextChangelog.yml b/.github/workflows/checkNextChangelog.yml index 99788ee46a..d4cbf4bad7 100644 --- a/.github/workflows/checkNextChangelog.yml +++ b/.github/workflows/checkNextChangelog.yml @@ -34,6 +34,7 @@ jobs: # Store the sanitized list of files in a temporary file to avoid env variable issues echo "$sanitized_files" > modified_files.txt + echo "#sanitized_files" - name: Fetch PR message id: pr-message @@ -48,6 +49,7 @@ jobs: # Store the sanitized PR message echo "$sanitized_pr_message" > pr_message.txt + echo "$sanitized_pr_message" - name: Verify NEXT_CHANGELOG.md was modified or PR message contains NO_CHANGELOG=true run: | From 4d1edd24bc5f9c9966e463cabc4099d53356d0cb Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Fri, 25 Apr 2025 12:33:05 +0530 Subject: [PATCH 6/7] test --- .github/workflows/checkNextChangelog.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkNextChangelog.yml b/.github/workflows/checkNextChangelog.yml index d4cbf4bad7..997f50a648 100644 --- a/.github/workflows/checkNextChangelog.yml +++ b/.github/workflows/checkNextChangelog.yml @@ -34,7 +34,7 @@ jobs: # Store the sanitized list of files in a temporary file to avoid env variable issues echo "$sanitized_files" > modified_files.txt - echo "#sanitized_files" + echo "$sanitized_files" - name: Fetch PR message id: pr-message From 60c7dd4c8b230b9bee32099cf85efd069e42fa8f Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Fri, 25 Apr 2025 12:36:55 +0530 Subject: [PATCH 7/7] only on main --- .github/workflows/checkNextChangelog.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkNextChangelog.yml b/.github/workflows/checkNextChangelog.yml index 997f50a648..c98262f647 100644 --- a/.github/workflows/checkNextChangelog.yml +++ b/.github/workflows/checkNextChangelog.yml @@ -2,7 +2,7 @@ name: Check for NEXT_CHANGELOG.md Changes on: pull_request_target: - # branches: [ main ] + branches: [ main ] permissions: contents: read