-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.js
63 lines (50 loc) · 1.69 KB
/
release.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
const cp = require('child_process');
const p = require('path');
function execSync(cmd) {
cp.execSync(cmd, { stdio: ['inherit', 'inherit', 'inherit'] });
}
function execSyncRead(cmd) {
return String(cp.execSync(cmd, { stdio: ['inherit', 'pipe', 'inherit'] })).trim();
}
function execSyncSilently(cmd) {
cp.execSync(cmd, { stdio: ['ignore', 'ignore', 'ignore'] });
}
function validateEnv() {
if (!process.env.CI || !process.env.TRAVIS) {
throw new Error(`releasing is only available from Travis CI`);
}
if (process.env.TRAVIS_BRANCH !== 'master') {
console.error(`not publishing on branch ${process.env.TRAVIS_BRANCH}`);
return false;
}
if (process.env.TRAVIS_PULL_REQUEST !== 'false') {
console.error(`not publishing as triggered by pull request ${process.env.TRAVIS_PULL_REQUEST}`);
return false;
}
return true;
}
function setupGit() {
execSyncSilently(`git config --global push.default simple`);
execSyncSilently(`git config --global user.email "${process.env.GIT_EMAIL}"`);
execSyncSilently(`git config --global user.name "${process.env.GIT_USER}"`);
const remoteUrl = new RegExp(`https?://(\\S+)`).exec(execSyncRead(`git remote -v`))[1];
execSyncSilently(`git remote remove origin`);
execSyncSilently(`git remote add origin "https://${process.env.GIT_USER}:${process.env.GIT_TOKEN}@${remoteUrl}"`);
execSync(`git checkout master`);
}
function copyNpmRc() {
const npmrcPath = p.resolve(`${__dirname}/.npmrc`);
execSync(`cp -rf ${npmrcPath} .`);
}
function release() {
execSync(`lerna publish -m "[skip ci] Publish" --cd-version patch --yes`);
}
function run() {
if (!validateEnv()) {
return;
}
setupGit();
copyNpmRc();
release();
}
run();