You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sanitized_files=$(echo "$files" | sed 's/[^a-zA-Z0-9._/-]/_/g')
28
+
29
+
# Store the sanitized list of files in a temporary file to avoid env variable issues
30
+
echo "$sanitized_files" > modified_files.txt
31
+
32
+
- name: Fetch PR message
33
+
id: pr-message
34
+
env:
35
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36
+
run: |
37
+
# Use the GitHub API to fetch the PR message
38
+
pr_message=$(gh pr view ${{ github.event.pull_request.number }} --json body -q '.body')
39
+
40
+
# Sanitize the PR message to avoid code injection, keeping the equal sign
41
+
sanitized_pr_message=$(echo "$pr_message" | sed 's/[^a-zA-Z0-9._/-=]/_/g')
42
+
43
+
# Store the sanitized PR message
44
+
echo "$sanitized_pr_message" > pr_message.txt
45
+
46
+
- name: Verify NEXT_CHANGELOG.md was modified or PR message contains NO_CHANGELOG=true
47
+
run: |
48
+
# Read the sanitized files and PR message from the temporary files
49
+
modified_files=$(cat modified_files.txt)
50
+
pr_message=$(cat pr_message.txt)
51
+
52
+
# Check if NEXT_CHANGELOG.md exists in the list of changed files
53
+
echo "Changed files: $modified_files"
54
+
if ! echo "$modified_files" | grep -q "NEXT_CHANGELOG.md"; then
55
+
echo "NEXT_CHANGELOG.md not modified."
56
+
57
+
# Check if PR message contains NO_CHANGELOG=true
58
+
if echo "$pr_message" | grep -q "NO_CHANGELOG=true"; then
59
+
echo "NO_CHANGELOG=true found in PR message. Skipping changelog check."
60
+
exit 0
61
+
else
62
+
echo "WARNING: file NEXT_CHANGELOG.md not changed. If this is expected, add NO_CHANGELOG=true to the PR message."
63
+
exit 1
64
+
fi
65
+
fi
66
+
67
+
- name: Comment on PR with instructions if needed
68
+
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)
69
+
env:
70
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71
+
run: |
72
+
# Check if a comment exists with the instructions
73
+
previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
Please ensure that the NEXT_CHANGELOG.md file is updated with any relevant changes.
83
+
If this is not necessary for your PR, please include the following in your PR description:
84
+
NO_CHANGELOG=true
85
+
and rerun the job."
86
+
fi
87
+
88
+
- name: Delete instructions comment on success
89
+
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)
90
+
env:
91
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92
+
run: |
93
+
# Check if there is a previous instructions comment
94
+
previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
0 commit comments