Skip to content

Commit bee4016

Browse files
authored
tools: validate version number in release proposal commit message lint
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #64070 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com>
1 parent d95cbc2 commit bee4016

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,24 @@ jobs:
2828
persist-credentials: false
2929
fetch-depth: 2
3030
- name: Lint release commit title format
31+
id: commit-message-parse
3132
run: |
32-
EXPECTED_TITLE='^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}, Version [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+ (\(Current|'.+' \(LTS)\)$'
33+
VERSION=$(${CXX:-cc} -E -dM src/node_version.h | awk '
34+
$2 == "NODE_MAJOR_VERSION" { maj = $3 }
35+
$2 == "NODE_MINOR_VERSION" { min = $3 }
36+
$2 == "NODE_PATCH_VERSION" { pat = $3 }
37+
$2 == "NODE_VERSION_LTS_CODENAME" { gsub(/^"|"$/, "'"'"'",$3); lts = $3 }
38+
END { if (maj) print maj "\\." min "\\." pat " " (lts != "'"''"'" ? lts " \\(LTS" : "\\(Current" ) "\\)" }
39+
')
40+
MAJOR=${VERSION%%\\.*}
41+
EXPECTED_TITLE='^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}, Version '"$VERSION"'$'
3342
echo "Expected commit title format: $EXPECTED_TITLE"
3443
COMMIT_SUBJECT="$(git --no-pager log -1 --format=%s)"
35-
echo "Actual: $ACTUAL"
44+
echo "Actual: $COMMIT_SUBJECT"
3645
echo "$COMMIT_SUBJECT" | grep -q -E "$EXPECTED_TITLE"
37-
echo "COMMIT_SUBJECT=$COMMIT_SUBJECT" >> "$GITHUB_ENV"
46+
47+
echo "COMMIT_SUBJECT=$COMMIT_SUBJECT" >> "$GITHUB_OUTPUT"
48+
echo "MAJOR=$MAJOR" >> "$GITHUB_OUTPUT"
3849
- name: Lint release commit message trailers
3950
run: |
4051
EXPECTED_TRAILER="^$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/[[:digit:]]+\$"
@@ -54,8 +65,6 @@ jobs:
5465
SKIP_XZ=1 make release-only
5566
- name: Lint release commit content
5667
run: |
57-
MAJOR="$(awk '/^#define NODE_MAJOR_VERSION / { print $3 }' src/node_version.h)"
58-
5968
echo "Checking for expected files in the release commit:"
6069
missing_expected=
6170
for expected in CHANGELOG.md src/node_version.h doc/changelogs/; do
@@ -81,7 +90,6 @@ jobs:
8190
run: |
8291
EXPECTED_CHANGELOG_TITLE_INTRO="## $COMMIT_SUBJECT, @"
8392
echo "Expected CHANGELOG section title: $EXPECTED_CHANGELOG_TITLE_INTRO"
84-
MAJOR="$(awk '/^#define NODE_MAJOR_VERSION / { print $3 }' src/node_version.h)"
8593
CHANGELOG_PATH="doc/changelogs/CHANGELOG_V${MAJOR}.md"
8694
CHANGELOG_TITLE="$(grep "$EXPECTED_CHANGELOG_TITLE_INTRO" "$CHANGELOG_PATH")"
8795
echo "Actual: $CHANGELOG_TITLE"
@@ -106,4 +114,6 @@ jobs:
106114
done
107115
shell: bash # See https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference, we want the pipefail option.
108116
env:
117+
COMMIT_SUBJECT: ${{ steps.commit-message-parse.outputs.COMMIT_SUBJECT }}
118+
MAJOR: ${{ steps.commit-message-parse.outputs.MAJOR }}
109119
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)