build: stop execution on error in `validate-commit-message` (#28780)
Stop execution when an error happens in `validate-commit-message` gulp task and ensure the error message is printed at the bottom. Fixes #16829 PR Close #28780
This commit is contained in:
parent
af8d58cb51
commit
ababc5b4a4
|
@ -9,45 +9,51 @@
|
|||
|
||||
// tslint:disable:no-console
|
||||
module.exports = (gulp) => () => {
|
||||
const validateCommitMessage = require('../validate-commit-message');
|
||||
const shelljs = require('shelljs');
|
||||
try {
|
||||
const validateCommitMessage = require('../validate-commit-message');
|
||||
const shelljs = require('shelljs');
|
||||
|
||||
let baseBranch = 'master';
|
||||
const currentVersion = require('semver').parse(require('../../package.json').version);
|
||||
const baseHead =
|
||||
shelljs.exec(`git ls-remote --heads origin ${currentVersion.major}.${currentVersion.minor}.*`)
|
||||
.trim()
|
||||
.split('\n')
|
||||
.pop();
|
||||
if (baseHead) {
|
||||
const match = /refs\/heads\/(.+)/.exec(baseHead);
|
||||
baseBranch = match && match[1] || baseBranch;
|
||||
}
|
||||
shelljs.set('-e'); // Break on error.
|
||||
|
||||
// We need to fetch origin explicitly because it might be stale.
|
||||
// I couldn't find a reliable way to do this without fetch.
|
||||
result = shelljs.exec(
|
||||
`git fetch origin ${baseBranch} && git log --reverse --format=%s HEAD ^origin/${baseBranch}`);
|
||||
let baseBranch = 'master';
|
||||
const currentVersion = require('semver').parse(require('../../package.json').version);
|
||||
const baseHead =
|
||||
shelljs
|
||||
.exec(`git ls-remote --heads origin ${currentVersion.major}.${currentVersion.minor}.*`)
|
||||
.trim()
|
||||
.split('\n')
|
||||
.pop();
|
||||
if (baseHead) {
|
||||
const match = /refs\/heads\/(.+)/.exec(baseHead);
|
||||
baseBranch = match && match[1] || baseBranch;
|
||||
}
|
||||
|
||||
if (result.code) {
|
||||
console.log(result.stderr);
|
||||
process.exit(1);
|
||||
}
|
||||
// We need to fetch origin explicitly because it might be stale.
|
||||
// I couldn't find a reliable way to do this without fetch.
|
||||
const result = shelljs.exec(
|
||||
`git fetch origin ${baseBranch} && git log --reverse --format=%s HEAD ^origin/${baseBranch}`);
|
||||
|
||||
const commitsByLine = result.trim().split(/\n/).filter(line => line != '');
|
||||
if (result.code) {
|
||||
throw new Error(`Failed to fetch commits: ${result.stderr}`);
|
||||
}
|
||||
|
||||
console.log(`Examining ${commitsByLine.length} commits between HEAD and ${baseBranch}`);
|
||||
const commitsByLine = result.trim().split(/\n/).filter(line => line != '');
|
||||
|
||||
if (commitsByLine.length == 0) {
|
||||
console.log(`There are zero new commits between this HEAD and ${baseBranch}`);
|
||||
}
|
||||
console.log(`Examining ${commitsByLine.length} commits between HEAD and ${baseBranch}`);
|
||||
|
||||
const someCommitsInvalid = !commitsByLine.every(validateCommitMessage);
|
||||
if (commitsByLine.length == 0) {
|
||||
console.log(`There are zero new commits between this HEAD and ${baseBranch}`);
|
||||
}
|
||||
|
||||
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');
|
||||
const someCommitsInvalid = !commitsByLine.every(validateCommitMessage);
|
||||
|
||||
if (someCommitsInvalid) {
|
||||
throw new Error(
|
||||
'Please fix the failing commit messages before continuing...\n' +
|
||||
'Commit message guidelines: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue