@@ -64,12 +64,13 @@ jobs:
6464 path : " **/node_modules"
6565 key : ${{ runner.arch }}-${{ runner.os }}-modules-${{ hashFiles('yarn.lock', 'scripts/release/yarn.lock') }}
6666 - run : yarn install --frozen-lockfile
67+ name : yarn install (react)
6768 - run : yarn install --frozen-lockfile
69+ name : yarn install (scripts/release)
6870 working-directory : scripts/release
6971 - name : Download artifacts for base revision
7072 run : |
71- git fetch origin main
72- GH_TOKEN=${{ github.token }} scripts/release/download-experimental-build-ghaction.js --commit=$(git rev-parse origin/main)
73+ GH_TOKEN=${{ github.token }} scripts/release/download-experimental-build-ghaction.js --commit=${{ github.event.workflow_run.head_sha }}
7374 - name : Display structure of build
7475 run : ls -R build
7576 - name : Strip @license from eslint plugin and react-refresh
@@ -126,9 +127,9 @@ jobs:
126127 ls -R ./compiled-rn
127128 - name : Add REVISION files
128129 run : |
129- echo ${{ github.sha }} >> ./compiled/facebook-www/REVISION
130+ echo ${{ github.event.workflow_run.head_sha }} >> ./compiled/facebook-www/REVISION
130131 cp ./compiled/facebook-www/REVISION ./compiled/facebook-www/REVISION_TRANSFORMS
131- echo ${{ github.sha }} >> ./compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION
132+ echo ${{ github.event.workflow_run.head_sha }} >> ./compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/REVISION
132133 - name : " Get current version string"
133134 id : get_current_version
134135 run : |
@@ -149,3 +150,244 @@ jobs:
149150 with :
150151 name : compiled-rn
151152 path : compiled-rn/
153+
154+ commit_www_artifacts :
155+ needs : download_artifacts
156+ if : ${{ (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.www_branch_count == '0') || github.ref == 'refs/heads/meta-www' }}
157+ runs-on : ubuntu-latest
158+ steps :
159+ - uses : actions/checkout@v4
160+ with :
161+ ref : builds/facebook-www
162+ - name : Ensure clean directory
163+ run : rm -rf compiled
164+ - uses : actions/download-artifact@v3
165+ with :
166+ name : compiled
167+ path : compiled/
168+ - name : Revert version changes
169+ if : needs.download_artifacts.outputs.last_version_classic != '' && needs.download_artifacts.outputs.last_version_modern != ''
170+ env :
171+ CURRENT_VERSION_CLASSIC : ${{ needs.download_artifacts.outputs.current_version_classic }}
172+ CURRENT_VERSION_MODERN : ${{ needs.download_artifacts.outputs.current_version_modern }}
173+ LAST_VERSION_CLASSIC : ${{ needs.download_artifacts.outputs.last_version_classic }}
174+ LAST_VERSION_MODERN : ${{ needs.download_artifacts.outputs.last_version_modern }}
175+ run : |
176+ echo "Reverting $CURRENT_VERSION_CLASSIC to $LAST_VERSION_CLASSIC"
177+ grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled || echo "No files found with $CURRENT_VERSION_CLASSIC"
178+ grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled | xargs -r sed -i -e "s/$CURRENT_VERSION_CLASSIC/$LAST_VERSION_CLASSIC/g"
179+ grep -rl "$CURRENT_VERSION_CLASSIC" ./compiled || echo "Classic version reverted"
180+ echo "===================="
181+ echo "Reverting $CURRENT_VERSION_MODERN to $LAST_VERSION_MODERN"
182+ grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "No files found with $CURRENT_VERSION_MODERN"
183+ grep -rl "$CURRENT_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$CURRENT_VERSION_MODERN/$LAST_VERSION_MODERN/g"
184+ grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "Modern version reverted"
185+ - name : Check for changes
186+ id : check_should_commit
187+ run : |
188+ echo "Full git status"
189+ git add .
190+ git status
191+ echo "===================="
192+ if git status --porcelain | grep -qv '/REVISION'; then
193+ echo "Changes detected"
194+ echo "===== Changes ====="
195+ git --no-pager diff -U0 | grep '^[+-]' | head -n 50
196+ echo "==================="
197+ echo "should_commit=true" >> "$GITHUB_OUTPUT"
198+ else
199+ echo "No Changes detected"
200+ echo "should_commit=false" >> "$GITHUB_OUTPUT"
201+ fi
202+ - name : Re-apply version changes
203+ if : steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_classic != '' && needs.download_artifacts.outputs.last_version_modern != ''
204+ env :
205+ CURRENT_VERSION_CLASSIC : ${{ needs.download_artifacts.outputs.current_version_classic }}
206+ CURRENT_VERSION_MODERN : ${{ needs.download_artifacts.outputs.current_version_modern }}
207+ LAST_VERSION_CLASSIC : ${{ needs.download_artifacts.outputs.last_version_classic }}
208+ LAST_VERSION_MODERN : ${{ needs.download_artifacts.outputs.last_version_modern }}
209+ run : |
210+ echo "Re-applying $LAST_VERSION_CLASSIC to $CURRENT_VERSION_CLASSIC"
211+ grep -rl "$LAST_VERSION_CLASSIC" ./compiled || echo "No files found with $LAST_VERSION_CLASSIC"
212+ grep -rl "$LAST_VERSION_CLASSIC" ./compiled | xargs -r sed -i -e "s/$LAST_VERSION_CLASSIC/$CURRENT_VERSION_CLASSIC/g"
213+ grep -rl "$LAST_VERSION_CLASSIC" ./compiled || echo "Classic version re-applied"
214+ echo "===================="
215+ echo "Re-applying $LAST_VERSION_MODERN to $CURRENT_VERSION_MODERN"
216+ grep -rl "$LAST_VERSION_MODERN" ./compiled || echo "No files found with $LAST_VERSION_MODERN"
217+ grep -rl "$LAST_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$LAST_VERSION_MODERN/$CURRENT_VERSION_MODERN/g"
218+ grep -rl "$LAST_VERSION_MODERN" ./compiled || echo "Classic version re-applied"
219+ - name : Will commit these changes
220+ if : steps.check_should_commit.outputs.should_commit == 'true'
221+ run : |
222+ echo ":"
223+ git status -u
224+ - name : Commit changes to branch
225+ if : steps.check_should_commit.outputs.should_commit == 'true'
226+ uses : stefanzweifel/git-auto-commit-action@v4
227+ with :
228+ commit_message : |
229+ ${{ github.event.workflow_run.head_commit.message }}
230+
231+ DiffTrain build for [${{ github.event.workflow_run.head_sha }}](https://github.com/facebook/react/commit/${{ github.event.workflow_run.head_sha }})
232+ branch : builds/facebook-www
233+ commit_user_name : ${{ github.event.workflow_run.actor.name }}
234+ commit_user_email : ${{ github.event.workflow_run.actor.email || format('{0}@users.noreply.github.com', github.event.workflow_run.actor.name) }}
235+ create_branch : true
236+
237+ commit_fbsource_artifacts :
238+ needs : download_artifacts
239+ if : ${{ (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.fbsource_branch_count == '0') || github.ref == 'refs/heads/meta-fbsource' }}
240+ runs-on : ubuntu-latest
241+ steps :
242+ - uses : actions/checkout@v4
243+ with :
244+ ref : builds/facebook-fbsource
245+ - name : Ensure clean directory
246+ run : rm -rf compiled-rn
247+ - uses : actions/download-artifact@v3
248+ with :
249+ name : compiled-rn
250+ path : compiled-rn/
251+ - name : Revert version changes
252+ if : needs.download_artifacts.outputs.last_version_rn != ''
253+ env :
254+ CURRENT_VERSION : ${{ needs.download_artifacts.outputs.current_version_rn }}
255+ LAST_VERSION : ${{ needs.download_artifacts.outputs.last_version_rn }}
256+ run : |
257+ echo "Reverting $CURRENT_VERSION to $LAST_VERSION"
258+ grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "No files found with $CURRENT_VERSION"
259+ grep -rl "$CURRENT_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$CURRENT_VERSION/$LAST_VERSION/g"
260+ grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "Version reverted"
261+ - name : Check for changes
262+ id : check_should_commit
263+ run : |
264+ echo "Full git status"
265+ git add .
266+ git --no-pager diff -U0 --cached | grep '^[+-]' | head -n 100
267+ echo "===================="
268+ # Ignore REVISION or lines removing @generated headers.
269+ if git diff --cached ':(exclude)*REVISION' | grep -vE "^(@@|diff|index|\-\-\-|\+\+\+|\- \* @generated SignedSource)" | grep "^[+-]" > /dev/null; then
270+ echo "Changes detected"
271+ echo "===== Changes ====="
272+ git --no-pager diff --cached ':(exclude)*REVISION' | grep -vE "^(@@|diff|index|\-\-\-|\+\+\+|\- \* @generated SignedSource)" | grep "^[+-]" | head -n 50
273+ echo "==================="
274+ echo "should_commit=true" >> "$GITHUB_OUTPUT"
275+ else
276+ echo "No Changes detected"
277+ echo "should_commit=false" >> "$GITHUB_OUTPUT"
278+ fi
279+ - name : Re-apply version changes
280+ if : steps.check_should_commit.outputs.should_commit == 'true' && needs.download_artifacts.outputs.last_version_rn != ''
281+ env :
282+ CURRENT_VERSION : ${{ needs.download_artifacts.outputs.current_version_rn }}
283+ LAST_VERSION : ${{ needs.download_artifacts.outputs.last_version_rn }}
284+ run : |
285+ echo "Re-applying $LAST_VERSION to $CURRENT_VERSION"
286+ grep -rl "$LAST_VERSION" ./compiled-rn || echo "No files found with $LAST_VERSION"
287+ grep -rl "$LAST_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$LAST_VERSION/$CURRENT_VERSION/g"
288+ grep -rl "$LAST_VERSION" ./compiled-rn || echo "Version re-applied"
289+ - name : Add files for signing
290+ if : steps.check_should_commit.outputs.should_commit == 'true'
291+ run : |
292+ echo ":"
293+ git add .
294+ - name : Signing files
295+ if : steps.check_should_commit.outputs.should_commit == 'true'
296+ uses : actions/github-script@v6
297+ with :
298+ script : |
299+ // TODO: Move this to a script file.
300+ // We currently can't call scripts from the repo because
301+ // at this point in the workflow, we're on the compiled
302+ // artifact branch (so the scripts don't exist).
303+ // We can fix this with a composite action in the main repo.
304+ // This script is duplicated above.
305+ const fs = require('fs');
306+ const crypto = require('crypto');
307+ const {execSync} = require('child_process');
308+
309+ // TODO: when we move this to a script, we can use this from npm.
310+ // Copy of signedsource since we can't install deps on this branch.
311+ const GENERATED = '@' + 'generated';
312+ const NEWTOKEN = '<<SignedSource::*O*zOeWoEQle#+L!plEphiEmie@IsG>>';
313+ const PATTERN = new RegExp(`${GENERATED} (?:SignedSource<<([a-f0-9]{32})>>)`);
314+
315+ const TokenNotFoundError = new Error(
316+ `SignedSource.signFile(...): Cannot sign file without token: ${NEWTOKEN}`
317+ );
318+
319+ function hash(data, encoding) {
320+ const md5sum = crypto.createHash('md5');
321+ md5sum.update(data, encoding);
322+ return md5sum.digest('hex');
323+ }
324+
325+ const SignedSource = {
326+ getSigningToken() {
327+ return `${GENERATED} ${NEWTOKEN}`;
328+ },
329+ isSigned(data) {
330+ return PATTERN.exec(data) != null;
331+ },
332+ signFile(data) {
333+ if (!data.includes(NEWTOKEN)) {
334+ if (SignedSource.isSigned(data)) {
335+ // Signing a file that was previously signed.
336+ data = data.replace(PATTERN, SignedSource.getSigningToken());
337+ } else {
338+ throw TokenNotFoundError;
339+ }
340+ }
341+ return data.replace(NEWTOKEN, `SignedSource<<${hash(data, 'utf8')}>>`);
342+ },
343+ };
344+
345+ const directory = './compiled-rn';
346+ console.log('Signing files in directory:', directory);
347+ try {
348+ const result = execSync(`git status --porcelain ${directory}`, {encoding: 'utf8'});
349+
350+ // Parse the git status output to get file paths
351+ const files = result.split('\n').filter(file => file.endsWith('.js'));
352+
353+ if (files.length === 0) {
354+ throw new Error(
355+ 'git status returned no files to sign. this job should not have run.'
356+ );
357+ } else {
358+ files.forEach(line => {
359+ const file = line.slice(3).trim();
360+ if (file) {
361+ console.log(' Signing file:', file);
362+ const originalContents = fs.readFileSync(file, 'utf8');
363+ const signedContents = SignedSource.signFile(
364+ originalContents
365+ // Need to add the header in, since it's not inserted at build time.
366+ .replace(' */\n', ` * ${SignedSource.getSigningToken()}\n */\n`)
367+ );
368+
369+ fs.writeFileSync(file, signedContents, 'utf8');
370+ }
371+ });
372+ }
373+ } catch (e) {
374+ process.exitCode = 1;
375+ console.error('Error signing files:', e);
376+ }
377+ - name : Will commit these changes
378+ if : steps.check_should_commit.outputs.should_commit == 'true'
379+ run : |
380+ git add .
381+ git status
382+ - name : Commit changes to branch
383+ if : steps.check_should_commit.outputs.should_commit == 'true'
384+ uses : stefanzweifel/git-auto-commit-action@v4
385+ with :
386+ commit_message : |
387+ ${{ github.event.workflow_run.head_commit.message }}
388+
389+ DiffTrain build for commit https://github.com/facebook/react/commit/${{ github.event.workflow_run.head_sha }}.
390+ branch : builds/facebook-fbsource
391+ commit_user_name : ${{ github.event.workflow_run.actor.name }}
392+ commit_user_email : ${{ github.event.workflow_run.actor.email || format('{0}@users.noreply.github.com', github.event.workflow_run.actor.name) }}
393+ create_branch : true
0 commit comments