Skip to content

Commit aec90bb

Browse files
bestanderFacebook Github Bot 4
authored andcommitted
Version release script
Summary:npm-publish.js is not cohesive enough: besides building and publishing it also modifies some files. It is better to have a separate script that will bump versions, make a commit and tag it. scripts/bump-oss-version.js does exactly that. This simplifies release process and allows manual release to npm if CI is not available. Closes #6625 Differential Revision: D3092849 fb-gh-sync-id: 92cf38bd3df31c8c9c433fc5f9e15c129855fe0e shipit-source-id: 92cf38bd3df31c8c9c433fc5f9e15c129855fe0e
1 parent 0f62dce commit aec90bb

File tree

4 files changed

+87
-28
lines changed

4 files changed

+87
-28
lines changed

ReactAndroid/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION_NAME=0.12.0-SNAPSHOT
1+
VERSION_NAME=0.0.1-master
22
GROUP=com.facebook.react
33

44
POM_NAME=ReactNative

Releases.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Run:
3434

3535
```
3636
git checkout -b <version_you_are_releasing>-stable # e.g. git checkout -b 0.22-stable
37-
git tag v<version_you_are_releasing>.0-rc # e.g. git tag v0.22.0-rc
37+
node ./scripts/bump-oss-version.js <exact-version_you_are_releasing> # e.g. git node ./scripts/bump-oss-version.js 0.22.0-rc
38+
./scripts/test-manual-e2e.sh # to double check that e2e process works
3839
git push origin <version_you_are_releasing>-stable --tags # e.g. git push origin 0.22-stable --tags
3940
```
4041

@@ -86,7 +87,7 @@ git cherry-pick commitHash1
8687
If everything worked:
8788

8889
```
89-
git tag v-version_you_are_releasing # e.g. git tag v0.22.0, git tag v0.22.1
90+
node ./scripts/bump-oss-version.js <exact_version_you_are_releasing> # e.g. git node ./scripts/bump-oss-version.js 0.22.0
9091
git tag -d latest
9192
git push origin :latest
9293
git tag latest # for docs [website](https://facebook.github.io/react-native) to be generated

scripts/bump-oss-version.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
'use strict';
10+
11+
/**
12+
* This script bumps a new version for open source releases.
13+
* It updates the version in podspec/json/gradle files and makes sure they are consistent between each other
14+
* After changing the files it makes a commit and tags it.
15+
* All you have to do is push changes to remote and CI will make a new build.
16+
*/
17+
/*eslint-disable no-undef */
18+
require(`shelljs/global`);
19+
20+
// - check we are in release branch, e.g. 0.33-stable
21+
let branch = exec(`git symbolic-ref --short HEAD`, {silent: true}).stdout.trim();
22+
23+
if (branch.indexOf(`-stable`) === -1) {
24+
echo(`You must be in 0.XX-stable branch to bump a version`);
25+
exit(1);
26+
}
27+
28+
// e.g. 0.33
29+
let versionMajor = branch.slice(0, branch.indexOf(`-stable`));
30+
31+
// - check that argument version matches branch
32+
// e.g. 0.33.1 or 0.33.0-rc4
33+
let version = process.argv[2];
34+
if (!version || version.indexOf(versionMajor) !== 0) {
35+
echo(`You must pass a tag like ${versionMajor}.[X]-rc[Y] to bump a version`);
36+
exit(1);
37+
}
38+
39+
let packageJson = JSON.parse(cat(`package.json`));
40+
packageJson.version = version;
41+
JSON.stringify(packageJson, null, 2).to(`package.json`);
42+
43+
// - change ReactAndroid/gradle.properties
44+
if (sed(`-i`, /^VERSION_NAME=.*/, `VERSION_NAME=${version}`, `ReactAndroid/gradle.properties`).code) {
45+
echo(`Couldn't update version for Gradle`);
46+
exit(1);
47+
}
48+
49+
// - change React.podspec
50+
if (sed(`-i`, /s.version\s*=.*/, `s.version = \"${version}\"`, `React.podspec`).code) {
51+
echo(`Couldn't update version for React.podspec`);
52+
exit(1);
53+
}
54+
55+
// verify that files changed, we just do a git diff and check how many times version is added across files
56+
let numberOfChangedLinesWithNewVersion = exec(`git diff -U0 | grep '^[+]' | grep -c ${version} `, {silent: true})
57+
.stdout.trim();
58+
if (+numberOfChangedLinesWithNewVersion !== 3) {
59+
echo(`Failed to update all the files. React.podspec, package.json and gradle.properties must have versions in them`);
60+
echo(`Fix the issue, revert and try again`);
61+
exec(`git diff`);
62+
exit(1);
63+
}
64+
65+
// - make commit [0.21.0-rc] Bump version numbers
66+
if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) {
67+
echo(`failed to commit`);
68+
exit(1);
69+
}
70+
71+
// - add tag v0.21.0-rc
72+
if (exec(`git tag v${version}`).code) {
73+
echo(`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`);
74+
echo(`You may want to rollback the last commit`);
75+
echo(`git reset --hard HEAD~1`);
76+
exit(1);
77+
}
78+
79+
exit(0);
80+
/*eslint-enable no-undef */

scripts/publish-npm.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ if (javaVersion.indexOf(requiredJavaVersion) === -1) {
9090
exit(1);
9191
}
9292

93-
if (sed(`-i`, /^VERSION_NAME=[0-9\.]*-SNAPSHOT/, `VERSION_NAME=${releaseVersion}`, `ReactAndroid/gradle.properties`).code) {
94-
echo(`Couldn't update version for Gradle`);
95-
exit(1);
96-
}
97-
9893
// Uncomment Javadoc generation
9994
if (sed(`-i`, `// archives androidJavadocJar`, `archives androidJavadocJar`, `ReactAndroid/release.gradle`).code) {
10095
echo(`Couldn't enable Javadoc generation`);
@@ -106,6 +101,9 @@ if (exec(`./gradlew :ReactAndroid:installArchives`).code) {
106101
exit(1);
107102
}
108103

104+
// undo uncommenting javadoc setting
105+
exec(`git checkout ReactAndroid/gradle.properties`);
106+
109107
echo("Generated artifacts for Maven");
110108

111109
let artifacts = ['-javadoc.jar', '-sources.jar', '.aar', '.pom'].map((suffix) => {
@@ -119,23 +117,6 @@ artifacts.forEach((name) => {
119117
}
120118
});
121119

122-
// ----------- Reverting changes to local files
123-
124-
exec(`git checkout ReactAndroid/gradle.properties`);
125-
exec(`git checkout ReactAndroid/release.gradle`);
126-
127-
128-
if (exec(`npm version --no-git-tag-version ${releaseVersion}`).code) {
129-
echo(`Couldn't update version for npm`);
130-
exit(1);
131-
}
132-
if (sed(`-i`, `s.version = "0.0.1-master"`, `s.version = \"${releaseVersion}\"`, `React.podspec`).code) {
133-
echo(`Couldn't update version for React.podspec`);
134-
exit(1);
135-
}
136-
137-
// shrinkwrapping without dev dependencies
138-
exec(`npm shrinkwrap`);
139120
if (releaseVersion.indexOf(`-rc`) === -1) {
140121
// release, package will be installed by default
141122
exec(`npm publish`);
@@ -144,9 +125,6 @@ if (releaseVersion.indexOf(`-rc`) === -1) {
144125
exec(`npm publish --tag next`);
145126
}
146127

147-
exec(`git checkout package.json`);
148-
exec(`git checkout React.podspec`);
149-
150128
echo(`Published to npm ${releaseVersion}`);
151129

152130
exit(0);

0 commit comments

Comments
 (0)