Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions .github/workflows/lint-release-proposal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,23 @@ jobs:
- name: Validate CHANGELOG
id: releaser-info
run: |
HAS_ERROR=
EXPECTED_CHANGELOG_TITLE_INTRO="## $COMMIT_SUBJECT, @"
echo "Expected CHANGELOG section title: $EXPECTED_CHANGELOG_TITLE_INTRO"
CHANGELOG_PATH="doc/changelogs/CHANGELOG_V${MAJOR}.md"
CHANGELOG_TITLE="$(grep "$EXPECTED_CHANGELOG_TITLE_INTRO" "$CHANGELOG_PATH")"
CHANGELOG_TITLE="$(grep "$EXPECTED_CHANGELOG_TITLE_INTRO" "$CHANGELOG_PATH" || true)"
echo "Actual: $CHANGELOG_TITLE"
[ "${CHANGELOG_TITLE%%@*}@" = "$EXPECTED_CHANGELOG_TITLE_INTRO" ]
if [ "${CHANGELOG_TITLE%%@*}@" != "$EXPECTED_CHANGELOG_TITLE_INTRO" ]; then
echo "::error file=$CHANGELOG_PATH,title=Release proposal linter::Cannot find CHANGELOG section title starting with $EXPECTED_CHANGELOG_TITLE_INTRO"
HAS_ERROR=1
fi
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
--jq '.commits.[] | { smallSha: .sha[0:10] } + (.commit.message|capture("^(?<title>.+)\n\n(.*\n)*PR-URL: (?<prURL>.+)(\n|$)"))' \
"/repos/${GITHUB_REPOSITORY}/compare/v${MAJOR}.x...$GITHUB_SHA" --paginate \
| node tools/actions/lint-release-proposal-commit-list.mjs "$CHANGELOG_PATH" "$GITHUB_SHA" \
| while IFS= read -r PR_URL; do
| { while IFS= read -r PR_URL; do
DONT_LAND_LABEL="dont-land-on-v${MAJOR}.x" LTS_WATCH_LABEL="lts-watch-v${MAJOR}.x" gh pr view \
--json labels,url \
--jq '
Expand All @@ -114,8 +118,9 @@ jobs:
error("\(.url) has the \(env.LTS_WATCH_LABEL) label, please remove the label now that the PR is included in a release proposal")
end
' \
"$PR_URL" > /dev/null
done
"$PR_URL" > /dev/null || HAS_LABEL_ERROR=1
done; [ -z "$HAS_LABEL_ERROR" ]; } || HAS_ERROR=1
[ -z "$HAS_ERROR" ]
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.
env:
COMMIT_SUBJECT: ${{ steps.commit-message-parse.outputs.COMMIT_SUBJECT }}
Expand Down
44 changes: 30 additions & 14 deletions tools/actions/lint-release-proposal-commit-list.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,40 @@ commitList = commitList

let expectedNumberOfCommitsLeft = commitList.match(/\n\* \[/g)?.length ?? 0;

function reportError(message, lineStart = -1) {
let annotation = `file=${CHANGELOG_PATH}`;
if (lineStart !== -1) {
let line = 1;
for (let i = 0; i < lineStart + commitListingStart; i = changelog.indexOf('\n', i + 1)) {
line++;
}
annotation += `,line=${line}`;
}
console.error(`::error ${annotation},title=Release proposal linter::${message}`);
process.exitCode ||= 1;
}

for await (const line of stdinLineByLine) {
const { smallSha, title, prURL } = JSON.parse(line);

if (smallSha === RELEASE_COMMIT_SHA.slice(0, 10)) {
assert.strictEqual(
expectedNumberOfCommitsLeft, 0,
'Some commits are listed without being included in the proposal, or are listed more than once',
);
if (expectedNumberOfCommitsLeft !== 0) {
reportError('Some commits are listed without being included in the proposal, or are listed more than once');
// Avoid reporting the same discrepancy again after the loop.
expectedNumberOfCommitsLeft = 0;
}
continue;
}

// Used by the wrapping shell (in lint-release-proposal.yml) to check to labels
console.log(prURL);

const lineStart = commitList.indexOf(`\n* [[\`${smallSha}\`]`);
assert.notStrictEqual(lineStart, -1, `Cannot find ${smallSha} on the list`);
if (lineStart === -1) {
reportError(`Cannot find ${smallSha} on the list`);
continue;
}
expectedNumberOfCommitsLeft--;
const lineEnd = commitList.indexOf('\n', lineStart + 1);

try {
Expand All @@ -80,15 +101,10 @@ for await (const line of stdinLineByLine) {
if (e?.code !== 'ERR_ASSERTION') {
throw e;
}
let line = 1;
for (let i = 0; i < lineStart + commitListingStart; i = changelog.indexOf('\n', i + 1)) {
line++;
}
console.error(`::error file=${CHANGELOG_PATH},line=${line},title=Release proposal linter::${e.message}`);
reportError(e.message, lineStart);
console.error(e);
process.exitCode ||= 1;
}
expectedNumberOfCommitsLeft--;
console.log(prURL);
}
assert.strictEqual(expectedNumberOfCommitsLeft, 0, 'Release commit is not the last commit in the proposal');
if (expectedNumberOfCommitsLeft !== 0) {
reportError('Release commit is not the last commit in the proposal');
}
Loading