-
-
Notifications
You must be signed in to change notification settings - Fork 174
220 lines (201 loc) · 9.62 KB
/
Copy pathchangelog-check.yml
File metadata and controls
220 lines (201 loc) · 9.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: Release Documentation Check
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled, ready_for_review]
jobs:
check-release-docs:
name: Check for changelog and roadmap updates
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
- name: Check if PR has minor or major label and targets main
id: check-labels
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: |
# Skip checks for draft PRs entirely
IS_DRAFT=$(gh pr view "$PR_NUMBER" --json isDraft --jq '.isDraft')
if [ "$IS_DRAFT" = "true" ]; then
echo "requires_docs=false" >> $GITHUB_OUTPUT
echo "✅ PR is a draft - release documentation check skipped"
exit 0
fi
LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
# Only require changelog for PRs targeting main branch
if [ "$BASE_REF" != "main" ]; then
echo "requires_docs=false" >> $GITHUB_OUTPUT
echo "✅ PR does not target main branch - release documentation not required"
exit 0
fi
if echo "$LABELS" | grep -qE '^(minor|major)$'; then
echo "requires_docs=true" >> $GITHUB_OUTPUT
echo "PR targets main and has minor or major label - release documentation required"
else
echo "requires_docs=false" >> $GITHUB_OUTPUT
echo "PR does not have minor or major label - release documentation not required"
fi
- name: Check for new blog post
if: steps.check-labels.outputs.requires_docs == 'true'
id: check-blog
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
# Use git diff directly instead of gh pr diff to avoid API limitations
# GitHub's diff API has a limit of ~300 files or ~3000 lines, which fails on large PRs
# git diff works locally without these limitations
echo "Checking for blog post files between $BASE_SHA and $HEAD_SHA"
NEW_BLOG_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" | grep -E '^website/blog/.*\.(md|mdx)$' | grep -v 'tags.yml' || true)
if [ -z "$NEW_BLOG_FILES" ]; then
echo "has_changelog=false" >> $GITHUB_OUTPUT
echo "❌ No changelog entry found"
else
echo "has_changelog=true" >> $GITHUB_OUTPUT
echo "blog_files<<EOF" >> $GITHUB_OUTPUT
echo "$NEW_BLOG_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "✅ Changelog entry found:"
echo "$NEW_BLOG_FILES"
fi
- name: Check for roadmap update
if: steps.check-labels.outputs.requires_docs == 'true'
id: check-roadmap
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
# Check if website/src/data/roadmap.js was modified
echo "Checking for roadmap updates between $BASE_SHA and $HEAD_SHA"
ROADMAP_CHANGED=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" | grep -E '^website/src/data/roadmap\.js$' || true)
if [ -z "$ROADMAP_CHANGED" ]; then
echo "has_roadmap=false" >> $GITHUB_OUTPUT
echo "❌ No roadmap update found"
else
echo "has_roadmap=true" >> $GITHUB_OUTPUT
echo "✅ Roadmap update found"
fi
- name: Comment on PR if documentation missing
if: |
steps.check-labels.outputs.requires_docs == 'true' &&
(steps.check-blog.outputs.has_changelog == 'false' || steps.check-roadmap.outputs.has_roadmap == 'false')
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HAS_CHANGELOG: ${{ steps.check-blog.outputs.has_changelog }}
HAS_ROADMAP: ${{ steps.check-roadmap.outputs.has_roadmap }}
GH_REPO: ${{ github.repository }}
run: |
# Build checklist based on what's missing
MISSING_ITEMS=""
if [ "$HAS_CHANGELOG" = "false" ]; then
MISSING_ITEMS="${MISSING_ITEMS}
> - [ ] **Changelog entry** - Add a blog post in \`website/blog/YYYY-MM-DD-feature-name.mdx\`"
else
MISSING_ITEMS="${MISSING_ITEMS}
> - [x] **Changelog entry** ✅"
fi
if [ "$HAS_ROADMAP" = "false" ]; then
MISSING_ITEMS="${MISSING_ITEMS}
> - [ ] **Roadmap update** - Update \`website/src/data/roadmap.js\` with the new milestone"
else
MISSING_ITEMS="${MISSING_ITEMS}
> - [x] **Roadmap update** ✅"
fi
# Check if comment already exists
EXISTING_COMMENT=$(gh pr view "$PR_NUMBER" --json comments --jq '.comments[] | select(.body | contains("<!-- release-docs-check -->")) | .id' | head -1)
COMMENT_BODY="<!-- release-docs-check -->
> [!WARNING]
> #### Release Documentation Required
>
> This PR is labeled \`minor\` or \`major\` and requires documentation updates:
${MISSING_ITEMS}
>
> **Alternatively:** If this change doesn't require release documentation, remove the \`minor\` or \`major\` label."
if [ -n "$EXISTING_COMMENT" ]; then
echo "Updating existing comment..."
gh api -X PATCH "/repos/${GH_REPO}/issues/comments/$EXISTING_COMMENT" \
-f body="$COMMENT_BODY" || {
echo "⚠️ Failed to update comment, creating new one..."
gh pr comment "$PR_NUMBER" --body "$COMMENT_BODY"
}
else
echo "Creating new comment..."
gh pr comment "$PR_NUMBER" --body "$COMMENT_BODY"
fi
- name: Update comment with success message
if: |
steps.check-labels.outputs.requires_docs == 'true' &&
steps.check-blog.outputs.has_changelog == 'true' &&
steps.check-roadmap.outputs.has_roadmap == 'true'
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
BLOG_FILES: ${{ steps.check-blog.outputs.blog_files }}
GH_REPO: ${{ github.repository }}
run: |
# Find existing comment (warning or success)
EXISTING_COMMENT=$(gh pr view "$PR_NUMBER" --json comments --jq '.comments[] | select(.body | contains("<!-- release-docs-check -->")) | .id' | head -1)
EXISTING_COMMENT_BODY=$(gh pr view "$PR_NUMBER" --json comments --jq '.comments[] | select(.body | contains("<!-- release-docs-check -->")) | .body' | head -1)
SUCCESS_COMMENT_BODY="<!-- release-docs-check -->
> [!NOTE]
> #### Release Documentation Complete ✅
>
> - [x] **Changelog:** $(echo "$BLOG_FILES" | head -1 | sed 's/^/`/' | sed 's/$/`/')
> - [x] **Roadmap:** \`website/src/data/roadmap.js\`
>
> Thank you!"
if [ -n "$EXISTING_COMMENT" ]; then
# Check if comment already shows success
if echo "$EXISTING_COMMENT_BODY" | grep -q "Release Documentation Complete ✅"; then
echo "ℹ️ Comment already shows success - no update needed"
else
echo "Updating existing comment with success message..."
gh api -X PATCH "/repos/${GH_REPO}/issues/comments/$EXISTING_COMMENT" \
-f body="$SUCCESS_COMMENT_BODY" || {
echo "⚠️ Failed to update comment (it may have been deleted)"
}
echo "✅ Comment updated from warning to success"
fi
else
echo "ℹ️ No existing comment to update (comment only created when documentation is missing)"
fi
- name: Fail if documentation missing
if: |
steps.check-labels.outputs.requires_docs == 'true' &&
(steps.check-blog.outputs.has_changelog == 'false' || steps.check-roadmap.outputs.has_roadmap == 'false')
env:
HAS_CHANGELOG: ${{ steps.check-blog.outputs.has_changelog }}
HAS_ROADMAP: ${{ steps.check-roadmap.outputs.has_roadmap }}
run: |
echo "❌ ERROR: PR is labeled 'minor' or 'major' but release documentation is incomplete."
echo ""
if [ "$HAS_CHANGELOG" = "false" ]; then
echo "Missing: Changelog entry"
echo " → Add a blog post in website/blog/YYYY-MM-DD-feature-name.mdx"
echo ""
fi
if [ "$HAS_ROADMAP" = "false" ]; then
echo "Missing: Roadmap update"
echo " → Update website/src/data/roadmap.js with the new milestone"
echo ""
fi
echo "If this change should not require release documentation, remove the 'minor' or 'major' label."
exit 1
- name: Success
if: |
steps.check-labels.outputs.requires_docs == 'false' ||
(steps.check-blog.outputs.has_changelog == 'true' && steps.check-roadmap.outputs.has_roadmap == 'true')
env:
REQUIRES_DOCS: ${{ steps.check-labels.outputs.requires_docs }}
run: |
if [ "$REQUIRES_DOCS" = "false" ]; then
echo "✅ No release documentation required for this PR"
else
echo "✅ Release documentation complete - check passed"
fi