|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +/** |
| 13 | + * This script prepares a release package to be pushed to npm |
| 14 | + * It will: |
| 15 | + * * It updates the version in json/gradle files and makes sure they are consistent between each other (set-rn-version) |
| 16 | + * * Updates podfile for RNTester |
| 17 | + * * Commits changes and tags with the next version based off of last version tag. |
| 18 | + * This in turn will trigger another CircleCI job to publish to npm |
| 19 | + */ |
| 20 | +const {echo, exec, exit} = require('shelljs'); |
| 21 | +const yargs = require('yargs'); |
| 22 | +const { |
| 23 | + isReleaseBranch, |
| 24 | + isTaggedLatest, |
| 25 | + getNextVersionFromTags, |
| 26 | +} = require('./version-utils'); |
| 27 | + |
| 28 | +const branch = process.env.CIRCLE_BRANCH; |
| 29 | +const currentCommit = process.env.CIRCLE_SHA1; |
| 30 | + |
| 31 | +const argv = yargs.option('r', { |
| 32 | + alias: 'remote', |
| 33 | + default: 'origin', |
| 34 | +}).argv; |
| 35 | + |
| 36 | +if (!isReleaseBranch(branch)) { |
| 37 | + console.error('This needs to be on a release branch'); |
| 38 | + exit(1); |
| 39 | +} |
| 40 | + |
| 41 | +// Progress the version by 1 using existing git tags |
| 42 | +const {version} = getNextVersionFromTags(branch); |
| 43 | + |
| 44 | +if (exec(`node scripts/set-rn-version.js --to-version ${version}`).code) { |
| 45 | + echo(`Failed to set React Native version to ${version}`); |
| 46 | + exit(1); |
| 47 | +} |
| 48 | + |
| 49 | +// Release builds should commit the version bumps, and create tags. |
| 50 | +echo('Updating RNTester Podfile.lock...'); |
| 51 | +if (exec('source scripts/update_podfile_lock.sh && update_pods').code) { |
| 52 | + echo('Failed to update RNTester Podfile.lock.'); |
| 53 | + echo('Fix the issue, revert and try again.'); |
| 54 | + exit(1); |
| 55 | +} |
| 56 | + |
| 57 | +// Check if this release has been tagged as latest |
| 58 | +const isLatest = isTaggedLatest(currentCommit); |
| 59 | + |
| 60 | +// Make commit [0.21.0-rc] Bump version numbers |
| 61 | +if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) { |
| 62 | + echo('failed to commit'); |
| 63 | + exit(1); |
| 64 | +} |
| 65 | + |
| 66 | +// Since we just committed, if `isLatest`, move the tag to commit we just made |
| 67 | +// This tag will also update npm release as `latest` |
| 68 | +if (isLatest) { |
| 69 | + exec('git tag -d latest'); |
| 70 | + exec(`git push ${remote} :latest`); |
| 71 | + exec('git tag latest'); |
| 72 | + exec(`git push ${remote} latest`); |
| 73 | +} |
| 74 | + |
| 75 | +// Add tag v0.21.0-rc.1 |
| 76 | +if (exec(`git tag v${version}`).code) { |
| 77 | + echo( |
| 78 | + `failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`, |
| 79 | + ); |
| 80 | + echo('You may want to rollback the last commit'); |
| 81 | + echo('git reset --hard HEAD~1'); |
| 82 | + exit(1); |
| 83 | +} |
| 84 | + |
| 85 | +// Push newly created tag |
| 86 | +let remote = argv.remote; |
| 87 | +exec(`git push ${remote} v${version}`); |
| 88 | + |
| 89 | +exec(`git push ${remote} ${branch} --follow-tags`); |
| 90 | + |
| 91 | +exit(0); |
0 commit comments