Skip to content

Commit a7ef01a

Browse files
hoxyqRuslan Lesiutin
andauthored
[DevTools] Use deterministic extension commit hashes (react#37305)
## Summary `git show --format=%h` is not stable: abbreviation length depends on `core.abbrev` and how unique the prefix is in that clone. Two rebuilds of the same commit can therefore embed different strings in `DEVTOOLS_VERSION` and the extension manifest. Always take the full hash (`%H`) and slice it to 10 characters so the value is the same everywhere. This also removes the `build/COMMIT_SHA` fallback used when Mozilla rebuilds from a git archive (no `.git`). That path used a different length (7) and a different source, so it could not match a git checkout of the same commit. Firefox source review should rebuild from a checkout of the commit in react#37307, not from the tarball alone. Stack: this PR → react#37306react#37307. ## How did you test this change? Build-script only. `getGitCommit()` now returns `HEAD` sliced to 10 chars, independent of `core.abbrev`. Co-authored-by: Ruslan Lesiutin <hoxy@meta.com>
1 parent 084f5f2 commit a7ef01a

1 file changed

Lines changed: 10 additions & 28 deletions

File tree

  • packages/react-devtools-extensions

packages/react-devtools-extensions/utils.js

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

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

1212
const GITHUB_URL = 'https://github.com/facebook/react';
13+
const GIT_COMMIT_HASH_LENGTH = 10;
14+
15+
function shortenCommitHash(commitHash) {
16+
return commitHash.trim().slice(0, GIT_COMMIT_HASH_LENGTH);
17+
}
1318

1419
function getGitCommit() {
15-
try {
16-
return execSync('git show -s --no-show-signature --format=%h')
17-
.toString()
18-
.trim();
19-
} catch (error) {
20-
// Mozilla runs this command from a git archive.
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-
}
41-
}
20+
const commitHash = execSync(
21+
'git show -s --no-show-signature --format=%H',
22+
).toString();
23+
return shortenCommitHash(commitHash);
4224
}
4325

4426
function getVersionString(packageVersion = null) {

0 commit comments

Comments
 (0)