Skip to content

Commit b094600

Browse files
hramosfacebook-github-bot
authored andcommitted
Deploy to npm on tagged commits only (facebook#21250)
Summary: This PR applies some fixes I made to the 0.57-stable branch to ensure we only run on commits tagged as "v0.57.1", as an example. This also ensures we only deploy after all tests pass. Pull Request resolved: facebook#21250 Differential Revision: D10003666 Pulled By: hramos fbshipit-source-id: 22d5e674ca925dce53d0ddf0e12c64dc82ec7aa1
1 parent c31f79f commit b094600

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

.circleci/config.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,11 @@ workflows:
677677
# Only runs on vX.X.X tags if all tests are green
678678
- publish_npm_package:
679679
filters:
680-
branches:
681-
only:
682-
- /.*-stable/
683680
tags:
684681
only: /v[0-9]+(\.[0-9]+)*(\-rc(\.[0-9]+)?)?/
685682
requires:
683+
- analyze
684+
- test_detox_end_to_end
686685
- test_javascript
687686
- test_objc
688687
- test_android

scripts/publish-npm.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,28 @@
1313
* This script publishes a new version of react-native to NPM.
1414
* It is supposed to run in CI environment, not on a developer's machine.
1515
*
16-
* To make it easier for developers it uses some logic to identify with which version to publish the package.
16+
* To make it easier for developers it uses some logic to identify with which
17+
* version to publish the package.
1718
*
1819
* To cut a branch (and release RC):
1920
* - Developer: `git checkout -b 0.XY-stable`
20-
* - Developer: `git tag v0.XY.0-rc` and `git push --tags` to [email protected]:facebook/react-native.git
21-
* - CI: test and deploy to npm (run this script) with version 0.XY.0-rc with tag "next"
21+
* - Developer: `./scripts/bump-oss-version.js v0.XY.0-rc.0`
22+
* - CI: test and deploy to npm (run this script) with version `0.XY.0-rc.0`
23+
* with tag "next"
2224
*
2325
* To update RC release:
2426
* - Developer: `git checkout 0.XY-stable`
2527
* - Developer: cherry-pick whatever changes needed
26-
* - Developer: `git tag v0.XY.0-rc1` and `git push --tags` to [email protected]:facebook/react-native.git
27-
* - CI: test and deploy to npm (run this script) with version 0.XY.0-rc1 with tag "next"
28+
* - Developer: `./scripts/bump-oss-version.js v0.XY.0-rc.1`
29+
* - CI: test and deploy to npm (run this script) with version `0.XY.0-rc.1`
30+
* with tag "next"
2831
*
2932
* To publish a release:
3033
* - Developer: `git checkout 0.XY-stable`
3134
* - Developer: cherry-pick whatever changes needed
32-
* - Developer: `git tag latest`
33-
* - Developer: `git tag v0.XY.0`
34-
* - Developer: `git push --tags` to [email protected]:facebook/react-native.git
35-
* - CI: test and deploy to npm (run this script) with version 0.XY.0 with and not tag (latest is implied by npm)
35+
* - Developer: `./scripts/bump-oss-version.js v0.XY.0`
36+
* - CI: test and deploy to npm (run this script) with version `0.XY.0`
37+
* and no tag ("latest" is implied by npm)
3638
*
3739
* To patch old release:
3840
* - Developer: `git checkout 0.XY-stable`
@@ -43,23 +45,28 @@
4345
* there is a version higher than XY
4446
*
4547
* Important tags:
46-
* If tag v0.XY.0-rcZ is present on the commit then publish to npm with version 0.XY.0-rcZ and tag next
48+
* If tag v0.XY.0-rc.Z is present on the commit then publish to npm with version 0.XY.0-rc.Z and tag next
4749
* If tag v0.XY.Z is present on the commit then publish to npm with version 0.XY.Z and no tag (npm will consider it latest)
4850
*/
4951

5052
/*eslint-disable no-undef */
5153
require('shelljs/global');
5254

53-
const buildBranch = process.env.CIRCLE_BRANCH;
55+
const buildTag = process.env.CIRCLE_TAG;
5456
const otp = process.env.NPM_CONFIG_OTP;
5557

56-
let branchVersion;
57-
if (buildBranch.indexOf('-stable') !== -1) {
58-
branchVersion = buildBranch.slice(0, buildBranch.indexOf('-stable'));
59-
} else {
60-
echo('Error: We publish only from stable branches');
61-
exit(0);
58+
if (!buildTag) {
59+
echo('Error: We publish only from git tags');
60+
exit(1);
61+
}
62+
63+
let match = buildTag.match(/^v(\d+\.\d+)\.\d+(?:-.+)?$/);
64+
if (!match) {
65+
echo('Error: We publish only from release version git tags');
66+
exit(1);
6267
}
68+
// 0.33
69+
let [, branchVersion] = match;
6370

6471
// 34c034298dc9cad5a4553964a5a324450fda0385
6572
const currentCommit = exec('git rev-parse HEAD', {silent: true}).stdout.trim();

0 commit comments

Comments
 (0)