Skip to content

Commit da1cbb3

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

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
with:
2828
persist-credentials: false
2929
- name: Lint release commit title format
30+
if: false
3031
run: |
3132
EXPECTED_TITLE='^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}, Version [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+ (\(Current|'.+' \(LTS)\)$'
3233
echo "Expected commit title format: $EXPECTED_TITLE"
@@ -35,6 +36,7 @@ jobs:
3536
echo "$COMMIT_SUBJECT" | grep -q -E "$EXPECTED_TITLE"
3637
echo "COMMIT_SUBJECT=$COMMIT_SUBJECT" >> "$GITHUB_ENV"
3738
- name: Lint release commit message trailers
39+
if: false
3840
run: |
3941
EXPECTED_TRAILER="^$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/[[:digit:]]+\$"
4042
echo "Expected trailer format: $EXPECTED_TRAILER"
@@ -49,6 +51,7 @@ jobs:
4951
env:
5052
GH_TOKEN: ${{ github.token }}
5153
- name: Verify it's release-ready
54+
if: false
5255
run: |
5356
SKIP_XZ=1 make release-only
5457
- 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)