2017-02-06 15:02:32 +00:00
|
|
|
#!/usr/bin/env node
|
2016-03-24 15:40:38 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This script bumps a new version for open source releases.
|
2017-02-27 21:25:47 +00:00
|
|
|
* It updates the version in json/gradle files and makes sure they are consistent between each other
|
2016-03-24 15:40:38 +00:00
|
|
|
* After changing the files it makes a commit and tags it.
|
|
|
|
* All you have to do is push changes to remote and CI will make a new build.
|
|
|
|
*/
|
2017-10-12 02:34:06 +00:00
|
|
|
const fs = require('fs');
|
2017-07-12 22:56:46 +00:00
|
|
|
const {
|
|
|
|
cat,
|
|
|
|
echo,
|
|
|
|
exec,
|
|
|
|
exit,
|
|
|
|
sed,
|
|
|
|
} = require('shelljs');
|
2016-03-24 15:40:38 +00:00
|
|
|
|
2017-02-06 15:02:32 +00:00
|
|
|
const minimist = require('minimist');
|
|
|
|
|
|
|
|
let argv = minimist(process.argv.slice(2), {
|
|
|
|
alias: {remote: 'r'},
|
|
|
|
default: {remote: 'origin'},
|
|
|
|
});
|
|
|
|
|
2016-03-24 15:40:38 +00:00
|
|
|
// - check we are in release branch, e.g. 0.33-stable
|
2017-10-10 00:37:08 +00:00
|
|
|
let branch = exec('git symbolic-ref --short HEAD', {silent: true}).stdout.trim();
|
2016-03-24 15:40:38 +00:00
|
|
|
|
2017-10-10 00:37:08 +00:00
|
|
|
if (branch.indexOf('-stable') === -1) {
|
|
|
|
echo('You must be in 0.XX-stable branch to bump a version');
|
2016-03-24 15:40:38 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// e.g. 0.33
|
2017-10-10 00:37:08 +00:00
|
|
|
let versionMajor = branch.slice(0, branch.indexOf('-stable'));
|
2016-03-24 15:40:38 +00:00
|
|
|
|
|
|
|
// - check that argument version matches branch
|
|
|
|
// e.g. 0.33.1 or 0.33.0-rc4
|
2017-02-06 15:02:32 +00:00
|
|
|
let version = argv._[0];
|
2016-03-24 15:40:38 +00:00
|
|
|
if (!version || version.indexOf(versionMajor) !== 0) {
|
2017-09-28 01:19:44 +00:00
|
|
|
echo(`You must pass a tag like 0.${versionMajor}.[X]-rc[Y] to bump a version`);
|
2016-03-24 15:40:38 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2017-09-28 01:19:44 +00:00
|
|
|
// Generate version files to detect mismatches between JS and native.
|
|
|
|
let match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/);
|
|
|
|
if (!match) {
|
|
|
|
echo(`You must pass a correctly formatted version; couldn't parse ${version}`);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
let [, major, minor, patch, prerelease] = match;
|
|
|
|
|
2017-10-12 02:34:06 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
'ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
|
|
|
|
cat('scripts/versiontemplates/ReactNativeVersion.java.template')
|
|
|
|
.replace('${major}', major)
|
|
|
|
.replace('${minor}', minor)
|
|
|
|
.replace('${patch}', patch)
|
|
|
|
.replace('${prerelease}', prerelease !== undefined ? `"${prerelease}"` : 'null'),
|
|
|
|
'utf-8'
|
|
|
|
);
|
2017-09-28 01:19:44 +00:00
|
|
|
|
2017-10-12 02:34:06 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
'React/Base/RCTVersion.h',
|
|
|
|
cat('scripts/versiontemplates/RCTVersion.h.template')
|
|
|
|
.replace('${major}', `@(${major})`)
|
|
|
|
.replace('${minor}', `@(${minor})`)
|
|
|
|
.replace('${patch}', `@(${patch})`)
|
|
|
|
.replace('${prerelease}', prerelease !== undefined ? `@"${prerelease}"` : '[NSNull null]'),
|
|
|
|
'utf-8'
|
|
|
|
);
|
2017-09-28 01:19:44 +00:00
|
|
|
|
2017-10-12 02:34:06 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
'Libraries/Core/ReactNativeVersion.js',
|
|
|
|
cat('scripts/versiontemplates/ReactNativeVersion.js.template')
|
|
|
|
.replace('${major}', major)
|
|
|
|
.replace('${minor}', minor)
|
|
|
|
.replace('${patch}', patch)
|
|
|
|
.replace('${prerelease}', prerelease !== undefined ? `'${prerelease}'` : 'null'),
|
|
|
|
'utf-8'
|
|
|
|
);
|
2017-09-28 01:19:44 +00:00
|
|
|
|
2017-10-10 00:37:08 +00:00
|
|
|
let packageJson = JSON.parse(cat('package.json'));
|
2016-03-24 15:40:38 +00:00
|
|
|
packageJson.version = version;
|
2017-10-12 02:34:06 +00:00
|
|
|
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2), 'utf-8');
|
2016-03-24 15:40:38 +00:00
|
|
|
|
|
|
|
// - change ReactAndroid/gradle.properties
|
2017-10-10 00:37:08 +00:00
|
|
|
if (sed('-i', /^VERSION_NAME=.*/, `VERSION_NAME=${version}`, 'ReactAndroid/gradle.properties').code) {
|
|
|
|
echo('Couldn\'t update version for Gradle');
|
2016-03-24 15:40:38 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify that files changed, we just do a git diff and check how many times version is added across files
|
|
|
|
let numberOfChangedLinesWithNewVersion = exec(`git diff -U0 | grep '^[+]' | grep -c ${version} `, {silent: true})
|
|
|
|
.stdout.trim();
|
2017-02-27 21:25:47 +00:00
|
|
|
if (+numberOfChangedLinesWithNewVersion !== 2) {
|
2017-10-10 00:37:08 +00:00
|
|
|
echo('Failed to update all the files. package.json and gradle.properties must have versions in them');
|
|
|
|
echo('Fix the issue, revert and try again');
|
|
|
|
exec('git diff');
|
2016-03-24 15:40:38 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// - make commit [0.21.0-rc] Bump version numbers
|
|
|
|
if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) {
|
2017-10-10 00:37:08 +00:00
|
|
|
echo('failed to commit');
|
2016-03-24 15:40:38 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// - add tag v0.21.0-rc
|
|
|
|
if (exec(`git tag v${version}`).code) {
|
|
|
|
echo(`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`);
|
2017-10-10 00:37:08 +00:00
|
|
|
echo('You may want to rollback the last commit');
|
|
|
|
echo('git reset --hard HEAD~1');
|
2016-03-24 15:40:38 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2016-09-23 15:24:15 +00:00
|
|
|
// Push newly created tag
|
2017-02-06 15:02:32 +00:00
|
|
|
let remote = argv.remote;
|
|
|
|
exec(`git push ${remote} v${version}`);
|
2016-09-23 15:24:15 +00:00
|
|
|
|
|
|
|
// Tag latest if doing stable release
|
2017-10-10 00:37:08 +00:00
|
|
|
if (version.indexOf('rc') === -1) {
|
|
|
|
exec('git tag -d latest');
|
2017-02-06 15:02:32 +00:00
|
|
|
exec(`git push ${remote} :latest`);
|
2017-10-10 00:37:08 +00:00
|
|
|
exec('git tag latest');
|
2017-02-06 15:02:32 +00:00
|
|
|
exec(`git push ${remote} latest`);
|
2016-09-23 15:24:15 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 15:02:32 +00:00
|
|
|
exec(`git push ${remote} ${branch} --follow-tags`);
|
2016-09-23 15:24:15 +00:00
|
|
|
|
2016-03-24 15:40:38 +00:00
|
|
|
exit(0);
|