1+ name : Check for NEXT_CHANGELOG.md Changes
2+
3+ on :
4+ pull_request_target :
5+ branches : [ main ]
6+
7+ permissions :
8+ contents : read
9+ pull-requests : write
10+
11+ jobs :
12+ check-next-changelog :
13+ runs-on :
14+ group : databricks-protected-runner-group
15+ labels : linux-ubuntu-latest
16+
17+ steps :
18+ - name : Checkout base branch (main)
19+ uses : actions/checkout@v4
20+ with :
21+ ref : ${{ github.event.pull_request.base.ref }}
22+ fetch-depth : 0
23+
24+ - name : Fetch list of changed files
25+ id : changed-files
26+ run : |
27+ files=$(git diff --name-only HEAD^ HEAD || git diff --name-only origin/main HEAD)
28+ echo "MODIFIED_FILES<<EOF" >> $GITHUB_ENV
29+ echo "$files" >> $GITHUB_ENV
30+ echo "EOF" >> $GITHUB_ENV
31+
32+ - name : Verify NEXT_CHANGELOG.md was modified or PR message contains NO_CHANGELOG=true
33+ id : verify-changelog
34+ run : |
35+ PR_BODY="${{ github.event.pull_request.body }}"
36+ echo "PR body: $PR_BODY"
37+
38+ if ! echo "$MODIFIED_FILES" | grep -q "NEXT_CHANGELOG.md"; then
39+ if echo "$PR_BODY" | grep -q "NO_CHANGELOG=true"; then
40+ echo "NO_CHANGELOG=true found in PR body."
41+ echo "CHANGELOG_NEEDED=false" >> $GITHUB_ENV
42+ exit 0
43+ else
44+ echo "ERROR: NEXT_CHANGELOG.md not modified and NO_CHANGELOG=true not present."
45+ echo "CHANGELOG_NEEDED=true" >> $GITHUB_ENV
46+ exit 1
47+ fi
48+ else
49+ echo "✅ NEXT_CHANGELOG.md was updated."
50+ echo "CHANGELOG_NEEDED=false" >> $GITHUB_ENV
51+ fi
52+
53+ - name : Comment on PR with instructions if needed
54+ if : failure() && env.CHANGELOG_NEEDED == 'true'
55+ uses : actions/github-script@v7
56+ with :
57+ github-token : ${{ secrets.GITHUB_TOKEN }}
58+ script : |
59+ const { owner, repo } = context.repo;
60+ const issue_number = context.issue.number;
61+
62+ // Check if we've already commented
63+ const comments = await github.rest.issues.listComments({
64+ owner,
65+ repo,
66+ issue_number
67+ });
68+
69+ const existingComment = comments.data.find(comment =>
70+ comment.body.includes('<!-- NEXT_CHANGELOG_INSTRUCTIONS -->')
71+ );
72+
73+ if (!existingComment) {
74+ await github.rest.issues.createComment({
75+ owner,
76+ repo,
77+ issue_number,
78+ body: `<!-- NEXT_CHANGELOG_INSTRUCTIONS -->
79+ Please ensure that the \`NEXT_CHANGELOG.md\` file is updated with any relevant changes.
80+ If this is not necessary for your PR, include this in the PR body:
81+
82+ \`\`\`
83+ NO_CHANGELOG=true
84+ \`\`\`
85+
86+ and rerun the workflow.`
87+ });
88+ }
89+
90+ - name : Delete instructions comment on success
91+ if : success() && env.CHANGELOG_NEEDED == 'false'
92+ uses : actions/github-script@v7
93+ with :
94+ github-token : ${{ secrets.GITHUB_TOKEN }}
95+ script : |
96+ const { owner, repo } = context.repo;
97+ const issue_number = context.issue.number;
98+
99+ const comments = await github.rest.issues.listComments({
100+ owner,
101+ repo,
102+ issue_number
103+ });
104+
105+ const existingComments = comments.data.filter(comment =>
106+ comment.body.includes('<!-- NEXT_CHANGELOG_INSTRUCTIONS -->')
107+ );
108+
109+ for (const comment of existingComments) {
110+ await github.rest.issues.deleteComment({
111+ owner,
112+ repo,
113+ comment_id: comment.id
114+ });
115+ }
0 commit comments