@cratis/pi 7.3.4 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/corpus/harnesses/pi/extensions/cratis-hooks/index.ts +19 -2
- package/package/corpus/hooks/README.md +59 -3
- package/package/corpus/hooks/scripts/cratis-check-pr.mjs +397 -0
- package/package/corpus/hooks/scripts/cratis-guard-pr-body.sh +41 -0
- package/package/corpus/hooks/scripts/cratis-release-notes-reviewed.cjs +867 -0
- package/package/corpus/hooks/settings.template.json +4 -0
- package/package/corpus/prompts/ship-changes.prompt.md +7 -2
- package/package/corpus/rules/pull-requests.md +15 -5
- package/package/corpus/skills/cratis-release-notes/SKILL.md +10 -7
- package/package/corpus/skills/cratis-release-notes/verification.json +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,867 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
// Exact marked programs from Cratis/Workflows at 40125b4fcae388e62ed9471edfffd0e991422f0a.
|
|
4
|
+
"use strict";
|
|
5
|
+
if (process.argv[2] === "release-notes") {
|
|
6
|
+
"use strict";
|
|
7
|
+
// cratis:program release-notes
|
|
8
|
+
const fs = require("node:fs");
|
|
9
|
+
|
|
10
|
+
const ALLOWED = ["Added", "Changed", "Fixed", "Removed", "Security", "Deprecated"];
|
|
11
|
+
const ALLOWED_LIST = ALLOWED.map(name => `## ${name}`).join(", ");
|
|
12
|
+
const REVIEWER_HEADINGS = ["test plan", "testing", "tests", "verification", "verified", "validation",
|
|
13
|
+
"quality", "review", "notes", "notes for reviewers", "limitations", "known follow-up", "acceptance",
|
|
14
|
+
"checked locally", "out of scope", "not verified", "not tested", "draft"];
|
|
15
|
+
// Result headings with a qualifier: "Checks (local)", "Checks (local, mirroring dotnet-build.yml)", "Local
|
|
16
|
+
// checks", "CI results". A bare `### CI` stays allowed: it can group CI changes inside a section.
|
|
17
|
+
const REVIEWER_HEADING = /^(?:(?:checks?|ci|tests?|local)\s*\(.*\)|(?:local|ci)\s+(?:checks?|results?|status|runs?|gates?)|(?:checks?|gates?)\s+run)$/;
|
|
18
|
+
const isReviewerHeading = name => REVIEWER_HEADINGS.includes(name) || REVIEWER_HEADING.test(name);
|
|
19
|
+
const NARRATIVE_HEADINGS = ["overview", "description", "what", "why", "how", "context", "details"];
|
|
20
|
+
const CHANGE_HEADINGS = ["changes", "what changed"];
|
|
21
|
+
const FORBIDDEN_HEADINGS = [...REVIEWER_HEADINGS, ...NARRATIVE_HEADINGS, ...CHANGE_HEADINGS];
|
|
22
|
+
const isForbiddenHeading = name => FORBIDDEN_HEADINGS.includes(name) || REVIEWER_HEADING.test(name);
|
|
23
|
+
const PLACEHOLDERS = [
|
|
24
|
+
"Describe a new user-facing capability",
|
|
25
|
+
"Describe a user-facing behavior change",
|
|
26
|
+
"Describe a user-facing fix",
|
|
27
|
+
"Optional summary of the PR",
|
|
28
|
+
"Short statement of what was added",
|
|
29
|
+
"Short statement of what changed",
|
|
30
|
+
"Short statement of what was fixed",
|
|
31
|
+
"Short statement of what was removed",
|
|
32
|
+
"Short statement of the security fix",
|
|
33
|
+
"Short statement of what is deprecated",
|
|
34
|
+
];
|
|
35
|
+
const VERBATIM = "This pull request description is published verbatim as the release notes; editing the description re-runs this check.";
|
|
36
|
+
const PR_COMMENT = "Move test plans, verification, review notes and provenance to a pull request comment.";
|
|
37
|
+
|
|
38
|
+
// Code is shown, not published as prose: the same fences and inline spans release-action ignores.
|
|
39
|
+
const FENCED_CODE = /^[ \t]*(`{3,}|~{3,})[\s\S]*?^[ \t]*\1[ \t]*$/gm;
|
|
40
|
+
const INLINE_CODE = /(`+)[^\n]*?\1/g;
|
|
41
|
+
const HTML_COMMENT = /<!--[\s\S]*?-->/g;
|
|
42
|
+
const KEYWORD = /\b(close[sd]?|fix(?:e[sd])?|resolve[sd]?|refs?|references)(?:[ \t]*:[ \t]*|[ \t]+)((?:[\w.-]+\/[\w.-]+)?#(\d+))/gi;
|
|
43
|
+
const KEYWORD_URL = /\b(close[sd]?|fix(?:e[sd])?|resolve[sd]?|refs?|references)(?:[ \t]*:[ \t]*|[ \t]+)(https?:\/\/(?:www\.)?github\.com\/([\w.-]+\/[\w.-]+)\/(?:issues|pull)\/(\d+))/gi;
|
|
44
|
+
// The pattern release-action closes issues with.
|
|
45
|
+
// It sees everything but fenced and inline code: HTML comments are not skipped.
|
|
46
|
+
const CLOSES_ISSUE = /(?<![\w/-])\(#(\d+)\)/g;
|
|
47
|
+
// What may follow the delivering `(#n)` and still count as the end of the bullet: more issue references
|
|
48
|
+
// (`(part of #n)`, `(see #n)`, `(Cratis/Repo#n)` too), closing emphasis, a trailing `<br>` and sentence
|
|
49
|
+
// punctuation (a `:` may introduce nested bullets).
|
|
50
|
+
const ONLY_ISSUES_AFTER = /^(?:\s*(?:\((?:(?:part of|see) )?(?:[\w.-]+\/[\w.-]+)?#\d+\)|\*\*|__|\*|_|<br\s*\/?>|[.,;:!?]))*\s*$/i;
|
|
51
|
+
// `(#56, #57)` closes nothing: release-action only recognises a `(#n)` of its own.
|
|
52
|
+
const GROUPED_ISSUES = /\(#\d+(?:\s*[, ]\s*#\d+)+\)/g;
|
|
53
|
+
// Labels that only ever introduce process notes, bullet or not.
|
|
54
|
+
const PROCESS_LABEL = /^\s*(?:(?:[-*+]|\d{1,9}[.)])\s+)?(?:\*\*|__|\*|_)?(?:test plan|notes? (?:for|to) reviewers?|reviewer notes?|known follow-up)(?:\s*:|(?:\*\*|__|\*|_)\s*:)/i;
|
|
55
|
+
// "Reviewed by ..." opens a note only outside a bullet or prose section: "- Reviewed by status is now shown
|
|
56
|
+
// on the dashboard (#4)" is a product bullet, and "Reviewed by Claude" is caught by the provenance rules.
|
|
57
|
+
const REVIEWED_BY = /^\s*(?:(?:[-*+]|\d{1,9}[.)])\s+)?(?:\*\*|__|\*|_)?reviewed by\b/i;
|
|
58
|
+
// Labels that can also open a product bullet ("- Validation: rules now apply to commands (#3)", "- Review:
|
|
59
|
+
// requests are now sent when a pull request is ready (#4)"): they are notes when standalone, when not a
|
|
60
|
+
// bullet under a section, or when what follows reports a test, CI or review result.
|
|
61
|
+
const RESULT_LABEL = /^\s*(?<bullet>(?:[-*+]|\d{1,9}[.)])\s+)?(?:\*\*|__|\*|_)?(?:validation|testing|verification|tests?|test results?|review|reviewed|tested|verified|local|locally|checked locally|local checks|checks|ci|ci results|gates?)(?:\s*:|(?:\*\*|__|\*|_)\s*:)(?<rest>.*)$/i;
|
|
62
|
+
// A result is reported, not described: the result word ends the clause ("all green", "12 specs passed"),
|
|
63
|
+
// so "failed commands now return a 400" and "green-field templates" stay product wording.
|
|
64
|
+
const END = String.raw`\s*(?=[.,;!:(]|$)`;
|
|
65
|
+
const RESULT_WORDING = new RegExp([
|
|
66
|
+
String.raw`\b\d+\s+(?:\w+\s+)?(?:passed|passing|failed|failing)\b`,
|
|
67
|
+
String.raw`^\s*(?:all\s+(?:\w+\s+){0,2}?)?(?:passed|passing|pass|green|failed|failing|ok|okay|done|locally|yes|no|clean|approved|lgtm|good|fine|none|pending)${END}`,
|
|
68
|
+
String.raw`\ball\s+(?:\w+\s+){0,2}?(?:pass|passed|passing|green)${END}`,
|
|
69
|
+
String.raw`\b(?:tests?|specs?|builds?|gates?|checks?)\s+(?:pass|passed)${END}`,
|
|
70
|
+
String.raw`\breviewers?\s+(?:\w+\s+){0,2}approved\b|\blgtm\b|\bno (?:blocking |new )?(?:findings|concerns)\b`,
|
|
71
|
+
].join("|"), "i");
|
|
72
|
+
// A claim opens its own clause ("CI green, all tests passed."), so "The release is published when all tests
|
|
73
|
+
// pass" stays a product statement.
|
|
74
|
+
const CLAIM_START = String.raw`(?:^|[;,:.!]\s*)(?:(?:[-*+>]|\d{1,9}[.)])\s+)*(?:\*\*|__|\*|_)?\s*(?:done\s*[-;:,]\s*)?`;
|
|
75
|
+
const RESULT_CLAIM = new RegExp(CLAIM_START + "(?:" + [
|
|
76
|
+
String.raw`all\s+(?:(?:the|unit|integration)\s+)*tests?\s+(?:now\s+)?(?:pass|passed|passing)(?:${END}|\s+(?:locally|in\s+ci|again)\b)`,
|
|
77
|
+
String.raw`ci\s+(?:is\s+|was\s+|has\s+been\s+)?(?:green|passing|passed)(?:${END}|\s+(?:locally|again|and)\b)`,
|
|
78
|
+
].join("|") + ")", "i");
|
|
79
|
+
// Notes about the pull request rather than the change, recognised by their phrasing, wherever they stand: a
|
|
80
|
+
// bullet, the summary, the lead paragraph or a line of their own. Each pattern names how the note is
|
|
81
|
+
// worded, not its topic, so "Events are now verified against their schema" and "Toasts are stacked on top
|
|
82
|
+
// of each other" stay product wording.
|
|
83
|
+
// A clause opens a line (after list markers, a quote and emphasis) or follows sentence punctuation. Not a
|
|
84
|
+
// comma: "Forms are submitted, validated in the browser and saved" is product wording.
|
|
85
|
+
const CLAUSE = String.raw`(?:^\s*(?:(?:[-*+>]|\d{1,9}[.)])\s+)*(?:\*\*|__|\*|_)?|[;:.!(\u2014]\s*(?:\*\*|__|\*|_)?)`;
|
|
86
|
+
const CHECKED = String.raw`(?:verified|tested|checked|validated|confirmed|reproduced|exercised|smoke[- ]tested)`;
|
|
87
|
+
const CHECKED_BY = String.raw`(?:(?:this|it|everything(?: else)?|the rest|the (?:change|changes|fix|feature|branch|pr|pull request))\s+(?:was|were|has been|is)\s+)?(?:also\s+|only\s+|manually\s+|locally\s+)?${CHECKED}`;
|
|
88
|
+
// "locally", "manually" and "visually" end the note or lead into how ("Tested locally with ..."), so
|
|
89
|
+
// "- Validated locally stored tokens before use" stays product wording.
|
|
90
|
+
const HOW_CHECKED = String.raw`(?:(?:locally|manually|visually|by hand|end[- ]to[- ]end)(?=\s*(?:$|[.,;:)(*_\u2014-]|\s(?:with|and|on|in|by|against|using|via|before|after|first|too|only|as well|across|for|through)\b))|in (?:ci|storybook|the browser|a browser|a sandbox|the sandbox)\b|on (?:my|a local)\b|by (?:building|running|rebuilding|deploying|opening|installing|executing|starting|comparing)\b)`;
|
|
91
|
+
const PULL_REQUEST_REF = String.raw`(?:#\d+|[\w.-]+\/[\w.-]+#\d+|https:\/\/github\.com\/\S+\/pull\/\d+)`;
|
|
92
|
+
// The first match decides the message, so provenance comes before how a change was checked.
|
|
93
|
+
const PROCESS_NOTES = [
|
|
94
|
+
// Provenance: which branch or build it was checked against ("Verified against Arc.TypeScript main (v0.34.0)").
|
|
95
|
+
{ kind: "provenance", pattern: new RegExp(CLAUSE + CHECKED_BY + String.raw`\s+(?:[\w-]+\s+){0,2}?(?:against|on|with|from)\s+(?:the\s+)?(?:[\w@/.-]+\s+){0,2}?(?:(?:main|master|HEAD)(?:\s+branch)?(?=\s*(?:\(|[.,;:)]|$))|the default branch\b)`, "i") },
|
|
96
|
+
// ... or which kind of environment, where the note opens the clause ("Tested against a real kernel").
|
|
97
|
+
{ kind: "provenance", pattern: new RegExp(`${CLAUSE}${CHECKED_BY}\\s+(?:[\\w-]+\\s+){0,3}?(?:against|on|with)\\s+(?:a|the)\\s+(?:real|local|live|running)\\s+\\w`, "i") },
|
|
98
|
+
// How or where it was checked: "Verified by building the sample", "verified in Storybook", "Tested locally".
|
|
99
|
+
{ kind: "verification", pattern: new RegExp(`${CLAUSE}${CHECKED_BY}\\s+(?:[\\w-]+\\s+){0,2}?${HOW_CHECKED}`, "i") },
|
|
100
|
+
// What was not checked; the lookahead keeps "- Not verified events are rejected" product wording.
|
|
101
|
+
{ kind: "verification", pattern: new RegExp(CLAUSE + String.raw`(?:(?:this|it)\s+(?:is|was|has)\s+)?(?:not|never)\s+(?:yet\s+)?(?:been\s+)?(?:verified|tested|validated|exercised)(?=\s*(?:$|[.,;:)*_]|\s(?:against|on|with|in|here|yet|locally|end|by|manually|visually)\b))`, "i") },
|
|
102
|
+
// Scope notes: "Storybook only;", "Docs-only.", "Tests only (#3)".
|
|
103
|
+
{ kind: "verification", pattern: new RegExp(CLAUSE + String.raw`(?:storybook|docs?|documentation|specs?|tests?|ci|tooling)[- ]only(?:\s+(?:change|changes|pr|pull request|update))?\s*(?:[;.,:)]|\(#|$)`, "i") },
|
|
104
|
+
// Result counts: "specs 492/492", "Integration 110/110", "9 of 9 runs", "518 specs passed", "12 passed, 0 failed".
|
|
105
|
+
{ kind: "verification", pattern: /\b(?:specs?|tests?|runs?|checks?|jobs?|integration|unit|e2e|scenarios?)\s+(\d[\d,]*)\s*\/\s*\1\b|\b(\d[\d,]*)\s*\/\s*\2\s+(?:specs?|tests?|runs?|checks?|passed|passing|green)\b|\b\d[\d,]*\s+(?:tests?|specs?|scenarios?)\s+(?:passed|passing|green|failed|failing)\b|\b\d+\s+passed,\s*\d+\s+(?:failed|skipped)\b/i },
|
|
106
|
+
// "3 of 3 runs" is a count in prose ("The dashboard shows 3 of 3 runs completed for each observer"): a result
|
|
107
|
+
// only when it starts a clause or is followed by verification wording.
|
|
108
|
+
{ kind: "verification", pattern: new RegExp(CLAUSE + String.raw`(\d+)\s+of\s+\1\s+(?:runs|specs|tests|checks|scenarios)\b`, "i") },
|
|
109
|
+
{ kind: "verification", pattern: /\b(\d+)\s+of\s+\1\s+(?:runs|specs|tests|checks|scenarios)\s+(?:(?:all|have|had)\s+)?(?:passed|passing|green|succeeded|successful|failed|failing|ok)\b/i },
|
|
110
|
+
// Gate results: "Tier 1 PASS", "0 warnings, 0 errors".
|
|
111
|
+
{ kind: "verification", pattern: /\btier[ -]?[123]\b[^.\n]{0,20}?\b(?:pass(?:ed|es)?|green|ok|clean)\b|\b\d+\s+warnings?,\s*\d+\s+errors?\b/i },
|
|
112
|
+
// Reviewer instructions: stacking, retargeting, merge and deploy order, draft status.
|
|
113
|
+
{ kind: "instruction", pattern: new RegExp(String.raw`\bstacked\s+(?:on|onto)\s+(?:top of\s+)?(?:${PULL_REQUEST_REF}|(?:the\s+(?:other\s+)?|another\s+|this\s+)?(?:pr|pull request|branch)\b)|${CLAUSE}retarget(?:ed|ing)?\s+(?:it\s+|this\s+(?:pr\s+|pull request\s+)?)?(?:to|onto)\s+(?:main|master|the default branch)\b|\b(?:depends on|blocked by|merge (?:it\s+|this\s+)?(?:after|before)|land (?:it\s+|this\s+)?(?:after|before))\s+${PULL_REQUEST_REF}`, "i") },
|
|
114
|
+
// "This PR is ..." always speaks to reviewers; "this branch" only when it says what the branch needs, so
|
|
115
|
+
// "The CLI now warns when this branch is behind main" stays product wording.
|
|
116
|
+
{ kind: "instruction", pattern: /\bthis\s+(?:pr|pull request)\s+(?:is|was|should|must|needs|depends|requires|has to|can only|will need|replaces|supersedes|builds on|targets)\b/i },
|
|
117
|
+
{ kind: "instruction", pattern: new RegExp(CLAUSE + String.raw`this\s+branch\s+(?:should|must|needs|depends|requires|has to|can only|will need|replaces|supersedes|builds on|targets|is (?:stacked|based|built|part))\b`, "i") },
|
|
118
|
+
// "Do not merge" is an instruction when it opens a clause ("Do not merge until the kernel ships.") or says what not
|
|
119
|
+
// to merge yet; "Arrays in read models do not merge" and "should be deployed before" about other subjects are
|
|
120
|
+
// product wording.
|
|
121
|
+
{ kind: "instruction", pattern: new RegExp(String.raw`\b(?:before|after|once)\s+(?:merging|deploying|releasing)\s+this\s+(?:pr|pull request|branch|change)\b|${CLAUSE}(?:do not|don['\u2019]t)\s+merge(?=\s*(?:$|[.,;:!)]))|\b(?:do not|don['\u2019]t)\s+merge\s+(?:this|it|yet|until|before|after)\b|\b(?:this|it)\s+(?:pr\s+|pull request\s+)?should be (?:deployed|merged|released) (?:separately|together|first|after|before|alongside)\b`, "i") },
|
|
122
|
+
{ kind: "instruction", pattern: /^\s*(?:\*\*|__)?(?:draft|wip|dnm|reviewers?|for reviewers|note to reviewers)(?:\*\*|__)?\s*:/i },
|
|
123
|
+
];
|
|
124
|
+
const PROCESS_FIX = {
|
|
125
|
+
verification: "How or where the change was checked, what was not checked, and test or CI results are for reviewers: move them to a pull request comment. The release notes say only what changed for the reader.",
|
|
126
|
+
provenance: "Which branch, commit or build the change was checked against is for reviewers: move it to a pull request comment. If compatibility matters to the reader, state it as a fact, for example `Requires @cratis/arc 0.34 or later`.",
|
|
127
|
+
instruction: "Stacking, retargeting, merge or deploy order and draft status are for reviewers: move them to a pull request comment. If consumers must upgrade in a set order, write that as an upgrade bullet, for example `Upgrade the Chronicle kernel to 19.25 before this client`.",
|
|
128
|
+
};
|
|
129
|
+
const PROCESS_RULE = {
|
|
130
|
+
verification: "Review, verification or provenance note",
|
|
131
|
+
provenance: "Review, verification or provenance note",
|
|
132
|
+
instruction: "Reviewer instruction",
|
|
133
|
+
};
|
|
134
|
+
const BOLD_ONLY = /^\s*(?:(?:[-*+]|\d{1,9}[.)])\s+)?(?:\*\*|__|\*|_)(.+?)(?:\*\*|__|\*|_)\s*:?\s*$/;
|
|
135
|
+
const AGENT = "(?:claude|copilot|codex|chatgpt|gpt|cursor|gemini|opus|sonnet|haiku|openai|anthropic|an? ai\\b|llm)";
|
|
136
|
+
// Authorship of the description itself starts the line ("Generated with Claude Code"); a bullet about a
|
|
137
|
+
// product feature that generates text with a model ("Text generated with OpenAI is now cached") does not.
|
|
138
|
+
const AUTHORED = new RegExp(`^\\s*(?:(?:[-*+>]|\\d{1,9}[.)])\\s+)*[^\\w\\s]*\\s*(?:(?:this|the)\\s+(?:pull request|pr|description|change|changes|code|patch|commit)\\s+(?:was|is|has been)\\s+)?(?:\\*\\*|__|\\*|_)?(?:generated|written|drafted|authored|produced)\\s+(?:entirely\\s+|mostly\\s+|partly\\s+)?(?:with|by)\\s+(?:an?\\s+)?\\[?${AGENT}`, "i");
|
|
139
|
+
// Provenance is a note when it starts a clause ("Reviewed with a cross-provider review.", "Review: Opus-only
|
|
140
|
+
// review"), not when it sits inside a product sentence ("Adds same-provider review routing ..."). Where the
|
|
141
|
+
// text is product wording (a bullet under an allowed section, a `## Summary` or a lead paragraph) the note
|
|
142
|
+
// must also END the clause, apart from issue references and a result word ("- Cross-provider review
|
|
143
|
+
// pending (#5)"), so "- Cross-provider review is now selectable (#5)" passes. Only a stand-alone line
|
|
144
|
+
// outside those uses the loose tail below.
|
|
145
|
+
const PROVIDER = "(?:opus|anthropic|gpt|claude|openai)-only";
|
|
146
|
+
const QUALIFIER = String.raw`(?:(?:an?|the|this|our|quick|brief|short|final|full|independent|second|extra|additional|another|fresh|light)\s+)*`;
|
|
147
|
+
const NOTE_START = CLAIM_START.replace("(?:^|", "(?:^\\s*|");
|
|
148
|
+
const PROVENANCE_TOPIC = new RegExp(NOTE_START + "(?:" + [
|
|
149
|
+
String.raw`${QUALIFIER}(?:same|cross)-provider\)?\s+review\b`,
|
|
150
|
+
String.raw`review(?:ed|s)?\s+(?:(?:was|is|with|by|using|via|through)\s+)*(?:an?\s+)?(?:(?:same|cross)-provider|${PROVIDER})(?:\s+review)?\b`,
|
|
151
|
+
String.raw`${QUALIFIER}${PROVIDER}\s+(?:\([^)]*\)\s+)?review\b`,
|
|
152
|
+
].join("|") + ")", "i");
|
|
153
|
+
const NOTE_RESULT = String.raw`\s*(?:(?:is|was|has\s+been)\s+)?(?:pending|passed|passing|done|complete|completed|approved|clean|green|ok|skipped|missing|unavailable|only|requested|required)\b`;
|
|
154
|
+
// In product wording the note must end the clause: nothing but a result word, punctuation, closing emphasis
|
|
155
|
+
// or `<br>` after it. Elsewhere any punctuation that continues the note ("Cross-provider review: no
|
|
156
|
+
// findings") is enough.
|
|
157
|
+
// Product wording can say a review "is required", "is requested" or "only" applies ("Cross-provider review is
|
|
158
|
+
// required (#4)"); inside a bullet those words describe the feature, so the strict tail leaves them out.
|
|
159
|
+
const NOTE_RESULT_STRICT = String.raw`\s*(?:(?:is|was|has\s+been)\s+)?(?:pending|passed|passing|done|complete|completed|approved|clean|green|ok|skipped|missing|unavailable)\b`;
|
|
160
|
+
const NOTE_TAIL_STRICT = new RegExp(`^(?:${NOTE_RESULT_STRICT})?(?:[\\s:;,.!*_]|<br\\s*\\/?>)*$`, "i");
|
|
161
|
+
// An outright result or provenance claim ("Reviewed with Anthropic models only") keeps every result word:
|
|
162
|
+
// only the topic path is narrowed for product wording.
|
|
163
|
+
const NOTE_TAIL_CLAIM = new RegExp(`^(?:${NOTE_RESULT})?(?:[\\s:;,.!*_]|<br\\s*\\/?>)*$`, "i");
|
|
164
|
+
const NOTE_TAIL_LOOSE = new RegExp(`^(?:${NOTE_RESULT}|\\s*[:;,.!\u2014\u2013-]\\s*\\S|\\s*\\((?!#)|[\\s:;,.!]*$)`, "i");
|
|
165
|
+
// A model or agent name may run to a few words ("Claude Code", "GPT-5.5", "Opus 5.5").
|
|
166
|
+
const AGENT_NAME = String.raw`${AGENT}\b(?:[\s-]+(?:code|opus|sonnet|haiku|pro|max|mini|[\w.]*\d[\w.]*)\b)*`;
|
|
167
|
+
// "Reviewed with Anthropic models only (...)": a clause that opens by saying who or what reviewed it. In
|
|
168
|
+
// product wording only the past tense is a claim: "- Review with two models (#5)" names a feature.
|
|
169
|
+
const provenanceResult = verb => new RegExp(NOTE_START + "(?:" + [
|
|
170
|
+
String.raw`${verb}\s+(?:with|by|using|via)\s+(?:(?:an?|the|two|three|both|only)\s+)?(?:[\w.-]+\s+){0,2}?(?:models?|agents?|providers?)\b`,
|
|
171
|
+
String.raw`${verb}\s+(?:with|by|using|via)\s+(?:an?\s+)?${AGENT_NAME}`,
|
|
172
|
+
String.raw`(?:the\s+)?review workflow\s+(?:has\s+|had\s+|also\s+)?(?:(?:passed|failed)${END}`
|
|
173
|
+
+ String.raw`|passed\s+with\s+(?:no\s+\w+|\w+\s+findings?)|passed\s+(?:with|locally|again|twice|cleanly)\b|returned\s+(?:findings|no\s+\w+|nothing|clean|\d+)\b`
|
|
174
|
+
+ String.raw`|ran\s+(?:twice|once|again|clean|cleanly|green|locally|successfully|\d+)\b`
|
|
175
|
+
+ String.raw`|found\s+(?:nothing|no\s+\w+|\d+|issues|findings|blockers)\b)`,
|
|
176
|
+
].join("|") + ")", "i");
|
|
177
|
+
const PROVENANCE_RESULT = provenanceResult(String.raw`review(?:ed)?`);
|
|
178
|
+
const PROVENANCE_RESULT_STRICT = provenanceResult("reviewed");
|
|
179
|
+
const CO_AUTHORED = /^\s*(?:(?:[-*+>]|\d{1,9}[.)])\s+)*(?:\*\*|__|\*|_)?\s*co-authored-by:/i;
|
|
180
|
+
const withoutIssues = text => text.replace(/(?:\s*\((?:part of )?#\d+\))+\s*$/, "");
|
|
181
|
+
// A product bullet that ends in an issue reference names a change ("- Cross-provider review (#12)"); it is
|
|
182
|
+
// only a note when a result word precedes the reference ("- Cross-provider review pending (#3)").
|
|
183
|
+
const NOTE_TAIL_STRICT_RESULT = new RegExp(`^(?:${NOTE_RESULT_STRICT})(?:[\\s:;,.!*_]|<br\\s*\\/?>)*$`, "i");
|
|
184
|
+
const strictTail = raw => {
|
|
185
|
+
const tail = withoutIssues(raw);
|
|
186
|
+
return (tail === raw ? NOTE_TAIL_STRICT : NOTE_TAIL_STRICT_RESULT).test(tail);
|
|
187
|
+
};
|
|
188
|
+
const provenance = (line, strict) => {
|
|
189
|
+
if (CO_AUTHORED.test(line)) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
const result = (strict ? PROVENANCE_RESULT_STRICT : PROVENANCE_RESULT).exec(line);
|
|
193
|
+
if (result && (!strict || NOTE_TAIL_CLAIM.test(withoutIssues(line.slice(result.index + result[0].length))))) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
const topic = PROVENANCE_TOPIC.exec(line);
|
|
197
|
+
if (!topic) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
const raw = line.slice(topic.index + topic[0].length);
|
|
201
|
+
return strict ? strictTail(raw) : NOTE_TAIL_LOOSE.test(withoutIssues(raw));
|
|
202
|
+
};
|
|
203
|
+
const TRANSCRIPT = /<summary>\s*original prompt\s*<\/summary>|^\s*(?:#{1,6}\s+|\*\*|__)?original prompt(?:\*\*|__)?\s*:?\s*$|\blet copilot coding agent\b|\bcopilot coding agent\s+(?:tips|settings|set things up)|\bfirewall rules blocked me\b/i;
|
|
204
|
+
const INLINE_LINK = /\]\(\s*<?([^)\s>]+)/g;
|
|
205
|
+
const REFERENCE_LINK = /^ {0,3}\[(?!\^)[^\]]+\]:\s*<?([^\s>]+)/;
|
|
206
|
+
const HTML_LINK = /\b(?:href|src)\s*=\s*["']([^"']+)["']/gi;
|
|
207
|
+
const ABSOLUTE = /^(?:https?:\/\/|#|mailto:)/i;
|
|
208
|
+
const ATX_HEADING = /^ {0,3}(#{1,6})(?:[ \t]+(.*?))?(?:[ \t]+#+)?[ \t]*$/;
|
|
209
|
+
const SETEXT_UNDERLINE = /^ {0,3}(=+|-+)[ \t]*$/;
|
|
210
|
+
const THEMATIC_BREAK = /^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/;
|
|
211
|
+
const LIST_ITEM = /^\s*(?:[-*+]|\d{1,9}[.)])[ \t]+\S/;
|
|
212
|
+
// A bullet that only says there is nothing (`- None.`, `- **N/A**`) is a filler, not a change.
|
|
213
|
+
const FILLER = /^(?:none|n\/a|nothing)$/i;
|
|
214
|
+
const isFiller = text => FILLER.test(text
|
|
215
|
+
.replace(/^\s*(?:[-*+]|\d{1,9}[.)])[ \t]+/, "")
|
|
216
|
+
.replace(/<\/?(?:b|i|em|strong|u|s|del|ins)\b[^>]*>/gi, "")
|
|
217
|
+
.replace(/[*_~\s]+/g, " ")
|
|
218
|
+
.replace(/^[\s.,;:!?]+|[\s.,;:!?]+$/g, ""));
|
|
219
|
+
// HTML that renders as a heading, or as a bold-only line, on the release page.
|
|
220
|
+
const HTML_HEADING = /^\s*<h([1-6])\b[^>]*>(.*?)(?:<\/h\1>)?\s*$/i;
|
|
221
|
+
const HTML_BOLD_ONLY = /^\s*(?:(?:[-*+]|\d{1,9}[.)])\s+)?(?:<p[^>]*>\s*)?<(b|strong|i|em)>(.+?)<\/\1>\s*:?\s*(?:<\/p>)?\s*$/i;
|
|
222
|
+
// A <summary> may span lines: it is read from the whole text and reported at the line it opens on.
|
|
223
|
+
const HTML_SUMMARY = /<summary\b[^>]*>([\s\S]*?)<\/summary>/gi;
|
|
224
|
+
const ISSUE_TEXT = /^(?:[\w.-]+\/[\w.-]+)?#\d+$/;
|
|
225
|
+
const KEYWORD_TEXT = /^(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?|refs?|references)\b(?:[ \t]*:)?(?:[ \t]+(?:[\w.-]+\/[\w.-]+)?#\d+)?$/i;
|
|
226
|
+
|
|
227
|
+
const blank = (text, pattern, fill) => text.replace(pattern, match => match.replace(/[^\n]/g, fill));
|
|
228
|
+
const plain = html => html.replace(/<[^>]*>/g, "").trim();
|
|
229
|
+
// A closing keyword is still one when wrapped in emphasis or a link (`**Closes** #1`, `Closes [#1](url)`),
|
|
230
|
+
// so the keyword rules read the text as it renders: emphasis dropped, a link reduced to its issue
|
|
231
|
+
// reference or its URL, or, when the link text is itself a keyword, to that text followed by its URL (`[Closes](issue-url)`).
|
|
232
|
+
// A keyword as link text is a keyword only where it starts a clause ("[Closes](url)", "Done. [Fixes](url)"), not
|
|
233
|
+
// inside a sentence ("Adds a [Fixes](url) page").
|
|
234
|
+
const CLAUSE_START = /(?:^|[.;:!(])\s*(?:(?:[-*+>]|\d{1,9}[.)])\s+)*$/;
|
|
235
|
+
const linkAs = (text, url, before) => {
|
|
236
|
+
const trimmed = text.trim();
|
|
237
|
+
return ISSUE_TEXT.test(trimmed) ? trimmed
|
|
238
|
+
: KEYWORD_TEXT.test(trimmed) && CLAUSE_START.test(before) ? `${trimmed} ${url}` : url;
|
|
239
|
+
};
|
|
240
|
+
const rendered = line => line
|
|
241
|
+
.replace(/\*+|~~|(?<!\w)_+|_+(?!\w)/g, "")
|
|
242
|
+
.replace(/<(https?:\/\/[^>\s]+)>/gi, "$1")
|
|
243
|
+
.replace(/<a\b[^>]*\bhref\s*=\s*["']([^"']+)["'][^>]*>(.*?)<\/a>/gi, (whole, url, text, offset, all) => linkAs(plain(text), url, all.slice(0, offset)))
|
|
244
|
+
.replace(/<\/?[a-z][^>]*>/gi, "")
|
|
245
|
+
.replace(/!?\[([^\]]*)\]\(\s*<?([^)\s>]+)>?(?:\s[^)]*)?\)/g, (whole, text, url, offset, all) => linkAs(text, url, all.slice(0, offset)))
|
|
246
|
+
.replace(/\[([^\]]*)\]\[[^\]]*\]/g, "$1")
|
|
247
|
+
.replace(/[\[\]]/g, "");
|
|
248
|
+
const normalize = name => name.replace(/^[*_\s]+|[*_\s:]+$/g, "").replace(/\s+/g, " ").toLowerCase();
|
|
249
|
+
const quote = line => {
|
|
250
|
+
const trimmed = line.trim();
|
|
251
|
+
return trimmed.length > 120 ? `${trimmed.slice(0, 117)}...` : trimmed;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
function headingAt(visible, index) {
|
|
255
|
+
const atx = ATX_HEADING.exec(visible[index]);
|
|
256
|
+
if (atx) {
|
|
257
|
+
return { level: atx[1].length, name: (atx[2] || "").trim(), setext: false };
|
|
258
|
+
}
|
|
259
|
+
const html = HTML_HEADING.exec(visible[index]);
|
|
260
|
+
if (html) {
|
|
261
|
+
return { level: Number(html[1]), name: plain(html[2]), setext: false, html: true };
|
|
262
|
+
}
|
|
263
|
+
const next = visible[index + 1];
|
|
264
|
+
const underline = next === undefined ? null : SETEXT_UNDERLINE.exec(next);
|
|
265
|
+
if (!underline || !visible[index].trim() || THEMATIC_BREAK.test(visible[index]) || ATX_HEADING.test(visible[index])) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
// Only a paragraph turns into a heading; under a list item or a quote the underline is a rule.
|
|
269
|
+
let start = index;
|
|
270
|
+
while (start > 0 && visible[start - 1].trim() && !ATX_HEADING.test(visible[start - 1])) {
|
|
271
|
+
start--;
|
|
272
|
+
}
|
|
273
|
+
if (!LIST_ITEM.test(visible[start]) && !/^\s*>/.test(visible[start]) && !/^\s*\|/.test(visible[start])) {
|
|
274
|
+
return { level: underline[1][0] === "=" ? 1 : 2, name: visible[index].trim(), setext: true };
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function headingFix(heading) {
|
|
280
|
+
const name = normalize(heading.name);
|
|
281
|
+
const setext = heading.setext
|
|
282
|
+
? " A line directly above `---` or `===` renders as a heading; put a blank line before a `---` rule."
|
|
283
|
+
: "";
|
|
284
|
+
if (isReviewerHeading(name)) {
|
|
285
|
+
return `${PR_COMMENT}${setext}`;
|
|
286
|
+
}
|
|
287
|
+
if (NARRATIVE_HEADINGS.includes(name)) {
|
|
288
|
+
return `Remove the heading: only an optional \`## Summary\` section or one lead paragraph of 1-3 sentences, without a heading, may precede the sections; everything else is a bullet under ${ALLOWED_LIST}.${setext}`;
|
|
289
|
+
}
|
|
290
|
+
if (CHANGE_HEADINGS.includes(name)) {
|
|
291
|
+
return `Write the changes as bullets under ${ALLOWED_LIST}.${setext}`;
|
|
292
|
+
}
|
|
293
|
+
return `Only ${ALLOWED_LIST} are allowed as sections. Breaking changes and upgrade steps are bullets in ## Changed or ## Removed; group bullets with a ### sub-heading inside an allowed section if needed.${setext}`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// The text release-action scans for `(#n)`: fenced code and then inline code removed outright (not blanked,
|
|
297
|
+
// so what surrounds a removed span joins up), with the original offset of every character kept.
|
|
298
|
+
function closingReferences(text, prose) {
|
|
299
|
+
let scanned = { text, origin: Array.from({ length: text.length }, (_, offset) => offset) };
|
|
300
|
+
for (const pattern of [FENCED_CODE, INLINE_CODE]) {
|
|
301
|
+
let out = "";
|
|
302
|
+
const origin = [];
|
|
303
|
+
let last = 0;
|
|
304
|
+
const keep = end => {
|
|
305
|
+
out += scanned.text.slice(last, end);
|
|
306
|
+
for (let offset = last; offset < end; offset++) {
|
|
307
|
+
origin.push(scanned.origin[offset]);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
for (const match of scanned.text.matchAll(pattern)) {
|
|
311
|
+
keep(match.index);
|
|
312
|
+
last = match.index + match[0].length;
|
|
313
|
+
}
|
|
314
|
+
keep(scanned.text.length);
|
|
315
|
+
scanned = { text: out, origin };
|
|
316
|
+
}
|
|
317
|
+
const starts = [0];
|
|
318
|
+
for (let offset = text.indexOf("\n"); offset >= 0; offset = text.indexOf("\n", offset + 1)) {
|
|
319
|
+
starts.push(offset + 1);
|
|
320
|
+
}
|
|
321
|
+
const position = offset => {
|
|
322
|
+
let line = starts.length - 1;
|
|
323
|
+
while (starts[line] > offset) {
|
|
324
|
+
line--;
|
|
325
|
+
}
|
|
326
|
+
return { line, column: offset - starts[line] };
|
|
327
|
+
};
|
|
328
|
+
const found = [];
|
|
329
|
+
for (const match of scanned.text.matchAll(CLOSES_ISSUE)) {
|
|
330
|
+
const first = position(scanned.origin[match.index]);
|
|
331
|
+
const last = position(scanned.origin[match.index + match[0].length - 1]);
|
|
332
|
+
found.push({ number: match[1], line: first.line, endLine: last.line, endColumn: last.column + 1,
|
|
333
|
+
commented: prose[first.line][first.column] === " " });
|
|
334
|
+
}
|
|
335
|
+
return found;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function check({ body, repository, defaultBranch }) {
|
|
339
|
+
const lines = body.replace(/\r\n?/g, "\n").split("\n");
|
|
340
|
+
// Code keeps its extent (so a section holding only an example is not empty) but loses its text;
|
|
341
|
+
// comments vanish entirely, as they do on the release page.
|
|
342
|
+
const text = lines.join("\n");
|
|
343
|
+
let visible = blank(text, FENCED_CODE, "x");
|
|
344
|
+
visible = blank(visible, INLINE_CODE, "x");
|
|
345
|
+
visible = blank(visible, HTML_COMMENT, " ").split("\n");
|
|
346
|
+
// The same without fenced code, which does not belong to the bullet text around it.
|
|
347
|
+
const uncommented = blank(blank(text, FENCED_CODE, " "), INLINE_CODE, "x");
|
|
348
|
+
const prose = blank(uncommented, HTML_COMMENT, " ").split("\n");
|
|
349
|
+
// What release-action reads when it closes issues: it removes fenced and inline code, in that order,
|
|
350
|
+
// and nothing else, so a `(#n)` hidden in an HTML comment still closes its issue. Each match is
|
|
351
|
+
// mapped back to where it sits in the description.
|
|
352
|
+
const closes = closingReferences(text, prose);
|
|
353
|
+
|
|
354
|
+
const violations = [];
|
|
355
|
+
const report = (rule, index, fix) => violations.push({ rule, line: index === null ? null : index + 1,
|
|
356
|
+
text: index === null ? null : quote(lines[index]), fix });
|
|
357
|
+
|
|
358
|
+
// The text of every <summary>, at the line it opens on.
|
|
359
|
+
const summaryAt = new Map();
|
|
360
|
+
const flat = visible.join("\n");
|
|
361
|
+
for (const match of flat.matchAll(HTML_SUMMARY)) {
|
|
362
|
+
summaryAt.set(flat.slice(0, match.index).split("\n").length - 1, plain(match[1]));
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Each bullet runs to the line before the next bullet, heading or unindented paragraph.
|
|
366
|
+
const bulletEnd = new Array(prose.length).fill(-1);
|
|
367
|
+
for (let start = 0; start < prose.length; start++) {
|
|
368
|
+
if (!LIST_ITEM.test(prose[start])) {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
let end = start;
|
|
372
|
+
for (let next = start + 1; next < prose.length; next++) {
|
|
373
|
+
const candidate = prose[next];
|
|
374
|
+
if (!candidate.trim()) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (LIST_ITEM.test(candidate) || ATX_HEADING.test(candidate) || THEMATIC_BREAK.test(candidate)
|
|
378
|
+
|| (!/^(?: {2,}|\t)/.test(candidate) && !prose[next - 1].trim())) {
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
end = next;
|
|
382
|
+
}
|
|
383
|
+
for (let line = start; line <= end; line++) {
|
|
384
|
+
bulletEnd[line] = end;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// GitHub hides everything after a `<!--` that is never closed.
|
|
389
|
+
const unclosed = visible.findIndex(line => line.includes("<!--"));
|
|
390
|
+
if (unclosed >= 0) {
|
|
391
|
+
report("Unclosed HTML comment", unclosed, "Close the comment with `-->`, or delete it: GitHub hides everything after an unclosed `<!--`, so the release page would lose the rest of the description.");
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
let section = null;
|
|
395
|
+
let preamble = true;
|
|
396
|
+
let paragraphs = 0;
|
|
397
|
+
let inParagraph = false;
|
|
398
|
+
let bulletsOutside = false;
|
|
399
|
+
let lastOrder = -1;
|
|
400
|
+
let summaries = 0;
|
|
401
|
+
const sections = [];
|
|
402
|
+
const proseOnly = index => {
|
|
403
|
+
if (!section.flagged) {
|
|
404
|
+
section.flagged = true;
|
|
405
|
+
report("Summary is prose", index, `A \`## Summary\` is short prose; put each change in a bullet under ${ALLOWED_LIST}, or delete the summary.`);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
for (let index = 0; index < visible.length; index++) {
|
|
410
|
+
const line = visible[index];
|
|
411
|
+
const heading = headingAt(visible, index);
|
|
412
|
+
|
|
413
|
+
if (heading) {
|
|
414
|
+
inParagraph = false;
|
|
415
|
+
const name = normalize(heading.name);
|
|
416
|
+
const order = ALLOWED.findIndex(allowed => allowed.toLowerCase() === name);
|
|
417
|
+
const summary = name === "summary";
|
|
418
|
+
// Inside an open section a `###` named like an allowed section (`### Added`) is a sub-heading; at the
|
|
419
|
+
// top, before or between sections, it is a section written at the wrong level.
|
|
420
|
+
const subHeading = heading.level > 2 && section !== null;
|
|
421
|
+
if (heading.level <= 2 || (order >= 0 && !subHeading) || (summary && preamble)) {
|
|
422
|
+
const leadParagraph = preamble && paragraphs > 0;
|
|
423
|
+
preamble = false;
|
|
424
|
+
if (summary) {
|
|
425
|
+
if (heading.level !== 2 || heading.html) {
|
|
426
|
+
report("Section heading level", index, "Sections are level-2 Markdown headings: write `## Summary`.");
|
|
427
|
+
}
|
|
428
|
+
if (summaries > 0 || lastOrder >= 0) {
|
|
429
|
+
report("Section order", index, `\`## Summary\` is optional, appears once and comes first, before ${ALLOWED_LIST}; move it to the top or delete it.`);
|
|
430
|
+
} else if (leadParagraph) {
|
|
431
|
+
report("Summary and lead paragraph", index, "Use either a `## Summary` section or one lead paragraph without a heading, not both; merge them into one.");
|
|
432
|
+
}
|
|
433
|
+
summaries++;
|
|
434
|
+
section = { index, content: false, bullets: 0, prose: true, flagged: false };
|
|
435
|
+
sections.push(section);
|
|
436
|
+
} else if (order >= 0) {
|
|
437
|
+
if (heading.level !== 2 || heading.html) {
|
|
438
|
+
report("Section heading level", index, `Sections are level-2 Markdown headings: write \`## ${ALLOWED[order]}\`.`);
|
|
439
|
+
}
|
|
440
|
+
if (order <= lastOrder) {
|
|
441
|
+
report("Section order", index, `Each allowed section appears once, in the order ${ALLOWED_LIST}; merge the bullets into the earlier section.`);
|
|
442
|
+
}
|
|
443
|
+
lastOrder = Math.max(lastOrder, order);
|
|
444
|
+
section = { index, content: false, bullets: 0, prose: false, flagged: false };
|
|
445
|
+
sections.push(section);
|
|
446
|
+
} else {
|
|
447
|
+
report("Heading not allowed", index, headingFix(heading));
|
|
448
|
+
section = null;
|
|
449
|
+
}
|
|
450
|
+
} else if (isForbiddenHeading(name) || name === "summary") {
|
|
451
|
+
report("Heading not allowed", index, headingFix(heading));
|
|
452
|
+
} else if (section && section.prose) {
|
|
453
|
+
proseOnly(index);
|
|
454
|
+
} else if (preamble) {
|
|
455
|
+
report("Sub-heading outside a section", index, `A ### sub-heading only groups bullets inside one of ${ALLOWED_LIST}; move it under the section it belongs to.`);
|
|
456
|
+
}
|
|
457
|
+
// A heading is still a line of the description: what a heading says is published, and a `(#n)`
|
|
458
|
+
// in it closes the issue, so it gets the same content checks as any other line below.
|
|
459
|
+
} else if (!line.trim() || THEMATIC_BREAK.test(line)) {
|
|
460
|
+
inParagraph = false;
|
|
461
|
+
} else {
|
|
462
|
+
if (section) {
|
|
463
|
+
section.content = true;
|
|
464
|
+
if (LIST_ITEM.test(line)) {
|
|
465
|
+
if (section.prose) {
|
|
466
|
+
proseOnly(index);
|
|
467
|
+
} else if (!isFiller(prose.slice(index, bulletEnd[index] + 1).join(" "))) {
|
|
468
|
+
section.bullets++;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
} else if (preamble) {
|
|
472
|
+
if (LIST_ITEM.test(line)) {
|
|
473
|
+
if (!bulletsOutside) {
|
|
474
|
+
report("Bullets outside a section", index, `Put bullets under one of ${ALLOWED_LIST}; only a lead paragraph without a heading may precede the sections.`);
|
|
475
|
+
}
|
|
476
|
+
bulletsOutside = true;
|
|
477
|
+
} else if (!inParagraph) {
|
|
478
|
+
paragraphs++;
|
|
479
|
+
if (paragraphs === 2) {
|
|
480
|
+
report("More than one lead paragraph", index, `Keep at most one lead paragraph of 1-3 sentences that states the theme across the bullets; put each change in a bullet under ${ALLOWED_LIST}.`);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
inParagraph = true;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const shown = rendered(line);
|
|
488
|
+
for (const match of shown.matchAll(KEYWORD)) {
|
|
489
|
+
const reference = match[2];
|
|
490
|
+
const number = match[3];
|
|
491
|
+
const bracketed = shown[match.index - 1] === "(" && shown[match.index + match[0].length] === ")";
|
|
492
|
+
const fix = reference.startsWith("#") && bracketed
|
|
493
|
+
? `Replace \`(${match[0].trim()})\` with \`(#${number})\` if this change delivers it, or \`(part of #${number})\` if it must stay open.`
|
|
494
|
+
: reference.startsWith("#")
|
|
495
|
+
? `Replace \`${match[0].trim()}\` with \`(#${number})\` at the end of the bullet that delivers it, or \`(part of #${number})\` if it must stay open.`
|
|
496
|
+
: `Replace \`${match[0].trim()}\` with a plain \`${reference}\` reference; another repository's issues are never closed from here.`;
|
|
497
|
+
report("Closing or linking keyword", index, `${fix} Keywords such as Closes, Fixes and Refs are never used in release notes.`);
|
|
498
|
+
}
|
|
499
|
+
for (const match of shown.matchAll(KEYWORD_URL)) {
|
|
500
|
+
const sameRepository = match[3].toLowerCase() === repository.toLowerCase();
|
|
501
|
+
const fix = sameRepository
|
|
502
|
+
? `Replace \`${match[0].trim()}\` with \`(#${match[4]})\` at the end of the bullet that delivers it, or \`(part of #${match[4]})\` if it must stay open.`
|
|
503
|
+
: `Replace \`${match[0].trim()}\` with a plain \`${match[3]}#${match[4]}\` reference; another repository's issues are never closed from here.`;
|
|
504
|
+
report("Closing or linking keyword", index, `${fix} Keywords such as Closes, Fixes and Refs are never used in release notes, with an issue URL either.`);
|
|
505
|
+
}
|
|
506
|
+
const bold = BOLD_ONLY.exec(line);
|
|
507
|
+
const htmlBold = HTML_BOLD_ONLY.exec(line);
|
|
508
|
+
const summarized = summaryAt.get(index);
|
|
509
|
+
const boldName = bold ? bold[1] : htmlBold ? plain(htmlBold[2]) : summarized !== undefined ? summarized : null;
|
|
510
|
+
// A heading's text is read without its `###` or `<h3>`, so a label there is a label like any other.
|
|
511
|
+
const noted = heading ? line.replace(/^\s{0,3}#{1,6}[ \t]+|^\s*<h[1-6]\b[^>]*>/i, "") : line;
|
|
512
|
+
const labelled = RESULT_LABEL.exec(noted);
|
|
513
|
+
const underAllowedSection = Boolean(labelled && labelled.groups.bullet && section && !section.prose);
|
|
514
|
+
// Inside a bullet under an allowed section (or a continuation line of it) wording is product wording
|
|
515
|
+
// unless it reads as a result.
|
|
516
|
+
const inBullet = bulletEnd[index] >= 0 && Boolean(section) && !section.prose;
|
|
517
|
+
// Product wording: a bullet, a `## Summary` or the lead paragraph. Only a stand-alone line outside them
|
|
518
|
+
// is checked loosely for provenance and "Reviewed by".
|
|
519
|
+
const productText = inBullet || (section ? section.prose : preamble);
|
|
520
|
+
const processNote = PROCESS_NOTES.find(note => note.pattern.test(noted));
|
|
521
|
+
if (boldName !== null && isForbiddenHeading(normalize(boldName))) {
|
|
522
|
+
// A bold line or a <summary> naming a forbidden heading is that heading, not a note.
|
|
523
|
+
report("Heading not allowed", index, headingFix({ name: boldName, setext: false }));
|
|
524
|
+
} else if (PROCESS_LABEL.test(noted) || (!productText && REVIEWED_BY.test(noted)) || AUTHORED.test(noted) || provenance(noted, productText) || RESULT_CLAIM.test(noted)
|
|
525
|
+
|| (labelled && (!underAllowedSection || RESULT_WORDING.test(labelled.groups.rest)))) {
|
|
526
|
+
report("Review, verification or provenance note", index, PR_COMMENT);
|
|
527
|
+
} else if (processNote && !(heading && isForbiddenHeading(normalize(heading.name)))) {
|
|
528
|
+
// A forbidden heading ("### Not verified") is already reported as the heading it is.
|
|
529
|
+
report(PROCESS_RULE[processNote.kind], index, PROCESS_FIX[processNote.kind]);
|
|
530
|
+
}
|
|
531
|
+
for (const match of prose[index].matchAll(GROUPED_ISSUES)) {
|
|
532
|
+
const numbers = [...match[0].matchAll(/\d+/g)].map(number => number[0]);
|
|
533
|
+
report("Issue reference position", index, `\`${match[0]}\` closes nothing: release-action only recognises a \`(#n)\` of its own. Write each delivered issue as its own \`(#n)\`: \`${numbers.map(number => `(#${number})`).join(" ")}\`.`);
|
|
534
|
+
}
|
|
535
|
+
for (const match of closes.filter(candidate => candidate.line === index)) {
|
|
536
|
+
if (match.commented) {
|
|
537
|
+
report("Issue reference position", index, `\`(#${match.number})\` sits inside an HTML comment: the release page does not show the comment, but release-action still closes #${match.number}. Delete it from the comment, or write \`(part of #${match.number})\` or \`see #${match.number}\` outside the comment if it must stay open; never put issue references in comments.`);
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
const end = bulletEnd[match.endLine];
|
|
541
|
+
const rest = prose[match.endLine].slice(match.endColumn);
|
|
542
|
+
const after = end < 0 ? null : [rest, ...prose.slice(match.endLine + 1, end + 1)].join("\n");
|
|
543
|
+
if (after !== null && !ONLY_ISSUES_AFTER.test(after)) {
|
|
544
|
+
const followed = [lines[match.endLine].slice(match.endColumn), ...lines.slice(match.endLine + 1, end + 1)]
|
|
545
|
+
.join(" ").replace(/\s+/g, " ").trim().replace(/`/g, "'");
|
|
546
|
+
const excerpt = followed.length > 60 ? `${followed.slice(0, 57).trimEnd()} ...` : followed;
|
|
547
|
+
report("Issue reference position", index, `\`(#${match.number})\` is followed by \`${excerpt}\`; move that text before \`(#${match.number})\` so the issue reference ends the bullet, or write \`(part of #${match.number})\` or \`see #${match.number}\` if it must stay open.`);
|
|
548
|
+
} else if (after === null) {
|
|
549
|
+
report("Issue reference position", index, `Release-action closes \`(#${match.number})\` wherever it appears; put \`(#${match.number})\` at the end of the bullet that delivers the issue, or write \`(part of #${match.number})\` or \`see #${match.number}\` if it must stay open.`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (TRANSCRIPT.test(line)) {
|
|
553
|
+
report("Agent transcript", index, "Remove the Copilot \"Original prompt\" / agent transcript; it is not part of the release notes.");
|
|
554
|
+
}
|
|
555
|
+
if (PLACEHOLDERS.some(placeholder => line.toLowerCase().includes(placeholder.toLowerCase()))) {
|
|
556
|
+
report("Template placeholder", index, "Replace the template placeholder with the actual change, or delete it and its section if there is nothing to say.");
|
|
557
|
+
}
|
|
558
|
+
const targets = [...line.matchAll(INLINE_LINK), ...line.matchAll(HTML_LINK)].map(match => match[1]);
|
|
559
|
+
const reference = REFERENCE_LINK.exec(line);
|
|
560
|
+
if (reference) {
|
|
561
|
+
targets.push(reference[1]);
|
|
562
|
+
}
|
|
563
|
+
for (const target of targets.filter(target => !ABSOLUTE.test(target))) {
|
|
564
|
+
const path = target.replace(/^\.?\//, "");
|
|
565
|
+
report("Relative link", index, `Use an absolute https:// link, for example https://github.com/${repository}/blob/${defaultBranch}/${path}; relative links 404 on the release page. #anchors and mailto: are fine.`);
|
|
566
|
+
}
|
|
567
|
+
if (heading && heading.setext) {
|
|
568
|
+
index++;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
for (const empty of sections.filter(candidate => !candidate.content)) {
|
|
573
|
+
report("Empty section", empty.index, "Delete sections that have nothing in them.");
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
for (const bulletless of sections.filter(candidate => candidate.content && !candidate.prose && candidate.bullets === 0)) {
|
|
577
|
+
report("Section without bullets", bulletless.index, "Every section lists its changes as bullets: turn the text into bullets, or delete the section (a summary belongs in `## Summary` or one lead paragraph).");
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (!sections.some(candidate => candidate.bullets > 0)) {
|
|
581
|
+
report("No release notes", null, `A release-bound pull request needs at least one bullet under ${ALLOWED_LIST}, describing what a consumer compiles against, runs or observes.`);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
return violations;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const escapeData = value => value.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
588
|
+
const escapeProperty = value => escapeData(value).replace(/:/g, "%3A").replace(/,/g, "%2C");
|
|
589
|
+
const summary = markdown => {
|
|
590
|
+
if (process.env.GITHUB_STEP_SUMMARY) {
|
|
591
|
+
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, `${markdown}\n`);
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
const RERUN = "Only a pull request into the default branch is checked; the check re-runs when the description or a label changes.";
|
|
595
|
+
const skip = reason => {
|
|
596
|
+
console.log(`::notice title=Release notes not checked::${escapeData(`${reason} ${RERUN}`)}`);
|
|
597
|
+
summary(`### Release notes\n\nNot checked: ${reason} ${RERUN}`);
|
|
598
|
+
process.exit(0);
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
// The pull request as it is now (see "Read the pull request as it is now"); the event payload when that read
|
|
602
|
+
// failed or did not run.
|
|
603
|
+
let live = null;
|
|
604
|
+
try {
|
|
605
|
+
const parsed = process.env.PR_JSON ? JSON.parse(fs.readFileSync(process.env.PR_JSON, "utf8")) : null;
|
|
606
|
+
live = parsed && typeof parsed === "object" && Number.isInteger(parsed.number) ? parsed : null;
|
|
607
|
+
} catch {
|
|
608
|
+
live = null;
|
|
609
|
+
}
|
|
610
|
+
let labels = [];
|
|
611
|
+
try {
|
|
612
|
+
const parsed = live ? (live.labels || []).map(label => label && label.name) : JSON.parse(process.env.PR_LABELS || "[]");
|
|
613
|
+
labels = Array.isArray(parsed) ? parsed.filter(label => typeof label === "string") : [];
|
|
614
|
+
} catch {
|
|
615
|
+
labels = [];
|
|
616
|
+
}
|
|
617
|
+
const body = live ? (typeof live.body === "string" ? live.body : "") : (process.env.PR_BODY || "");
|
|
618
|
+
const author = live ? (live.user && live.user.login) || "" : (process.env.PR_AUTHOR || "");
|
|
619
|
+
const base = live ? (live.base && live.base.ref) || "" : (process.env.PR_BASE || "");
|
|
620
|
+
const defaultBranch = process.env.DEFAULT_BRANCH || "";
|
|
621
|
+
|
|
622
|
+
if (!base) {
|
|
623
|
+
skip("this run was not triggered by a pull request.");
|
|
624
|
+
}
|
|
625
|
+
if (author === "dependabot[bot]") {
|
|
626
|
+
skip("Dependabot pull requests carry Dependabot's generated description.");
|
|
627
|
+
}
|
|
628
|
+
if (base !== defaultBranch) {
|
|
629
|
+
skip(`the pull request targets ${base}, not the default branch ${defaultBranch}, so merging it releases nothing.`);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// A pull request carrying any of major, minor or patch is release-bound, also next to a second intent label
|
|
633
|
+
// (verify-release-intent rejects that combination on its own). Every other pull request may still become
|
|
634
|
+
// release-bound, so its violations are reported as warnings.
|
|
635
|
+
const releaseLabels = [...new Set(labels.filter(label => ["major", "minor", "patch"].includes(label)))];
|
|
636
|
+
const noRelease = labels.includes("no-release");
|
|
637
|
+
const releaseBound = releaseLabels.length > 0;
|
|
638
|
+
const violations = check({
|
|
639
|
+
body,
|
|
640
|
+
repository: process.env.GITHUB_REPOSITORY || "Cratis/<Repository>",
|
|
641
|
+
defaultBranch,
|
|
642
|
+
// A no-release pull request publishes nothing, so having no change list is not a mistake there.
|
|
643
|
+
}).filter(violation => releaseBound || !noRelease || violation.rule !== "No release notes");
|
|
644
|
+
|
|
645
|
+
const status = releaseBound ? ""
|
|
646
|
+
: noRelease ? "The pull request is labelled no-release, so this description is not published now. "
|
|
647
|
+
: "The pull request carries none of major, minor or patch yet. ";
|
|
648
|
+
if (violations.length === 0) {
|
|
649
|
+
console.log(`${status}The pull request description follows the release-note contract.`);
|
|
650
|
+
summary(`### Release notes\n\n${status}The pull request description follows the release-note contract and can be published as the release notes.`);
|
|
651
|
+
process.exit(0);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const level = releaseBound ? "error" : "warning";
|
|
655
|
+
const consequence = releaseBound ? VERBATIM
|
|
656
|
+
: `${noRelease ? "Labelled no-release, so this is a warning" : "Not labelled yet, so this is a warning"}: it fails once the pull request is labelled major, minor or patch. ${VERBATIM}`;
|
|
657
|
+
for (const violation of violations) {
|
|
658
|
+
const where = violation.line === null ? "The description" : `Line ${violation.line} \`${violation.text}\``;
|
|
659
|
+
console.log(`::${level} title=${escapeProperty(`Release notes: ${violation.rule}`)}::${escapeData(`${violation.rule}: ${where}. ${violation.fix} ${consequence}`)}`);
|
|
660
|
+
}
|
|
661
|
+
const rows = violations.map(violation =>
|
|
662
|
+
`| ${violation.line ?? ""} | ${violation.rule} | ${(violation.text ?? "").replace(/\|/g, "\\|").replace(/`/g, "'")} |`);
|
|
663
|
+
summary([
|
|
664
|
+
"### Release notes",
|
|
665
|
+
"",
|
|
666
|
+
`${violations.length} release-note ${releaseBound ? "violation(s)" : "warning(s)"}. ${consequence}`,
|
|
667
|
+
"",
|
|
668
|
+
"| Line | Rule | Text |",
|
|
669
|
+
"| --- | --- | --- |",
|
|
670
|
+
...rows,
|
|
671
|
+
].join("\n"));
|
|
672
|
+
process.exit(releaseBound ? 1 : 0);
|
|
673
|
+
|
|
674
|
+
}
|
|
675
|
+
if (process.argv[2] === "release-notes-drift") {
|
|
676
|
+
"use strict";
|
|
677
|
+
// cratis:program release-notes-drift
|
|
678
|
+
const fs = require("node:fs");
|
|
679
|
+
const { execFileSync } = require("node:child_process");
|
|
680
|
+
|
|
681
|
+
const ALLOWED = ["added", "changed", "fixed", "removed", "security", "deprecated"];
|
|
682
|
+
const REGISTRIES = [
|
|
683
|
+
{ name: "PyPI", mention: /\bpypi\b/i, publish: /pypi|twine|pypa\/gh-action-pypi-publish|uv publish|poetry publish/i },
|
|
684
|
+
{ name: "npm", mention: /\bnpm(?:js)?\b(?!\s+(?:install|ci|run|scripts?|dependenc))/i, publish: /npm publish|yarn npm publish|npm-publish|registry\.npmjs\.org|NPM_TOKEN|environment:\s*npm\b/i },
|
|
685
|
+
{ name: "NuGet", mention: /\bnuget(?:\.org)?\b/i, publish: /nuget push|dotnet nuget|NUGET_API_KEY|nuget\.org|environment:\s*nuget\b/i },
|
|
686
|
+
{ name: "Maven Central", mention: /\bmaven central\b|\bsonatype\b/i, publish: /maven|sonatype|central\.sonatype|publishToMavenCentral|gradle.*publish/i },
|
|
687
|
+
{ name: "Docker Hub", mention: /\bdocker hub\b|\bdockerhub\b/i, publish: /docker\/login-action|docker\.io|dockerhub|DOCKER_USERNAME|docker push/i },
|
|
688
|
+
{ name: "GHCR", mention: /\bghcr(?:\.io)?\b|\bgithub container registry\b/i, publish: /ghcr\.io/i },
|
|
689
|
+
];
|
|
690
|
+
const PUBLISH_CLAIM = /\b(?:publish(?:ed|es|ing)?|available|install(?:able)?|ships?|shipped|pushed|released|now on|from)\b/i;
|
|
691
|
+
const VERSION = /(?<![\w.-])v?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)(?![\w.-]*\w)/g;
|
|
692
|
+
|
|
693
|
+
const warnings = [];
|
|
694
|
+
const warn = (title, message) => warnings.push({ title, message });
|
|
695
|
+
const git = (...args) => execFileSync("git", args, { encoding: "utf8", maxBuffer: 256 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
696
|
+
const tryGit = (...args) => {
|
|
697
|
+
try {
|
|
698
|
+
return git(...args);
|
|
699
|
+
} catch {
|
|
700
|
+
return null;
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
const escapeData = value => value.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
704
|
+
const escapeProperty = value => escapeData(value).replace(/:/g, "%3A").replace(/,/g, "%2C");
|
|
705
|
+
const quote = text => (text.length > 100 ? `${text.slice(0, 97)}...` : text).replace(/`/g, "'");
|
|
706
|
+
|
|
707
|
+
// The bullets under the allowed sections, each with its continuation lines joined; code fences dropped.
|
|
708
|
+
function bullets(body) {
|
|
709
|
+
const lines = body.replace(/\r\n?/g, "\n").replace(/^[ \t]*(`{3,}|~{3,})[\s\S]*?^[ \t]*\1[ \t]*$/gm, "").replace(/<!--[\s\S]*?-->/g, "").split("\n");
|
|
710
|
+
const found = [];
|
|
711
|
+
let section = null;
|
|
712
|
+
let current = null;
|
|
713
|
+
for (const line of lines) {
|
|
714
|
+
const heading = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/.exec(line);
|
|
715
|
+
if (heading) {
|
|
716
|
+
current = null;
|
|
717
|
+
if (heading[1].length <= 2) {
|
|
718
|
+
section = heading[2].replace(/[*_`]/g, "").trim().toLowerCase();
|
|
719
|
+
}
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
if (!ALLOWED.includes(section)) {
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
const item = /^(\s*)(?:[-*+]|\d{1,9}[.)])\s+(.*)$/.exec(line);
|
|
726
|
+
if (item) {
|
|
727
|
+
current = { text: item[2] };
|
|
728
|
+
found.push(current);
|
|
729
|
+
} else if (current && /^\s+\S/.test(line)) {
|
|
730
|
+
current.text += ` ${line.trim()}`;
|
|
731
|
+
} else if (!line.trim()) {
|
|
732
|
+
continue;
|
|
733
|
+
} else {
|
|
734
|
+
current = null;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
return found;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
async function readBody() {
|
|
741
|
+
const api = process.env.GITHUB_API_URL || "https://api.github.com";
|
|
742
|
+
if (process.env.GH_TOKEN && process.env.REPOSITORY && process.env.NUMBER) {
|
|
743
|
+
try {
|
|
744
|
+
const response = await fetch(`${api}/repos/${process.env.REPOSITORY}/pulls/${process.env.NUMBER}`, {
|
|
745
|
+
headers: { authorization: `Bearer ${process.env.GH_TOKEN}`, accept: "application/vnd.github+json" },
|
|
746
|
+
});
|
|
747
|
+
if (response.ok) {
|
|
748
|
+
const pull = await response.json();
|
|
749
|
+
return { body: typeof pull.body === "string" ? pull.body : "", base: (pull.base && pull.base.ref) || process.env.BASE || "" };
|
|
750
|
+
}
|
|
751
|
+
} catch {
|
|
752
|
+
// Falls back to the event payload below.
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return { body: process.env.PR_BODY || "", base: process.env.BASE || "" };
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
function compare({ body, base, before, action }) {
|
|
759
|
+
const upstream = `origin/${base}`;
|
|
760
|
+
const mergeBase = tryGit("merge-base", upstream, "HEAD");
|
|
761
|
+
if (!mergeBase) {
|
|
762
|
+
return { skipped: `could not find where this pull request branched from ${upstream}` };
|
|
763
|
+
}
|
|
764
|
+
const mb = mergeBase.trim();
|
|
765
|
+
const names = git("diff", "--name-only", "--no-renames", mb, "HEAD").split("\n").filter(Boolean);
|
|
766
|
+
const patch = tryGit("diff", "-U0", "--no-color", "--no-ext-diff", "--no-textconv", mb, "HEAD");
|
|
767
|
+
const added = [];
|
|
768
|
+
const removed = [];
|
|
769
|
+
for (const line of (patch || "").split("\n")) {
|
|
770
|
+
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
771
|
+
added.push(line);
|
|
772
|
+
} else if (line.startsWith("-") && !line.startsWith("---")) {
|
|
773
|
+
removed.push(line);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
const changedText = `${names.join("\n")}\n${added.join("\n")}\n${removed.join("\n")}`;
|
|
777
|
+
const addedText = added.join("\n");
|
|
778
|
+
const removedText = removed.join("\n");
|
|
779
|
+
|
|
780
|
+
// 1. A bullet naming code the diff no longer touches.
|
|
781
|
+
if (patch !== null) {
|
|
782
|
+
for (const bullet of bullets(body)) {
|
|
783
|
+
const spans = [...bullet.text.matchAll(/(`+)([^`\n]+?)\1/g)].map(match => match[2].trim())
|
|
784
|
+
.filter(span => /^[\w.@/-]{3,}$/.test(span) && !/^v?[\d.]+$/.test(span) && /[A-Za-z]{2}/.test(span));
|
|
785
|
+
if (spans.length > 0 && !spans.some(span => changedText.includes(span)
|
|
786
|
+
|| changedText.includes(span.replace(/^\.?\//, "")) || changedText.includes(span.split("/").pop()))) {
|
|
787
|
+
warn("Release notes drift: bullet not in the diff",
|
|
788
|
+
`The bullet \`${quote(bullet.text)}\` names ${spans.map(span => `\`${span}\``).join(", ")}, which this pull request's diff no longer touches; the change may already be on ${base} or was dropped in conflict resolution. Re-read the bullet against \`git diff origin/${base}...HEAD\`.`);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// 2. A version the diff only removes.
|
|
793
|
+
const seen = new Set();
|
|
794
|
+
for (const match of body.matchAll(VERSION)) {
|
|
795
|
+
const version = match[1];
|
|
796
|
+
const before = body.slice(Math.max(0, match.index - 12), match.index);
|
|
797
|
+
if (seen.has(version) || /\bfrom\s+$|\bwas\s+$/i.test(before)) {
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
seen.add(version);
|
|
801
|
+
if (removedText.includes(version) && !addedText.includes(version)) {
|
|
802
|
+
warn("Release notes drift: replaced version",
|
|
803
|
+
`The description names ${version}, which the diff only removes: it is the version this pull request replaces. Name the version it moves to.`);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// 3. A registry the publish workflows never push to.
|
|
809
|
+
const workflows = tryGit("grep", "-h", "-i", "-e", ".", "HEAD", "--", ".github/workflows") || "";
|
|
810
|
+
for (const bullet of bullets(body)) {
|
|
811
|
+
for (const registry of REGISTRIES) {
|
|
812
|
+
if (registry.mention.test(bullet.text) && PUBLISH_CLAIM.test(bullet.text) && !registry.publish.test(workflows)) {
|
|
813
|
+
warn("Release notes drift: publish claim",
|
|
814
|
+
`The bullet \`${quote(bullet.text)}\` names ${registry.name}, but no workflow in .github/workflows publishes there. State only where the release is actually published.`);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// 4. A merge from the base branch that changed what the pull request contains.
|
|
820
|
+
const parents = (tryGit("rev-list", "--parents", "-n", "1", "HEAD") || "").trim().split(/\s+/).slice(1);
|
|
821
|
+
if (action === "synchronize" && before && !/^0+$/.test(before) && parents.length === 2
|
|
822
|
+
&& tryGit("merge-base", "--is-ancestor", parents[1], upstream) !== null
|
|
823
|
+
&& tryGit("cat-file", "-e", `${before}^{commit}`) !== null) {
|
|
824
|
+
const oldBase = tryGit("merge-base", before, upstream);
|
|
825
|
+
if (oldBase) {
|
|
826
|
+
const was = new Set(git("diff", "--name-only", "--no-renames", oldBase.trim(), before).split("\n").filter(Boolean));
|
|
827
|
+
const now = new Set(names);
|
|
828
|
+
const dropped = [...was].filter(name => !now.has(name));
|
|
829
|
+
const gained = [...now].filter(name => !was.has(name));
|
|
830
|
+
const changed = dropped.length + gained.length;
|
|
831
|
+
if (dropped.length > 0 || changed >= Math.max(3, Math.ceil(was.size * 0.25))) {
|
|
832
|
+
const list = files => files.slice(0, 5).map(name => `\`${name}\``).join(", ") + (files.length > 5 ? ` and ${files.length - 5} more` : "");
|
|
833
|
+
warn("Release notes drift: merge from the base branch",
|
|
834
|
+
`The merge from ${base} changed what this pull request contains${dropped.length ? `: it no longer changes ${list(dropped)}` : ""}${gained.length ? `${dropped.length ? ", and" : ":"} it now changes ${list(gained)}` : ""}. Re-read the notes against \`git diff origin/${base}...HEAD\`.`);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
return { skipped: null };
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
(async () => {
|
|
842
|
+
let outcome;
|
|
843
|
+
try {
|
|
844
|
+
const { body, base } = await readBody();
|
|
845
|
+
outcome = compare({ body, base, before: process.env.BEFORE || "", action: process.env.ACTION || "" });
|
|
846
|
+
} catch (error) {
|
|
847
|
+
outcome = { skipped: `the comparison failed: ${error.message.split("\n")[0]}` };
|
|
848
|
+
}
|
|
849
|
+
const summary = [];
|
|
850
|
+
if (outcome.skipped) {
|
|
851
|
+
console.log(`::notice title=Release notes drift not checked::${escapeData(`Not compared with the diff: ${outcome.skipped}.`)}`);
|
|
852
|
+
summary.push(`Not compared with the diff: ${outcome.skipped}.`);
|
|
853
|
+
} else if (warnings.length === 0) {
|
|
854
|
+
console.log("The release notes match the diff as far as this job can tell.");
|
|
855
|
+
summary.push("The release notes match the diff as far as this job can tell.");
|
|
856
|
+
}
|
|
857
|
+
for (const warning of warnings) {
|
|
858
|
+
console.log(`::warning title=${escapeProperty(warning.title)}::${escapeData(warning.message)}`);
|
|
859
|
+
summary.push(`- **${warning.title.replace(/^Release notes drift: /, "")}**: ${warning.message}`);
|
|
860
|
+
}
|
|
861
|
+
if (process.env.GITHUB_STEP_SUMMARY) {
|
|
862
|
+
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, `### Release notes and the diff\n\n${summary.join("\n")}\n`);
|
|
863
|
+
}
|
|
864
|
+
process.exit(0);
|
|
865
|
+
})();
|
|
866
|
+
|
|
867
|
+
}
|