@samitouri / QOS-React-2 / commits / 3cad3a54ed

Use content hash for facebook-www builds (#26331)

Currently, any commit to React causes an internal sync since the Git commit hash is part of the build. This creates a lot more sync commits and noise than necessary, see: https://github.com/facebook/react/commits/builds/facebook-www This PR changes the version string to be a hash of the target build files instead. This way we get a new version with any change that actually impacts the generated files and still have a matching version across the files.

Jan Kassens committed Mar 6, 2023 at 17:13 UTC 3cad3a54eda7b2d1c670c2d414f33d78a4c3f6af
2 files changed +32 -10
.github/workflows/commit_artifacts.yml
+10 -2
@@ -123,10 +123,9 @@ jobs:
123 ./compiled/babel-plugin-react-refresh/index.js
124
125 ls -R ./compiled
126 - - name: Add REVISION files
126 + - name: Add REVISION file
127 run: |
128 echo ${{ github.sha }} >> ./compiled/facebook-www/REVISION
129 - cp ./compiled/facebook-www/REVISION ./compiled/facebook-www/REVISION_TRANSFORMS
129 - uses: actions/upload-artifact@v3
130 with:
131 name: compiled
@@ -146,7 +145,16 @@ jobs:
145 name: compiled
146 path: compiled/
147 - run: git status -u
148 + - name: Check if only the REVISION file has changed
149 + id: check_should_commit
150 + run: |
151 + if git status --porcelain | grep -qv '/REVISION$'; then
152 + echo "should_commit=true" >> "$GITHUB_OUTPUT"
153 + else
154 + echo "should_commit=false" >> "$GITHUB_OUTPUT"
155 + fi
156 - name: Commit changes to branch
157 + if: steps.check_should_commit.outputs.should_commit == 'true'
158 uses: stefanzweifel/git-auto-commit-action@v4
159 with:
160 commit_message: |
scripts/rollup/build-all-release-channels.js
+22 -8
@@ -2,6 +2,7 @@
2
3 /* eslint-disable no-for-of-loops/no-for-of-loops */
4
5 +const crypto = require('node:crypto');
6 const fs = require('fs');
7 const fse = require('fs-extra');
8 const {spawnSync} = require('child_process');
@@ -40,10 +41,7 @@ if (dateString.startsWith("'")) {
41
42 // Build the artifacts using a placeholder React version. We'll then do a string
43 // replace to swap it with the correct version per release channel.
43 -//
44 -// The placeholder version is the same format that the "next" channel uses
45 -const PLACEHOLDER_REACT_VERSION =
46 - ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString;
44 +const PLACEHOLDER_REACT_VERSION = ReactVersion + '-PLACEHOLDER';
45
46 // TODO: We should inject the React version using a build-time parameter
47 // instead of overwriting the source files.
@@ -164,19 +162,27 @@ function processStable(buildDir) {
162 }
163
164 if (fs.existsSync(buildDir + '/facebook-www')) {
167 - for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) {
165 + const hash = crypto.createHash('sha1');
166 + for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
167 const filePath = buildDir + '/facebook-www/' + fileName;
168 const stats = fs.statSync(filePath);
169 if (!stats.isDirectory()) {
170 + hash.update(fs.readFileSync(filePath));
171 fs.renameSync(filePath, filePath.replace('.js', '.classic.js'));
172 }
173 }
174 updatePlaceholderReactVersionInCompiledArtifacts(
175 buildDir + '/facebook-www',
176 - ReactVersion + '-www-classic-' + sha + '-' + dateString
176 + ReactVersion + '-www-classic-' + hash.digest('hex').substr(0, 8)
177 );
178 }
179
180 + // Update remaining placeholders with next channel version
181 + updatePlaceholderReactVersionInCompiledArtifacts(
182 + buildDir,
183 + ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString
184 + );
185 +
186 if (fs.existsSync(buildDir + '/sizes')) {
187 fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-stable');
188 }
@@ -210,19 +216,27 @@ function processExperimental(buildDir, version) {
216 }
217
218 if (fs.existsSync(buildDir + '/facebook-www')) {
213 - for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) {
219 + const hash = crypto.createHash('sha1');
220 + for (const fileName of fs.readdirSync(buildDir + '/facebook-www').sort()) {
221 const filePath = buildDir + '/facebook-www/' + fileName;
222 const stats = fs.statSync(filePath);
223 if (!stats.isDirectory()) {
224 + hash.update(fs.readFileSync(filePath));
225 fs.renameSync(filePath, filePath.replace('.js', '.modern.js'));
226 }
227 }
228 updatePlaceholderReactVersionInCompiledArtifacts(
229 buildDir + '/facebook-www',
222 - ReactVersion + '-www-modern-' + sha + '-' + dateString
230 + ReactVersion + '-www-modern-' + hash.digest('hex').substr(0, 8)
231 );
232 }
233
234 + // Update remaining placeholders with next channel version
235 + updatePlaceholderReactVersionInCompiledArtifacts(
236 + buildDir,
237 + ReactVersion + '-' + nextChannelLabel + '-' + sha + '-' + dateString
238 + );
239 +
240 if (fs.existsSync(buildDir + '/sizes')) {
241 fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-experimental');
242 }