Skip to content

Commit aaad0ea

Browse files
authored
[DevTools] chore: read from build/COMMIT_SHA fle as fallback for commit hash (#34915)
This eliminates the gap in a reproducer for the React DevTools browser extension from the source code that we submit to Firefox extension stores. We use the commit hash as part of the Backend version, here: https://github.com/facebook/react/blob/2cfb221937eac48209d01d5dda5664de473b1953/packages/react-devtools-extensions/utils.js#L26-L38 The problem is that we archive the source code for Mozilla extension store reviews and there is no git. But since we still download the React sources from the CI, we could reuse the hash from `build/COMMIT_HASH` file.
1 parent 02c80f0 commit aaad0ea

File tree

1 file changed

+21
-3
lines changed
  • packages/react-devtools-extensions

1 file changed

+21
-3
lines changed

packages/react-devtools-extensions/utils.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
const {execSync} = require('child_process');
9-
const {readFileSync} = require('fs');
9+
const {existsSync, readFileSync} = require('fs');
1010
const {resolve} = require('path');
1111

1212
const GITHUB_URL = 'https://github.com/facebook/react';
@@ -18,8 +18,26 @@ function getGitCommit() {
1818
.trim();
1919
} catch (error) {
2020
// Mozilla runs this command from a git archive.
21-
// In that context, there is no Git revision.
22-
return null;
21+
// In that context, there is no Git context.
22+
// Using the commit hash specified to download-experimental-build.js script as a fallback.
23+
24+
// Try to read from build/COMMIT_SHA file
25+
const commitShaPath = resolve(__dirname, '..', '..', 'build', 'COMMIT_SHA');
26+
if (!existsSync(commitShaPath)) {
27+
throw new Error(
28+
'Could not find build/COMMIT_SHA file. Did you run scripts/release/download-experimental-build.js script?',
29+
);
30+
}
31+
32+
try {
33+
const commitHash = readFileSync(commitShaPath, 'utf8').trim();
34+
// Return short hash (first 7 characters) to match abbreviated commit hash format
35+
return commitHash.slice(0, 7);
36+
} catch (readError) {
37+
throw new Error(
38+
`Failed to read build/COMMIT_SHA file: ${readError.message}`,
39+
);
40+
}
2341
}
2442
}
2543

0 commit comments

Comments
 (0)