-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci.publish.js
67 lines (56 loc) · 2.1 KB
/
ci.publish.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* tslint:disable: no-console */
const exec = require('shell-utils').exec;
const {log, logSection, getVersionSafe} = require('./ci.common');
function publishNewVersion(packageVersion, npmTag) {
validatePrerequisites();
projectSetup();
publishToNpm(npmTag);
const newVersion = getVersionSafe();
if (newVersion === packageVersion) {
log(`Stopping: Lerna completed without upgrading the version - nothing to publish (version is ${newVersion})`);
return false;
}
updateGit(newVersion);
return true;
}
function validatePrerequisites() {
const lernaBin = exec.which('lerna');
if (!lernaBin) {
throw new Error(`Cannot publish: lerna not installed!`);
}
}
function projectSetup() {
logSection('Project setup');
exec.execSync(`git checkout ${process.env.GIT_BRANCH}`);
exec.execSync(`lerna bootstrap --no-ci`);
}
function publishToNpm(npmTag) {
logSection('Lerna publish');
const versionType = process.env.RELEASE_VERSION_TYPE;
const dryRun = process.env.RELEASE_DRY_RUN === "true";
const skipNpm = process.env.RELEASE_SKIP_NPM === "true";
if (dryRun) {
log('DRY RUN: Lerna-publishing without publishing to NPM');
}
else if (skipNpm) {
log('SKIP NPM is set: Lerna-publishing without publishing to NPM');
}
const preid = npmTag === 'latest'? '': `--preid='${npmTag}`;
exec.execSync(`lerna publish --cd-version "${versionType}" --yes --dist-tag ${npmTag} ${preid} --no-git-tag-version --no-push ${(dryRun || skipNpm) ? '--skip-npm' : ''}`);
exec.execSync('git status');
}
function updateGit(newVersion) {
logSection('Packing changes up onto a git commit');
exec.execSync(`git add -u`);
exec.execSync(`git commit -m "Publish ${newVersion} [ci skip]"`);
exec.execSync(`git tag ${newVersion}`);
exec.execSync(`git log -1 --date=short --pretty=format:'%h %ad %s %d %cr %an'`);
const dryRun = process.env.RELEASE_DRY_RUN === "true";
if (dryRun) {
log('DRY RUN: not pushing to git');
} else {
exec.execSync(`git push deploy ${process.env.GIT_BRANCH}`);
exec.execSync(`git push --tags deploy ${process.env.GIT_BRANCH}`);
}
}
module.exports = publishNewVersion;