1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

chore(ci): verify the PR title as part of linting (#18163)

This verifies the PR title as part of the lint step.
This commit is contained in:
David Sherret 2023-03-13 14:59:13 -04:00 committed by GitHub
parent 44b0d4cb11
commit b9d2ac32d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 0 deletions

View file

@ -473,6 +473,12 @@ const ci = {
run: run:
"deno run --unstable --allow-write --allow-read --allow-run ./tools/format.js --check", "deno run --unstable --allow-write --allow-read --allow-run ./tools/format.js --check",
}, },
{
name: "Lint PR title",
if: "matrix.job == 'lint' && github.event_name == 'pull_request'",
run:
"deno run ./tools/verify_pr_title.js '${{ github.event.pull_request.title }}'",
},
{ {
name: "lint.js", name: "lint.js",
if: "matrix.job == 'lint'", if: "matrix.job == 'lint'",

View file

@ -285,6 +285,9 @@ jobs:
- name: test_format.js - name: test_format.js
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (steps.exit_early.outputs.EXIT_EARLY != ''true'' && (matrix.job == ''lint''))' if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (steps.exit_early.outputs.EXIT_EARLY != ''true'' && (matrix.job == ''lint''))'
run: deno run --unstable --allow-write --allow-read --allow-run ./tools/format.js --check run: deno run --unstable --allow-write --allow-read --allow-run ./tools/format.js --check
- name: Lint PR title
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (steps.exit_early.outputs.EXIT_EARLY != ''true'' && (matrix.job == ''lint'' && github.event_name == ''pull_request''))'
run: 'deno run ./tools/verify_pr_title.js ''${{ github.event.pull_request.title }}'''
- name: lint.js - name: lint.js
if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (steps.exit_early.outputs.EXIT_EARLY != ''true'' && (matrix.job == ''lint''))' if: '!(github.event_name == ''pull_request'' && matrix.skip_pr) && (steps.exit_early.outputs.EXIT_EARLY != ''true'' && (matrix.job == ''lint''))'
run: deno run --unstable --allow-write --allow-read --allow-run ./tools/lint.js run: deno run --unstable --allow-write --allow-read --allow-run ./tools/lint.js

47
tools/verify_pr_title.js Normal file
View file

@ -0,0 +1,47 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
const prTitle = Deno.args[0];
if (prTitle == null) {
Deno.exit(0); // not a PR
}
console.log("PR title:", prTitle);
// This is a release PR, so it's valid.
if (/^[^\s]+\.[^\s]+\.[^\s]+$/.test(prTitle)) {
console.log("Valid.");
Deno.exit(0);
}
const validPrefixes = [
"chore",
"fix",
"feat",
"perf",
"ci",
"cleanup",
"docs",
"bench",
"build",
"refactor",
"test",
// allow Revert PRs because it allows us to remove the landed
// commit from the generated changelog
"Revert ",
];
if (validPrefixes.some((prefix) => prTitle.startsWith(prefix))) {
console.log("Valid.");
} else {
console.error(
"The PR title must start with one of the following prefixes:\n",
);
for (const prefix of validPrefixes) {
console.error(` - ${prefix}`);
}
console.error(
"\nPlease fix the PR title according to https://www.conventionalcommits.org " +
"then push an empty commit to reset the CI.",
);
Deno.exit(1);
}