|
| 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 */ |
0 commit comments