-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci.release.js
86 lines (68 loc) · 2.4 KB
/
ci.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* tslint:disable: no-console */
const exec = require('shell-utils').exec;
const fs = require('fs');
const {log, logSection, getVersionSafe} = require('./ci.common');
const isRelease = (process.env.RELEASE_VERSION_TYPE && process.env.RELEASE_VERSION_TYPE !== 'none');
const ONLY_ON_BRANCH = 'origin/master';
function run() {
logSection('Script started');
if (!validateEnv()) {
return;
}
log('Configuring stuff...');
setupGitConfig();
setupNpmConfig();
versionTagAndPublish();
}
function validateEnv() {
if (!process.env.JENKINS_CI) {
throw new Error(`Release blocked: Not on a CI build machine!`);
}
if (!process.env.JENKINS_MASTER) {
log(`Release blocked: Not on jenkins' master build job!`);
return false;
}
if (process.env.GIT_BRANCH !== ONLY_ON_BRANCH) {
log(`Release blocked: Not publishing on branch ${process.env.GIT_BRANCH}, which isn't ${ONLY_ON_BRANCH}`);
return false;
}
return true;
}
function setupGitConfig() {
exec.execSyncSilent(`git config --global push.default simple`);
exec.execSyncSilent(`git config --global user.email "${process.env.GIT_EMAIL}"`);
exec.execSyncSilent(`git config --global user.name "${process.env.GIT_USER}"`);
const remoteUrl = new RegExp(`https?://(\\S+)`).exec(exec.execSyncRead(`git remote -v`))[1];
exec.execSyncSilent(`git remote add deploy "https://${process.env.GIT_USER}:${process.env.GIT_TOKEN}@${remoteUrl}"`);
}
function setupNpmConfig() {
exec.execSync(`rm -f package-lock.json`);
const content = `
email=\${NPM_EMAIL}
//registry.npmjs.org/:_authToken=\${NPM_TOKEN}
`;
fs.writeFileSync(`.npmrc`, content);
// Workaround. see https://github.com/lerna/lerna/issues/361
fs.copyFileSync('.npmrc', 'detox/.npmrc');
fs.copyFileSync('.npmrc', 'detox-cli/.npmrc');
}
function versionTagAndPublish() {
logSection('Preparing to tag/release');
const packageVersion = getVersionSafe();
log(` package version: ${packageVersion}`);
const currentPublished = findCurrentPublishedVersion();
log(` current published version: ${currentPublished}`);
if (isRelease) {
const publishNewVersion = require('./ci.publish');
publishNewVersion(packageVersion);
} else {
// Disabled for the time being
// const tagVersion = require('./ci.tagversion');
// tagVersion(packageVersion, currentPublished);
}
log(`Great success, much amaze`);
}
function findCurrentPublishedVersion() {
return exec.execSyncRead(`npm view detox dist-tags.latest`);
}
run();