Skip to content

Commit

Permalink
chore(ci): verify the PR title as part of linting (denoland#18163)
Browse files Browse the repository at this point in the history
This verifies the PR title as part of the lint step.
  • Loading branch information
dsherret committed Mar 13, 2023
1 parent 44b0d4c commit b9d2ac3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@ const ci = {
run:
"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",
if: "matrix.job == 'lint'",
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ jobs:
- name: test_format.js
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
- 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
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
Expand Down
47 changes: 47 additions & 0 deletions tools/verify_pr_title.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit b9d2ac3

Please sign in to comment.