ci: validate the message of each new commit as part of the CI linting
This patch adds the gulp command of `validate-commit-messages` which will validate the range of commits messages present in the active branch. This check now runs on CI as part of the linting checks. Allowed commit message types and scopes are controlled via commit-message.json file and documented at https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines This solution is based on old Vojta's code that he wrote for angular/angular.js, that was later adjusted by @matsko in #13815. Ideally we should switch over to something like https://www.npmjs.com/package/commitplease as suggested in #9953 but that package currently doesn't support strict scope checking, which is one of the primarily goal of this PR. Note that this PR removes support for "chore" which was previously overused by everyone on the team. Closes #13815 Fixes #3337
This commit is contained in:

committed by
Alex Rickabaugh

parent
ba52b2e08c
commit
dff6ee3272
36
gulpfile.js
36
gulpfile.js
@ -126,7 +126,7 @@ gulp.task('public-api:update', ['build.sh'], (done) => {
|
||||
});
|
||||
|
||||
// Check the coding standards and programming errors
|
||||
gulp.task('lint', ['format:enforce', 'tools:build'], () => {
|
||||
gulp.task('lint', ['format:enforce', 'tools:build', 'validate-commit-messages'], () => {
|
||||
const tslint = require('gulp-tslint');
|
||||
// Built-in rules are at
|
||||
// https://palantir.github.io/tslint/rules/
|
||||
@ -155,6 +155,40 @@ gulp.task('lint', ['format:enforce', 'tools:build'], () => {
|
||||
.pipe(tslint.report({emitError: true}));
|
||||
});
|
||||
|
||||
gulp.task('validate-commit-messages', () => {
|
||||
const validateCommitMessage = require('./tools/validate-commit-message');
|
||||
const childProcess = require('child_process');
|
||||
|
||||
// We need to fetch origin explicitly because it might be stale.
|
||||
// I couldn't find a reliable way to do this without fetch.
|
||||
childProcess.exec(
|
||||
'git fetch origin master && git log --reverse --format=%s HEAD ^origin/master',
|
||||
(error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.log(stderr);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let someCommitsInvalid = false;
|
||||
let commitsByLine = stdout.trim().split(/\n/);
|
||||
|
||||
console.log(`Examining ${commitsByLine.length} commits between HEAD and master`);
|
||||
|
||||
if (commitsByLine.length == 0) {
|
||||
console.log('There are zero new commits between this HEAD and master');
|
||||
}
|
||||
|
||||
someCommitsInvalid = !commitsByLine.every(validateCommitMessage);
|
||||
|
||||
if (someCommitsInvalid) {
|
||||
console.log('Please fix the failing commit messages before continuing...');
|
||||
console.log(
|
||||
'Commit message guidelines: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines');
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('tools:build', (done) => { tsc('tools/', done); });
|
||||
|
||||
// Check for circular dependency in the source code
|
||||
|
Reference in New Issue
Block a user