From 1f63d6ed5d11e560fdc8b92060eb7dc515bf4ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= Date: Fri, 25 Feb 2022 10:52:55 -0800 Subject: [PATCH] Add script for bumping Hermes version for a release Summary: React Native releases that bundle the Hermes source code will have a `sdks/.hermesversion` file which indicates the specific git tag used when pulling the Hermes source code. This script provides a method for release coordinators to specify which Hermes tag will be used in a given release. The Hermes tag should already exist on the `facebook/hermes` repository on GitHub, although this script makes no determination as to its validity. # Changelog [Internal] Added new script for release coordinators Reviewed By: cortinico Differential Revision: D34460693 fbshipit-source-id: b2f882ba66d925034c3803aafe81de5204d9e33f --- scripts/bump-hermes-version.js | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 scripts/bump-hermes-version.js diff --git a/scripts/bump-hermes-version.js b/scripts/bump-hermes-version.js new file mode 100644 index 00000000000..67ed4f2be35 --- /dev/null +++ b/scripts/bump-hermes-version.js @@ -0,0 +1,76 @@ +#!/usr/bin/env node +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +'use strict'; + +/** + * This script walks a releaser through bumping the Hermes version for a release. + */ +const {exit} = require('shelljs'); +const yargs = require('yargs'); +const inquirer = require('inquirer'); +const fs = require('fs'); +const path = require('path'); + +const HERMES_TAG_FILE_DIR = 'sdks'; +const HERMES_TAG_FILE_PATH = `${HERMES_TAG_FILE_DIR}/.hermesversion`; + +let argv = yargs.option('t', { + alias: 'tag', + describe: + 'Hermes release tag to use for this React Native release, ex. hermes-2022-02-21-RNv0.68.0', + required: true, +}).argv; + +function readHermesTag() { + if (fs.existsSync(path)) { + const data = fs.readFileSync(HERMES_TAG_FILE_PATH, { + encoding: 'utf8', + flag: 'r', + }); + return data.trim(); + } else { + return ''; + } +} + +function setHermesTag(hermesTag) { + if (readHermesTag() === hermesTag) { + // No need to update. + return; + } + + if (!fs.existsSync(HERMES_TAG_FILE_DIR)) { + fs.mkdirSync(HERMES_TAG_FILE_DIR, {recursive: true}); + } + + fs.writeFileSync(HERMES_TAG_FILE_PATH, hermesTag.trim()); + console.log('Hermes tag has been updated. Please commit your changes.'); +} + +async function main() { + const hermesTag = argv.tag; + const {confirmHermesTag} = await inquirer.prompt({ + type: 'confirm', + name: 'confirmHermesTag', + message: `Do you want to use the Hermes release tagged "${hermesTag}"?`, + }); + + if (!confirmHermesTag) { + console.log('Aborting.'); + return; + } + + setHermesTag(hermesTag); +} + +main().then(() => { + exit(0); +});