@samitouri / QOS-React-2 / commits / 5bd4031226

Revert Build Versions from Content Hash to Commit Hash (#29663)

https://github.com/facebook/react/pull/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: - https://github.com/facebook/react/pull/28633 (95319ab5afd384f5858f7c080573b9736e6b2f9c) - https://github.com/facebook/react/pull/28590 (37676aba76a9b97e1059e6dec39c3f401f44248d) - https://github.com/facebook/react/pull/28582 (cb076b593cec3a92338958f58468cce19cb8f0d9) - https://github.com/facebook/react/pull/26734 (5dd90c562354758942c833b0a46923176e92208e) - https://github.com/facebook/react/pull/26331 (3cad3a54eda7b2d1c670c2d414f33d78a4c3f6af)

Timothy Yung committed May 30, 2024 at 07:26 UTC 5bd403122645ef0f0924ac5466f56e670a8f5b8d
2 files changed +12 -65
.github/workflows/commit_artifacts.yml
+3 -20
@@ -147,7 +147,7 @@ jobs:
147 mkdir -p ${BASE_FOLDER}/react-native-github/Libraries/Renderer/
148 mkdir -p ${BASE_FOLDER}/RKJSModules/vendor/react/{scheduler,react,react-is,react-test-renderer}/
149
150 - # Move React Native renderer
150 + # Move React Native renderer
151 mv build/react-native/implementations/ $BASE_FOLDER/react-native-github/Libraries/Renderer/
152 mv build/react-native/shims/ $BASE_FOLDER/react-native-github/Libraries/Renderer/
153 mv build/facebook-react-native/scheduler/cjs/ $BASE_FOLDER/RKJSModules/vendor/react/scheduler/
@@ -161,9 +161,10 @@ jobs:
161 rm $RENDERER_FOLDER/ReactNativeRenderer-{dev,prod,profiling}.js
162
163 ls -R ./compiled
164 - - name: Add REVISION file
164 + - name: Add REVISION files
165 run: |
166 echo ${{ github.sha }} >> ./compiled/facebook-www/REVISION
167 + cp ./compiled/facebook-www/REVISION ./compiled/facebook-www/REVISION_TRANSFORMS
168 echo ${{ github.sha }} >> ./compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION
169 - uses: actions/upload-artifact@v3
170 with:
@@ -189,16 +190,7 @@ jobs:
190 name: compiled
191 path: compiled/
192 - 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
193 - name: Commit changes to branch
201 - if: steps.check_should_commit.outputs.should_commit == 'true'
194 uses: stefanzweifel/git-auto-commit-action@v4
195 with:
196 commit_message: |
@@ -225,16 +217,7 @@ jobs:
217 name: compiled-rn
218 path: compiled-rn/
219 - 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
220 - name: Commit changes to branch
237 - if: steps.check_should_commit.outputs.should_commit == 'true'
221 uses: stefanzweifel/git-auto-commit-action@v4
222 with:
223 commit_message: |
scripts/rollup/build-all-release-channels.js
+9 -45
@@ -2,7 +2,6 @@
2
3 /* eslint-disable no-for-of-loops/no-for-of-loops */
4
5 -const crypto = require('node:crypto');
5 const fs = require('fs');
6 const fse = require('fs-extra');
7 const {spawnSync} = require('child_process');
@@ -41,7 +40,10 @@ if (dateString.startsWith("'")) {
40
41 // Build the artifacts using a placeholder React version. We'll then do a string
42 // 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;
47
48 // TODO: We should inject the React version using a build-time parameter
49 // instead of overwriting the source files.
@@ -158,7 +160,7 @@ function processStable(buildDir) {
160 }
161
162 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')) {
164 const filePath = buildDir + '/facebook-www/' + fileName;
165 const stats = fs.statSync(filePath);
166 if (!stats.isDirectory()) {
@@ -167,28 +169,10 @@ function processStable(buildDir) {
169 }
170 updatePlaceholderReactVersionInCompiledArtifacts(
171 buildDir + '/facebook-www',
170 - ReactVersion + '-www-classic-%FILEHASH%'
172 + ReactVersion + '-www-classic-' + sha + '-' + dateString
173 );
174 }
175
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 -
176 if (fs.existsSync(buildDir + '/sizes')) {
177 fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-stable');
178 }
@@ -222,7 +206,7 @@ function processExperimental(buildDir, version) {
206 }
207
208 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')) {
210 const filePath = buildDir + '/facebook-www/' + fileName;
211 const stats = fs.statSync(filePath);
212 if (!stats.isDirectory()) {
@@ -231,28 +215,10 @@ function processExperimental(buildDir, version) {
215 }
216 updatePlaceholderReactVersionInCompiledArtifacts(
217 buildDir + '/facebook-www',
234 - ReactVersion + '-www-modern-%FILEHASH%'
218 + ReactVersion + '-www-modern-' + sha + '-' + dateString
219 );
220 }
221
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 -
222 if (fs.existsSync(buildDir + '/sizes')) {
223 fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-experimental');
224 }
@@ -362,11 +328,9 @@ function updatePlaceholderReactVersionInCompiledArtifacts(
328
329 for (const artifactFilename of artifactFilenames) {
330 const originalText = fs.readFileSync(artifactFilename, 'utf8');
365 - const fileHash = crypto.createHash('sha1');
366 - fileHash.update(originalText);
331 const replacedText = originalText.replaceAll(
332 PLACEHOLDER_REACT_VERSION,
369 - newVersion.replace(/%FILEHASH%/g, fileHash.digest('hex').slice(0, 8))
333 + newVersion
334 );
335 fs.writeFileSync(artifactFilename, replacedText);
336 }