@samitouri / QOS-React / commits / a0eb2653b8

[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

Lauren Tan committed May 15, 2024 at 16:13 UTC a0eb2653b89179927d0567ef65d847a3dfb84bf8
1 file changed +15 -4
compiler/scripts/publish.js
+15 -4
@@ -69,6 +69,13 @@ async function getDateStringForCommit(commit) {
69 * the command only report what it would have done, instead of actually publishing to npm.
70 */
71 async function main() {
72 + const currBranchName = await execHelper("git rev-parse --abbrev-ref HEAD");
73 + const isPristine = (await execHelper("git status --porcelain")) === "";
74 + if (currBranchName !== "main" || isPristine === false) {
75 + throw new Error(
76 + "This script must be run from the `main` branch with no uncommitted changes",
77 + );
78 + }
79 const argv = yargs(process.argv.slice(2))
80 .option("packages", {
81 description: "which packages to publish, defaults to all",
@@ -194,10 +201,14 @@ async function main() {
201
202 const opts = debug === true ? ["publish", "--dry-run"] : ["publish"];
203 try {
197 - await spawnHelper("npm", [...opts, "--registry=http://registry.npmjs.org"], {
198 - cwd: pkgDir,
199 - stdio: "inherit",
200 - });
204 + await spawnHelper(
205 + "npm",
206 + [...opts, "--registry=http://registry.npmjs.org"],
207 + {
208 + cwd: pkgDir,
209 + stdio: "inherit",
210 + },
211 + );
212 console.log("\n");
213 } catch (e) {
214 spinner.fail(e.toString());