ut-tools
Version:
Build and Release management automation package.
58 lines (52 loc) • 1.94 kB
JavaScript
/* eslint no-process-env:0, no-process-exit:0, no-console:0 */
const exec = require('../lib/exec');
const fs = require('fs');
const gitLog = exec('git', ['log', '-1', '--oneline'], 'pipe', false);
if (!process.env.UT_MODULE) {
const utModule = (process.env.GIT_URL || '').match(/^.*\/.*-(.*)\.git$/);
if (utModule) {
process.env.UT_MODULE = utModule[1];
}
}
require('../lib/setEnv');
if (process.env.JOB_TYPE !== 'pipeline' && fs.existsSync('Jenkinsfile')) {
console.error('SKIPPING OLD JENKINS JOBS');
process.exit(0);
}
let command;
const jobname = process.env.JOB_NAME || '';
const SKIP = /\[ci-skip]/;
const BRANCH = /^origin\/(master|(hotfix|major|minor|patch)\/[^/]+)$/;
const branch = process.env.BRANCH_NAME || process.env.GIT_BRANCH;
if (!/^origin\/(\w+\/)?(\w+-)*\w+$/.test(branch)) throw new Error('Branches names must match the following formats: xxx/yyy-zzz, xxx/yyy or xxx');
if (
process.env.JOB_TYPE === 'pipeline' &&
!gitLog.match(SKIP) &&
BRANCH.test(branch)
) {
command = process.env.CHANGE_ID ? 'cover' : 'release';
} else if (
/^(ut|(ut|create|impl|standard-service)(-\w{2,})+)(_cr|_post-commit)$/.test(jobname) &&
/SCMTRIGGER/.test(process.env.BUILD_CAUSE) &&
(
// /^(master|(hotfix|major|minor|patch)\/[^/]+)$/.test(process.env.gitlabSourceBranch) ||
BRANCH.test(branch)
)
) {
if (gitLog.match(SKIP)) {
console.error('SHOULD NOT BE RUN IN CI', gitLog);
process.exit(1);
}
command = 'release';
} else {
command = 'cover';
}
let result;
try {
result = exec('npm', ['run', command], undefined, false);
if (result !== false && require(process.env.npm_package_json)?.scripts?.review && process.env.CHANGE_ID) result = exec('npm', ['run', 'review'], undefined, false);
} finally {
exec('ut-run', ['metrics'], {shell: true}, false);
if (result === false) process.exit(1);
}