Repository: facebook/react
Pull request: fix: update release scripts for react devtools

This has been broken since the migration to GitHub actions.

Previously, we've been using `buildId` as an identifier from CircleCI. I've decided to use a commit hash as an identifier, because I don't know if there is a better option, and `scripts/release/download_build_artifacts.js` allows us to download them for a specific commit.

Changed files:
filename: scripts/devtools/build-and-test.js
patch: @@ -50,13 +50,13 @@ async function main() {
   });
 
   const archivePath = await archiveGitRevision();
-  const buildID = await downloadLatestReactBuild();
+  const currentCommitHash = await downloadLatestReactBuild();
 
   await buildAndTestInlinePackage();
   await buildAndTestStandalonePackage();
   await buildAndTestExtensions();
 
-  saveBuildMetadata({archivePath, buildID});
+  saveBuildMetadata({archivePath, currentCommitHash});
 
   printFinalInstructions();
 }
@@ -197,12 +197,17 @@ async function downloadLatestReactBuild() {
 
   console.log('');
 
+  const currentCommitHash = (await exec('git rev-parse HEAD')).stdout.trim();
+  if (!currentCommitHash) {
+    throw new Error('Failed to get current commit hash');
+  }
+
   const {commit} = await inquirer.prompt([
     {
       type: 'input',
       name: 'commit',
       message: 'Which React version (commit) should be used?',
-      default: 'main',
+      default: currentCommitHash,
     },
   ]);
   console.log('');
@@ -215,24 +220,11 @@ async function downloadLatestReactBuild() {
     `"${downloadScriptPath}" --commit=${commit}`
   );
 
-  const output = await logger(
-    downloadPromise,
-    'Downloading React artifacts from CI.',
-    {estimate: 15000}
-  );
-
-  const match = output.match('--build=([0-9]+)');
-  if (match.length === 0) {
-    console.error(chalk.red(`No build ID found in "${output}"`));
-    process.exit(1);
-  }
-
-  const buildID = match[1];
-
-  console.log('');
-  console.log(`Downloaded artifacts for CI build ${chalk.bold(buildID)}.`);
+  await logger(downloadPromise, 'Downloading React artifacts from CI.', {
+    estimate: 15000,
+  });
 
-  return buildID;
+  return currentCommitHash;
 }
 
 function printFinalInstructions() {

filename: scripts/devtools/publish-release.js
patch: @@ -29,16 +29,16 @@ async function main() {
     console.log(chalk.bold.green('  ' + pathToPrint));
   });
 
-  const {archivePath, buildID} = readSavedBuildMetadata();
+  const {archivePath, currentCommitHash} = readSavedBuildMetadata();
 
   await checkNPMPermissions();
 
   await publishToNPM();
 
-  await printFinalInstructions(buildID, archivePath);
+  await printFinalInstructions(currentCommitHash, archivePath);
 }
 
-async function printFinalInstructions(buildID, archivePath) {
+async function printFinalInstructions(currentCommitHash, archivePath) {
   console.log('');
   console.log(
     'You are now ready to publish the extension to Chrome, Edge, and Firefox:'
@@ -50,7 +50,7 @@ async function printFinalInstructions(buildID, archivePath) {
   );
   console.log('');
   console.log('When publishing to Firefox, remember the following:');
-  console.log(`  Build id: ${chalk.bold(buildID)}`);
+  console.log(`  Commit Hash: ${chalk.bold(currentCommitHash)}`);
   console.log(`  Git archive: ${chalk.bold(archivePath)}`);
   console.log('');
   console.log('Also consider syncing this release to Facebook:');

filename: scripts/devtools/utils.js
patch: @@ -101,19 +101,19 @@ function readSavedBuildMetadata() {
     process.exit(1);
   }
 
-  const {archivePath, buildID} = readJsonSync(path);
+  const {archivePath, currentCommitHash} = readJsonSync(path);
 
-  return {archivePath, buildID};
+  return {archivePath, currentCommitHash};
 }
 
-function saveBuildMetadata({archivePath, buildID}) {
+function saveBuildMetadata({archivePath, currentCommitHash}) {
   const path = join(BUILD_METADATA_TEMP_DIRECTORY, 'metadata');
 
   if (!existsSync(BUILD_METADATA_TEMP_DIRECTORY)) {
     mkdirSync(BUILD_METADATA_TEMP_DIRECTORY);
   }
 
-  writeJsonSync(path, {archivePath, buildID}, {spaces: 2});
+  writeJsonSync(path, {archivePath, currentCommitHash}, {spaces: 2});
 }
 
 module.exports = {