Skip to content

Commit 07c6a51

Browse files
authored
Cleanup old script files and packagejson scripts commands (#1986)
* Cleanup old script files and packagejson scripts commands * Rename script file name * Update bkRelease to release
1 parent f0fe7fa commit 07c6a51

File tree

8 files changed

+71
-188
lines changed

8 files changed

+71
-188
lines changed

.buildkite/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ steps:
1212
- "npm install"
1313
- "npm run test"
1414
- "npm run build"
15-
- "[[ $BUILDKITE_PULL_REQUEST == 'false' ]] && npm run bkRelease && npm run demo || true"
15+
- "[[ $BUILDKITE_PULL_REQUEST == 'false' ]] && npm run release && npm run demo || true"
1616
timeout_in_minutes: 15

package.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,23 @@
1515
},
1616
"scripts": {
1717
"start": "watchman watch-del-all && export DEV_MODE=true && react-native start",
18-
"start-ios": "node ./scripts/cliStuff.js",
1918
"ios": "react-native run-ios",
20-
"iPad": "react-native run-ios --simulator='iPad Pro (9.7 inch)'",
2119
"android": "react-native run-android",
20+
"iPad": "react-native run-ios --simulator='iPad Pro (9.7 inch)'",
2221
"pretest": "npm run lint",
2322
"test": "jest",
2423
"test:watch": "jest --watch",
2524
"lint": "eslint src -c .eslintrc.js --ext .tsx,.ts,.js",
2625
"lint:fix": "eslint src -c .eslintrc.js --fix",
27-
"lint:test": "mocha --compilers js:babel-core/register eslint-rules/tests/lib/rules",
2826
"xcode": "xed ios",
2927
"build:dev": "tsc --p tsconfig.dev.json",
30-
"build:src": "./node_modules/.bin/babel src --out-dir src --config-file ./src/.babelrc.json --extensions '.ts,.tsx' --ignore 'src/index.ts'",
31-
"build:lib": "./node_modules/.bin/babel lib --out-dir lib --config-file ./src/.babelrc.json --extensions '.ts,.tsx'",
32-
"build:exports": "npm run build:src && npm run build:lib",
33-
"build:packages": "node scripts/buildPackages.js",
3428
"build": "node scripts/build.js",
3529
"prepush": "npm run build:dev && npm run test",
36-
"log": "react-native log-ios | grep 'ethan -'",
3730
"docs:deploy": "./scripts/deployDocs.sh",
38-
"docs:build": "node scripts/build-docs.js",
31+
"docs:build": "node scripts/buildDocs.js",
3932
"snippets:build": "node scripts/generateSnippets.js",
40-
"bump:patch": "npm version patch",
4133
"demo": "./scripts/demo.sh",
42-
"release": "node ./scripts/release.js",
43-
"bkRelease": "node ./scripts/bkRelease.js"
34+
"release": "node ./scripts/release.js"
4435
},
4536
"dependencies": {
4637
"babel-plugin-transform-inline-environment-variables": "^0.0.2",

scripts/bkRelease.js

Lines changed: 0 additions & 93 deletions
This file was deleted.
File renamed without changes.

scripts/deploy.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.
File renamed without changes.

scripts/release.js

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,93 @@
1+
const exec = require('shell-utils').exec;
12
const cp = require('child_process');
2-
const p = require('path');
33
const semver = require('semver');
4+
const _ = require('lodash');
5+
const p = require('path');
46

5-
function execSync(cmd) {
6-
cp.execSync(cmd, { stdio: ['inherit', 'inherit', 'inherit'] });
7-
}
7+
// Workaround JS
88

9-
function execSyncRead(cmd) {
10-
return String(cp.execSync(cmd, { stdio: ['inherit', 'pipe', 'inherit'] })).trim();
9+
// Export buildkite variables for Release build
10+
// We cast toString() because function returns 'object'
11+
const isRelease = process.env.BUILDKITE_MESSAGE.match(/^release$/i);
12+
let VERSION;
13+
if (isRelease) {
14+
VERSION = cp.execSync(`buildkite-agent meta-data get version`).toString();
1115
}
1216

13-
function execSyncSilently(cmd) {
14-
cp.execSync(cmd, { stdio: ['ignore', 'ignore', 'ignore'] });
17+
const VERSION_TAG = isRelease ? 'latest' : 'snapshot';
18+
const VERSION_INC = 'patch';
19+
function run() {
20+
if (!validateEnv()) {
21+
return;
22+
}
23+
setupGit();
24+
createNpmRc();
25+
versionTagAndPublish();
1526
}
1627

1728
function validateEnv() {
18-
if (!process.env.CI || !process.env.TRAVIS) {
19-
throw new Error(`releasing is only available from Travis CI`);
20-
}
21-
22-
if (process.env.TRAVIS_BRANCH !== 'master') {
23-
console.error(`not publishing on branch ${process.env.TRAVIS_BRANCH}`);
24-
return false;
29+
if (!process.env.CI) {
30+
throw new Error('releasing is only available from CI');
2531
}
26-
27-
if (process.env.TRAVIS_PULL_REQUEST !== 'false') {
28-
console.error(`not publishing as triggered by pull request ${process.env.TRAVIS_PULL_REQUEST}`);
29-
return false;
30-
}
31-
3232
return true;
3333
}
3434

3535
function setupGit() {
36-
execSyncSilently(`git config --global push.default simple`);
37-
execSyncSilently(`git config --global user.email "${process.env.GIT_EMAIL}"`);
38-
execSyncSilently(`git config --global user.name "${process.env.GIT_USERNAME}"`);
39-
const remoteUrl = new RegExp(`https?://(\\S+)`).exec(execSyncRead(`git remote -v`))[1];
40-
execSyncSilently(`git remote add deploy "https://${process.env.GIT_USERNAME}:${process.env.GIT_TOKEN}@${remoteUrl}"`);
41-
execSync(`git checkout master`);
36+
exec.execSyncSilent('git config --global push.default simple');
37+
exec.execSyncSilent(`git config --global user.email "${process.env.GIT_EMAIL}"`);
38+
exec.execSyncSilent(`git config --global user.name "${process.env.GIT_USER}"`);
39+
const remoteUrl = new RegExp('https?://(\\S+)').exec(exec.execSyncRead('git remote -v'))[1];
40+
exec.execSyncSilent(`git remote add deploy "https://${process.env.GIT_USER}:${process.env.GIT_TOKEN}@${remoteUrl}"`);
41+
// exec.execSync(`git checkout ${ONLY_ON_BRANCH}`);
4242
}
4343

44-
function calcNewVersion() {
45-
const latestVersion = execSyncRead(`npm view ${process.env.npm_package_name}@latest version`);
46-
console.log(`latest version is: ${latestVersion}`);
47-
console.log(`package version is: ${process.env.npm_package_version}`);
48-
if (semver.gt(process.env.npm_package_version, latestVersion)) {
49-
return semver.inc(process.env.npm_package_version, 'patch');
50-
} else {
51-
return semver.inc(latestVersion, 'patch');
52-
}
44+
function createNpmRc() {
45+
exec.execSync('rm -f package-lock.json');
46+
const npmrcPath = p.resolve(`${__dirname}/.npmrc`);
47+
exec.execSync(`cp -rf ${npmrcPath} .`);
5348
}
5449

55-
function copyNpmRc() {
56-
execSync(`rm -f package-lock.json`);
57-
const npmrcPath = p.resolve(`${__dirname}/.npmrc`);
58-
execSync(`cp -rf ${npmrcPath} .`);
50+
function versionTagAndPublish() {
51+
const currentPublished = findCurrentPublishedVersion();
52+
console.log(`current published version: ${currentPublished}`);
53+
54+
const version = isRelease ? VERSION : `${currentPublished}-snapshot.${process.env.BUILDKITE_BUILD_NUMBER}`;
55+
console.log(`Publishing version: ${version}`);
56+
57+
tryPublishAndTag(version);
5958
}
6059

61-
function tagAndPublish(newVersion) {
62-
console.log(`new version is: ${newVersion}`);
63-
execSync(`npm version ${newVersion} -m "v${newVersion} [ci skip]"`);
64-
execSync(`npm publish --tag latest`);
65-
execSyncSilently(`git push deploy --tags`);
60+
function findCurrentPublishedVersion() {
61+
return exec.execSyncRead(`npm view ${process.env.npm_package_name} dist-tags.latest`);
6662
}
6763

68-
function run() {
69-
if (!validateEnv()) {
70-
return;
64+
function tryPublishAndTag(version) {
65+
let theCandidate = version;
66+
for (let retry = 0; retry < 5; retry++) {
67+
try {
68+
tagAndPublish(theCandidate);
69+
console.log(`Released ${theCandidate}`);
70+
return;
71+
} catch (err) {
72+
const alreadyPublished = _.includes(err.toString(), 'You cannot publish over the previously published version');
73+
if (!alreadyPublished) {
74+
throw err;
75+
}
76+
console.log(`previously published. retrying with increased ${VERSION_INC}...`);
77+
theCandidate = semver.inc(theCandidate, VERSION_INC);
78+
}
7179
}
72-
setupGit();
73-
copyNpmRc();
74-
tagAndPublish(calcNewVersion());
80+
}
81+
82+
83+
function tagAndPublish(newVersion) {
84+
console.log(`trying to publish ${newVersion}...`);
85+
exec.execSync(`npm --no-git-tag-version version ${newVersion}`);
86+
exec.execSync(`npm publish --tag ${VERSION_TAG}`);
87+
if (isRelease) {
88+
exec.execSync(`git tag -a ${newVersion} -m "${newVersion}"`);
89+
}
90+
exec.execSyncSilent(`git push deploy ${newVersion} || true`);
7591
}
7692

7793
run();

scripts/utils/propTypesHandler.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)