mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -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:
parent
44b0d4cb11
commit
b9d2ac32d5
3 changed files with 56 additions and 0 deletions
6
.github/workflows/ci.generate.ts
vendored
6
.github/workflows/ci.generate.ts
vendored
|
@ -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'",
|
||||||
|
|
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
@ -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
47
tools/verify_pr_title.js
Normal 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);
|
||||||
|
}
|
Loading…
Reference in a new issue