1/** 2 * Copyright (c) Meta Platforms, Inc. and 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 is triggered to run on CircleCI 15 * It will: 16 * * It updates the version in json/gradle files and makes sure they are consistent between each other (set-rn-version) 17 * * Updates podfile for RNTester 18 * * Commits changes and tags with the next version based off of last version tag. 19 * This in turn will trigger another CircleCI job to publish to npm 20 */ 21const {echo, exec, exit} = require('shelljs'); 22const yargs = require('yargs'); 23const {isReleaseBranch, parseVersion} = require('./version-utils'); 24 25const argv = yargs 26 .option('r', { 27 alias: 'remote', 28 default: 'origin', 29 }) 30 .option('v', { 31 alias: 'to-version', 32 type: 'string', 33 required: true, 34 }) 35 .option('l', { 36 alias: 'latest', 37 type: 'boolean', 38 default: false, 39 }).argv; 40 41const branch = process.env.CIRCLE_BRANCH; 42const remote = argv.remote; 43const releaseVersion = argv.toVersion; 44const isLatest = argv.latest; 45 46if (!isReleaseBranch(branch)) { 47 console.error(`This needs to be on a release branch. On branch: ${branch}`); 48 exit(1); 49} 50 51const {version} = parseVersion(releaseVersion); 52if (version == null) { 53 console.error(`Invalid version provided: ${releaseVersion}`); 54 exit(1); 55} 56 57if (exec(`node scripts/set-rn-version.js --to-version ${version}`).code) { 58 echo(`Failed to set React Native version to ${version}`); 59 exit(1); 60} 61 62// Release builds should commit the version bumps, and create tags. 63echo('Updating RNTester Podfile.lock...'); 64if (exec('source scripts/update_podfile_lock.sh && update_pods').code) { 65 echo('Failed to update RNTester Podfile.lock.'); 66 echo('Fix the issue, revert and try again.'); 67 exit(1); 68} 69 70// Make commit [0.21.0-rc] Bump version numbers 71if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) { 72 echo('failed to commit'); 73 exit(1); 74} 75 76// Add tag v0.21.0-rc.1 77if (exec(`git tag -a v${version} -m "v${version}"`).code) { 78 echo( 79 `failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`, 80 ); 81 echo('You may want to rollback the last commit'); 82 echo('git reset --hard HEAD~1'); 83 exit(1); 84} 85 86// If `isLatest`, this git tag will also set npm release as `latest` 87if (isLatest) { 88 exec('git tag -d latest'); 89 exec(`git push ${remote} :latest`); 90 91 // This will be pushed with the `--follow-tags` 92 exec('git tag -a latest -m "latest"'); 93} 94 95exec(`git push ${remote} ${branch} --follow-tags`); 96 97exit(0); 98