From a0eb2653b89179927d0567ef65d847a3dfb84bf8 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Wed, 15 May 2024 16:13:35 -0700 Subject: [PATCH] [compiler] Check if current branch is main This script needs to run from `main` since it commits version bumps for packages, and those need to point to publicly available hashes. So, throw an error if we're not already on main. ghstack-source-id: ce0168e826b990fd55733e777ee8effe4f35400a Pull Request resolved: https://github.com/facebook/react/pull/29083 --- compiler/scripts/publish.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/compiler/scripts/publish.js b/compiler/scripts/publish.js index 3079485418..74056ac317 100644 --- a/compiler/scripts/publish.js +++ b/compiler/scripts/publish.js @@ -69,6 +69,13 @@ async function getDateStringForCommit(commit) { * the command only report what it would have done, instead of actually publishing to npm. */ async function main() { + const currBranchName = await execHelper("git rev-parse --abbrev-ref HEAD"); + const isPristine = (await execHelper("git status --porcelain")) === ""; + if (currBranchName !== "main" || isPristine === false) { + throw new Error( + "This script must be run from the `main` branch with no uncommitted changes", + ); + } const argv = yargs(process.argv.slice(2)) .option("packages", { description: "which packages to publish, defaults to all", @@ -194,10 +201,14 @@ async function main() { const opts = debug === true ? ["publish", "--dry-run"] : ["publish"]; try { - await spawnHelper("npm", [...opts, "--registry=http://registry.npmjs.org"], { - cwd: pkgDir, - stdio: "inherit", - }); + await spawnHelper( + "npm", + [...opts, "--registry=http://registry.npmjs.org"], + { + cwd: pkgDir, + stdio: "inherit", + }, + ); console.log("\n"); } catch (e) { spinner.fail(e.toString());