-
Notifications
You must be signed in to change notification settings - Fork 872
355 lines (314 loc) · 17.1 KB
/
Copy pathcheck_release_notes.yml
File metadata and controls
355 lines (314 loc) · 17.1 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
name: Check release notes
on:
pull_request_target:
types: [opened, synchronize, reopened, labeled, unlabeled]
branches:
- 'main'
- 'release/*'
permissions:
contents: read
issues: write
pull-requests: write
concurrency:
group: release-notes-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
check_release_notes:
permissions:
contents: read
issues: write
pull-requests: write
env:
GH_TOKEN: ${{ github.token }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_LABELS: ${{ toJSON(github.event.pull_request.labels) }}
PR_NUMBER: ${{ github.event.pull_request.number }}
OPT_OUT_RELEASE_NOTES: ${{ contains(github.event.pull_request.labels.*.name, 'NO_RELEASE_NOTES') }}
VNEXT: ${{ vars.VNEXT }}
runs-on: ubuntu-latest
steps:
- name: Check for release notes changes
id: release_notes_changes
run: |
set -euo pipefail
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
FSHARP_REPO_URL="https://github.com/${GITHUB_REPOSITORY}"
PR_URL="${FSHARP_REPO_URL}/pull/${PR_NUMBER}"
[[ "$PR_BASE_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::Unexpected base SHA: $PR_BASE_SHA"; exit 1; }
[[ "$PR_HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::Unexpected head SHA: $PR_HEAD_SHA"; exit 1; }
echo "PR Tags: $PR_LABELS"
echo "Opt out of release notes: $OPT_OUT_RELEASE_NOTES"
_current_head_sha=$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" --jq '.head.sha')
if [[ "$_current_head_sha" != "$PR_HEAD_SHA" ]]; then
echo "::notice::Skipping stale release-note run for ${PR_HEAD_SHA}; current head is ${_current_head_sha}."
exit 0
fi
# VNEXT is a GitHub repository variable set via admin settings
# It controls the expected release notes version for FSharp.Core and FCS
if [[ -z "$VNEXT" ]]; then
echo "Error: VNEXT repository variable is not set. Please configure it in GitHub repository settings."
exit 1
fi
# Parse VS major version from eng/Versions.props for the vNext pattern
# <VSMajorVersion>18</VSMajorVersion>
_versions_props=$(
gh api \
-H 'Accept: application/vnd.github.raw+json' \
"repos/${GITHUB_REPOSITORY}/contents/eng/Versions.props?ref=${PR_BASE_SHA}"
)
_vs_major_version=$(
sed -n 's:.*<VSMajorVersion>\([^<]*\)</VSMajorVersion>.*:\1:p' <<< "$_versions_props" \
| head -n 1
)
FSHARP_CORE_VERSION="$VNEXT"
VISUAL_STUDIO_VERSION="$_vs_major_version.vNext"
echo "Using VNEXT for release notes: ${VNEXT}"
echo "Visual Studio release notes: ${VISUAL_STUDIO_VERSION}"
[[ "$VNEXT" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || (echo " Invalid VNEXT format (expected X.Y.Z)"; exit 1)
[[ "$_vs_major_version" =~ ^[0-9]+$ ]] || (echo " Invalid VS major version parsed"; exit 1)
_release_notes_base_path='docs/release-notes'
_fsharp_core_release_notes_path="${_release_notes_base_path}/.FSharp.Core/${FSHARP_CORE_VERSION}.md"
_fsharp_compiler_release_notes_path="${_release_notes_base_path}/.FSharp.Compiler.Service/${FSHARP_CORE_VERSION}.md"
_fsharp_language_release_notes_path="${_release_notes_base_path}/.Language/preview.md"
_fsharp_vs_release_notes_path="${_release_notes_base_path}/.VisualStudio/${VISUAL_STUDIO_VERSION}.md"
readonly paths=(
"src/FSharp.Core|${_fsharp_core_release_notes_path}"
"src/Compiler|${_fsharp_compiler_release_notes_path}"
"src/Compiler/Facilities/LanguageFeatures.fsi|${_fsharp_language_release_notes_path}"
"vsintegration/src|${_fsharp_vs_release_notes_path}"
)
# Check all changed paths
RELEASE_NOTES_MESSAGE=""
RELEASE_NOTES_MESSAGE_DETAILS=""
RELEASE_NOTES_FOUND=""
RELEASE_NOTES_NOT_FOUND=""
PULL_REQUEST_FOUND=true
_modified_files=$(
gh api \
--method GET \
--paginate \
--slurp \
"repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files" \
-f per_page=100
)
_modified_count=$(jq '[.[][]] | length' <<< "$_modified_files")
# GitHub caps this endpoint at 3,000 files. At the cap the response may be
# incomplete, so fail closed instead of silently missing a protected path.
if (( _modified_count >= 3000 )); then
echo "::error::Cannot safely validate a PR with 3,000 or more changed files."
exit 1
fi
path_changed() {
jq -e --arg path "$1" \
'any(.[][]; .filename == $path or (.filename | startswith($path + "/")))' \
<<< "$_modified_files" >/dev/null
}
release_note_url() {
jq -r --arg file "$1" \
'first(.[][] | select(.filename == $file and .status != "removed") | .contents_url) // empty' \
<<< "$_modified_files"
}
record_missing_release_note() {
local path="$1"
local release_notes="$2"
local description="**No release notes found or release notes format is not correct**"
RELEASE_NOTES_NOT_FOUND+="| \\\`$path\\\` | [$release_notes](${FSHARP_REPO_URL}/tree/main/$release_notes) | ${description} |"
RELEASE_NOTES_NOT_FOUND+=$'\n'
}
for fields in "${paths[@]}"; do
IFS=$'|' read -r path release_notes <<< "$fields"
echo "Checking for changed files in: $path"
# Check if path is in modified files:
if path_changed "$path"; then
echo " Found $path in modified files"
echo " Checking if release notes modified in: $release_notes"
if path_changed "$release_notes"; then
echo " Found $release_notes in modified files"
echo " Checking for pull request URL in $release_notes"
_release_note_url=$(release_note_url "$release_notes")
if [[ -n "$_release_note_url" ]]; then
if [[ "$_release_note_url" != "https://api.github.com/repos/${GITHUB_REPOSITORY}/contents/"* ]] \
|| [[ "$_release_note_url" != *"?ref=${PR_HEAD_SHA}" ]]; then
echo "::error::Release-note content URL does not target the expected repository and PR head."
exit 1
fi
_release_note_file=$(mktemp)
if ! gh api \
-H 'Accept: application/vnd.github.raw+json' \
"$_release_note_url" > "$_release_note_file"
then
rm -f "$_release_note_file"
echo "::error::Unable to read $release_notes at PR head $PR_HEAD_SHA."
exit 1
fi
_pr_link_occurrences=$(grep -Fc -- "$PR_URL" "$_release_note_file" || true)
rm -f "$_release_note_file"
echo " Found $_pr_link_occurrences occurrences of $PR_URL in $release_notes"
if [[ ${_pr_link_occurrences} -eq 1 ]]; then
echo " Found pull request URL in $release_notes once"
RELEASE_NOTES_FOUND+="> | \\\`$path\\\` | [$release_notes](${FSHARP_REPO_URL}/tree/main/$release_notes) | |"
RELEASE_NOTES_FOUND+=$'\n'
elif [[ ${_pr_link_occurrences} -eq 0 ]]; then
echo " Did not find pull request URL in $release_notes"
DESCRIPTION="**No current pull request URL (${PR_URL}) found, please consider adding it**"
RELEASE_NOTES_FOUND+="> | \\\`$path\\\` | [$release_notes](${FSHARP_REPO_URL}/tree/main/$release_notes) | ${DESCRIPTION} |"
RELEASE_NOTES_FOUND+=$'\n'
PULL_REQUEST_FOUND=false
fi
else
echo " $release_notes was removed or cannot be read at the PR head."
record_missing_release_note "$path" "$release_notes"
fi
else
echo " Did not find $release_notes in modified files"
record_missing_release_note "$path" "$release_notes"
fi
else
echo " Nothing found, no release notes required"
fi
done
echo "Done checking for release notes changes"
if [[ $RELEASE_NOTES_NOT_FOUND != "" ]]; then
RELEASE_NOTES_MESSAGE_DETAILS+=$"@${PR_AUTHOR},"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$"> [!CAUTION]"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$"> **No release notes found for the changed paths (see table below).**"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$">"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$"> Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on [Keep A Changelog](https://keepachangelog.com/en/1.1.0/) format."
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$">"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$"> **The following format is recommended for this repository:**"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$">"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$">"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$"> \\\`* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))\\\`"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$">"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$">"
RELEASE_NOTES_MESSAGE_DETAILS+=$"> See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html."
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$'**If you believe that release notes are not necessary for this PR, please add <kbd>NO_RELEASE_NOTES</kbd> label to the pull request.**'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+='| Change path | Release notes path | Description |'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+='| ---------------- | ------------------ | ----------- |'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+="${RELEASE_NOTES_NOT_FOUND}"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
fi
if [[ $RELEASE_NOTES_FOUND != "" ]]; then
RELEASE_NOTES_MESSAGE_DETAILS+=$"<hr/>"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$"> :white_check_mark: Found changes and release notes in following paths:"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
if [[ $PULL_REQUEST_FOUND = false ]]; then
RELEASE_NOTES_MESSAGE_DETAILS+=$"> [!WARNING]"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$"> **No PR link found in some release notes, please consider adding it.**"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
fi
RELEASE_NOTES_MESSAGE_DETAILS+='> | Change path | Release notes path | Description |'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+='> | ---------------- | ------------------ | ----------- |'
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
RELEASE_NOTES_MESSAGE_DETAILS+="${RELEASE_NOTES_FOUND}"
RELEASE_NOTES_MESSAGE_DETAILS+=$'\n'
fi
RELEASE_NOTES_MESSAGE+=$'<!-- DO_NOT_REMOVE: release_notes_check -->\n'
if [[ $RELEASE_NOTES_MESSAGE_DETAILS == "" ]]; then
RELEASE_NOTES_MESSAGE+=$'## :white_check_mark: No release notes required\n\n'
else
RELEASE_NOTES_MESSAGE+=$'## :heavy_exclamation_mark: Release notes required\n\n'
RELEASE_NOTES_MESSAGE+=$"**You can open this PR in browser to add release notes: [open in github.dev](https://github.dev/dotnet/fsharp/pull/${PR_NUMBER})**"
RELEASE_NOTES_MESSAGE+=$'\n\n'
RELEASE_NOTES_MESSAGE+=$RELEASE_NOTES_MESSAGE_DETAILS
fi
_current_head_sha=$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" --jq '.head.sha')
if [[ "$_current_head_sha" != "$PR_HEAD_SHA" ]]; then
echo "::notice::Discarding stale release-note result for ${PR_HEAD_SHA}; current head is ${_current_head_sha}."
exit 0
fi
{
echo "release-notes-check-message<<$EOF"
if [[ "$OPT_OUT_RELEASE_NOTES" = true ]]; then
echo "<!-- DO_NOT_REMOVE: release_notes_check -->"
echo ""
echo "## :warning: Release notes required, but author opted out"
echo ""
echo ""
echo "> [!WARNING]"
echo "> **Author opted out of release notes, check is disabled for this pull request.**"
echo "> cc @dotnet/fsharp-team-msft"
else
echo "${RELEASE_NOTES_MESSAGE}"
fi
echo "$EOF"
} >> "$GITHUB_OUTPUT"
if [[ $RELEASE_NOTES_NOT_FOUND != "" && ${OPT_OUT_RELEASE_NOTES} != true ]]; then
exit 1
fi
# Keep one bot comment current without evaluating pull request content as JavaScript.
# Posting the informational comment is best-effort and must never fail the check:
# this job runs via pull_request_target, and the Actions GITHUB_TOKEN is not always
# permitted to create a new issue comment (the comment API can return HTTP 403
# "Resource not accessible by integration"), even though release-notes validation
# above has already succeeded.
- name: Create or update comment
if: ${{ (success() || failure()) && steps.release_notes_changes.outputs.release-notes-check-message != '' }}
continue-on-error: true
uses: actions/github-script@v9
env:
COMMENT_BODY: ${{ steps.release_notes_changes.outputs.release-notes-check-message }}
with:
github-token: ${{ github.token }}
script: |
const marker = '<!-- DO_NOT_REMOVE: release_notes_check -->';
try {
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100
});
const existing = comments.find(comment =>
comment.user?.login === 'github-actions[bot]' && comment.body?.includes(marker));
if (existing) {
const comment = await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: process.env.COMMENT_BODY
});
return comment.data.id;
}
const comment = await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.COMMENT_BODY
});
return comment.data.id;
} catch (error) {
// The comment is informational only. The release-notes verdict is enforced by the
// "Check for release notes changes" step, so never fail the job if posting fails
// (e.g. a read-only token on some pull requests).
core.warning(`Unable to post release-notes comment: ${error.message}`);
}