Skip to content

Commit 5bd4031

Browse files
authored
Revert Build Versions from Content Hash to Commit Hash (#29663)
#29236 caused issues for internal syncs at Meta, because we were computing version numbers using file hashes (to eliminate "no-op" internal sync commits). The problem is that since version numbers may not be consistent across synced files (e.g. if some files have not changed in recent commits), the newly introduced version mismatch check fails. There's some more work that needs to be done here to restore the benefits of file-specific hashing, but for now this simply reverts the content hash changes from the following PRs: - #28633 (95319ab) - #28590 (37676ab) - #28582 (cb076b5) - #26734 (5dd90c5) - #26331 (3cad3a5)
1 parent 72644ef commit 5bd4031

File tree

2 files changed

+12
-65
lines changed

2 files changed

+12
-65
lines changed

.github/workflows/commit_artifacts.yml

+3-20
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ jobs:
147147
mkdir -p ${BASE_FOLDER}/react-native-github/Libraries/Renderer/
148148
mkdir -p ${BASE_FOLDER}/RKJSModules/vendor/react/{scheduler,react,react-is,react-test-renderer}/
149149
150-
# Move React Native renderer
150+
# Move React Native renderer
151151
mv build/react-native/implementations/ $BASE_FOLDER/react-native-github/Libraries/Renderer/
152152
mv build/react-native/shims/ $BASE_FOLDER/react-native-github/Libraries/Renderer/
153153
mv build/facebook-react-native/scheduler/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/scheduler/
@@ -161,9 +161,10 @@ jobs:
161161
rm $RENDERER_FOLDER/ReactNativeRenderer-{dev,prod,profiling}.js
162162
163163
ls -R ./compiled
164-
- name: Add REVISION file
164+
- name: Add REVISION files
165165
run: |
166166
echo ${{ github.sha }} >> ./compiled/facebook-www/REVISION
167+
cp ./compiled/facebook-www/REVISION ./compiled/facebook-www/REVISION_TRANSFORMS
167168
echo ${{ github.sha }} >> ./compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION
168169
- uses: actions/upload-artifact@v3
169170
with:
@@ -189,16 +190,7 @@ jobs:
189190
name: compiled
190191
path: compiled/
191192
- run: git status -u
192-
- name: Check if only the REVISION file has changed
193-
id: check_should_commit
194-
run: |
195-
if git status --porcelain | grep -qv '/REVISION$'; then
196-
echo "should_commit=true" >> "$GITHUB_OUTPUT"
197-
else
198-
echo "should_commit=false" >> "$GITHUB_OUTPUT"
199-
fi
200193
- name: Commit changes to branch
201-
if: steps.check_should_commit.outputs.should_commit == 'true'
202194
uses: stefanzweifel/git-auto-commit-action@v4
203195
with:
204196
commit_message: |
@@ -225,16 +217,7 @@ jobs:
225217
name: compiled-rn
226218
path: compiled-rn/
227219
- run: git status -u
228-
- name: Check if only the REVISION file has changed
229-
id: check_should_commit
230-
run: |
231-
if git status --porcelain | grep -qv '/REVISION$'; then
232-
echo "should_commit=true" >> "$GITHUB_OUTPUT"
233-
else
234-
echo "should_commit=false" >> "$GITHUB_OUTPUT"
235-
fi
236220
- name: Commit changes to branch
237-
if: steps.check_should_commit.outputs.should_commit == 'true'
238221
uses: stefanzweifel/git-auto-commit-action@v4
239222
with:
240223
commit_message: |

scripts/rollup/build-all-release-channels.js

+9-45
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/* eslint-disable no-for-of-loops/no-for-of-loops */
44

5-
const crypto = require('node:crypto');
65
const fs = require('fs');
76
const fse = require('fs-extra');
87
const {spawnSync} = require('child_process');
@@ -41,7 +40,10 @@ if (dateString.startsWith("'")) {
4140

4241
// Build the artifacts using a placeholder React version. We'll then do a string
4342
// replace to swap it with the correct version per release channel.
44-
const PLACEHOLDER_REACT_VERSION = ReactVersion + '-PLACEHOLDER';
43+
//
44+
// The placeholder version is the same format that the "next" channel uses
45+
const PLACEHOLDER_REACT_VERSION =
46+
ReactVersion + '-' + canaryChannelLabel + '-' + sha + '-' + dateString;
4547

4648
// TODO: We should inject the React version using a build-time parameter
4749
// instead of overwriting the source files.
@@ -158,7 +160,7 @@ function processStable(buildDir) {
158160
}
159161

160162
if (fs.existsSync(buildDir + '/facebook-www')) {
161-
for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
163+
for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) {
162164
const filePath = buildDir + '/facebook-www/' + fileName;
163165
const stats = fs.statSync(filePath);
164166
if (!stats.isDirectory()) {
@@ -167,28 +169,10 @@ function processStable(buildDir) {
167169
}
168170
updatePlaceholderReactVersionInCompiledArtifacts(
169171
buildDir + '/facebook-www',
170-
ReactVersion + '-www-classic-%FILEHASH%'
172+
ReactVersion + '-www-classic-' + sha + '-' + dateString
171173
);
172174
}
173175

174-
[
175-
buildDir + '/react-native/implementations/',
176-
buildDir + '/facebook-react-native/',
177-
].forEach(reactNativeBuildDir => {
178-
if (fs.existsSync(reactNativeBuildDir)) {
179-
updatePlaceholderReactVersionInCompiledArtifacts(
180-
reactNativeBuildDir,
181-
ReactVersion + '-' + canaryChannelLabel + '-%FILEHASH%'
182-
);
183-
}
184-
});
185-
186-
// Update remaining placeholders with canary channel version
187-
updatePlaceholderReactVersionInCompiledArtifacts(
188-
buildDir,
189-
ReactVersion + '-' + canaryChannelLabel + '-' + sha + '-' + dateString
190-
);
191-
192176
if (fs.existsSync(buildDir + '/sizes')) {
193177
fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-stable');
194178
}
@@ -222,7 +206,7 @@ function processExperimental(buildDir, version) {
222206
}
223207

224208
if (fs.existsSync(buildDir + '/facebook-www')) {
225-
for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
209+
for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) {
226210
const filePath = buildDir + '/facebook-www/' + fileName;
227211
const stats = fs.statSync(filePath);
228212
if (!stats.isDirectory()) {
@@ -231,28 +215,10 @@ function processExperimental(buildDir, version) {
231215
}
232216
updatePlaceholderReactVersionInCompiledArtifacts(
233217
buildDir + '/facebook-www',
234-
ReactVersion + '-www-modern-%FILEHASH%'
218+
ReactVersion + '-www-modern-' + sha + '-' + dateString
235219
);
236220
}
237221

238-
[
239-
buildDir + '/react-native/implementations/',
240-
buildDir + '/facebook-react-native/',
241-
].forEach(reactNativeBuildDir => {
242-
if (fs.existsSync(reactNativeBuildDir)) {
243-
updatePlaceholderReactVersionInCompiledArtifacts(
244-
reactNativeBuildDir,
245-
ReactVersion + '-' + canaryChannelLabel + '-%FILEHASH%'
246-
);
247-
}
248-
});
249-
250-
// Update remaining placeholders with canary channel version
251-
updatePlaceholderReactVersionInCompiledArtifacts(
252-
buildDir,
253-
ReactVersion + '-' + canaryChannelLabel + '-' + sha + '-' + dateString
254-
);
255-
256222
if (fs.existsSync(buildDir + '/sizes')) {
257223
fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-experimental');
258224
}
@@ -362,11 +328,9 @@ function updatePlaceholderReactVersionInCompiledArtifacts(
362328

363329
for (const artifactFilename of artifactFilenames) {
364330
const originalText = fs.readFileSync(artifactFilename, 'utf8');
365-
const fileHash = crypto.createHash('sha1');
366-
fileHash.update(originalText);
367331
const replacedText = originalText.replaceAll(
368332
PLACEHOLDER_REACT_VERSION,
369-
newVersion.replace(/%FILEHASH%/g, fileHash.digest('hex').slice(0, 8))
333+
newVersion
370334
);
371335
fs.writeFileSync(artifactFilename, replacedText);
372336
}

0 commit comments

Comments
 (0)