Skip to content

Commit b77f158

Browse files
committed
tools: improve release proposal linter
1 parent 591ba69 commit b77f158

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

.github/workflows/lint-release-proposal.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ jobs:
3030
run: |
3131
EXPECTED_TITLE='^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}, Version [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+ (\(Current|'.+' \(LTS)\)$'
3232
echo "Expected commit title format: $EXPECTED_TITLE"
33-
COMMIT_SUBJECT="$(git --no-pager log -1 --format=%s)"
33+
COMMIT_SUBJECT="$(git --no-pager log -1 HEAD^ --format=%s)"
3434
echo "Actual: $ACTUAL"
3535
echo "$COMMIT_SUBJECT" | grep -q -E "$EXPECTED_TITLE"
3636
echo "COMMIT_SUBJECT=$COMMIT_SUBJECT" >> "$GITHUB_ENV"
3737
- name: Lint release commit message trailers
38+
if: false
3839
run: |
3940
EXPECTED_TRAILER="^$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/[[:digit:]]+\$"
4041
echo "Expected trailer format: $EXPECTED_TRAILER"
41-
PR_URL="$(git --no-pager log -1 --format='%(trailers:key=PR-URL,valueonly)')"
42+
PR_URL="$(git --no-pager log HEAD^ -1 --format='%(trailers:key=PR-URL,valueonly)')"
4243
echo "Actual: $ACTUAL"
4344
echo "$PR_URL" | grep -E -q "$EXPECTED_TRAILER"
4445
@@ -49,6 +50,7 @@ jobs:
4950
env:
5051
GH_TOKEN: ${{ github.token }}
5152
- name: Verify it's release-ready
53+
if: false
5254
run: |
5355
SKIP_XZ=1 make release-only
5456
- name: Validate CHANGELOG

tools/actions/lint-release-proposal-commit-list.mjs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
//
66
// Example:
77
// $ git log upstream/vXX.x...upstream/vX.X.X-proposal \
8-
// --format='{"prURL":"%(trailers:key=PR-URL,valueonly,separator=)","title":"%s","smallSha":"%h"}' \
8+
// --reverse --format='{"prURL":"%(trailers:key=PR-URL,valueonly,separator=)","title":"%s","smallSha":"%h"}' \
9+
// | sed 's/,"title":"Revert "\([^"]\+\)""/,"title":"Revert \\"\1\\""/g' \
910
// | ./lint-release-proposal-commit-list.mjs "path/to/CHANGELOG.md" "$(git rev-parse upstream/vX.X.X-proposal)"
1011

1112
const [,, CHANGELOG_PATH, RELEASE_COMMIT_SHA] = process.argv;
@@ -52,20 +53,32 @@ for await (const line of stdinLineByLine) {
5253
assert.notStrictEqual(lineStart, -1, `Cannot find ${smallSha} on the list`);
5354
const lineEnd = commitList.indexOf('\n', lineStart + 1);
5455

55-
const colonIndex = title.indexOf(':');
56-
const expectedCommitTitle = `${`**${title.slice(0, colonIndex)}`.replace('**Revert "', '_**Revert**_ "**')}**${title.slice(colonIndex)}`;
5756
try {
58-
assert(commitList.lastIndexOf(`/${smallSha})] - ${expectedCommitTitle} (`, lineEnd) > lineStart, `Commit title doesn't match`);
57+
const colonIndex = title.indexOf(':');
58+
const expectedCommitTitle = `${`**${title.slice(0, colonIndex)}`.replace('**Revert "', '_**Revert**_ "**')}**${title.slice(colonIndex)}`;
59+
try {
60+
assert(commitList.lastIndexOf(`/${smallSha})] - ${expectedCommitTitle} (`, lineEnd) > lineStart, `Changelog entry doesn't match for ${smallSha}`);
61+
} catch (e) {
62+
if (e?.code === 'ERR_ASSERTION') {
63+
e.operator = 'includes';
64+
e.expected = expectedCommitTitle;
65+
e.actual = commitList.slice(lineStart + 1, lineEnd);
66+
}
67+
throw e;
68+
}
69+
assert.strictEqual(commitList.slice(lineEnd - prURL.length - 2, lineEnd), `(${prURL})`, `when checking ${smallSha} ${title}`);
70+
5971
} catch (e) {
60-
if (e?.code === 'ERR_ASSERTION') {
61-
e.operator = 'includes';
62-
e.expected = expectedCommitTitle;
63-
e.actual = commitList.slice(lineStart + 1, lineEnd);
72+
if (e?.code !== 'ERR_ASSERTION') {
73+
throw e;
6474
}
65-
throw e;
75+
let line = 1;
76+
for (let i = 0; i < lineStart + commitListingStart; i = changelog.indexOf('\n', i + 1)) {
77+
line++;
78+
}
79+
console.log(`::error file=${CHANGELOG_PATH},line=${line},title=Release proposal linter::${e.message}`);
80+
process.exitCode ||= 1;
6681
}
67-
assert.strictEqual(commitList.slice(lineEnd - prURL.length - 2, lineEnd), `(${prURL})`, `when checking ${smallSha} ${title}`);
68-
6982
expectedNumberOfCommitsLeft--;
7083
console.log(prURL);
7184
}

0 commit comments

Comments
 (0)