52
52
CIRCLECI_TOKEN : ${{secrets.CIRCLECI_TOKEN_DIFFTRAIN}}
53
53
with :
54
54
script : |
55
+ // TODO: Move this to a script file.
55
56
const cp = require('child_process');
56
57
57
58
function sleep(ms) {
@@ -250,14 +251,18 @@ jobs:
250
251
grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "No files found with $CURRENT_VERSION_MODERN"
251
252
grep -rl "$CURRENT_VERSION_MODERN" ./compiled | xargs -r sed -i -e "s/$CURRENT_VERSION_MODERN/$LAST_VERSION_MODERN/g"
252
253
grep -rl "$CURRENT_VERSION_MODERN" ./compiled || echo "Modern version reverted"
253
- - name : Check if only the REVISION file has changed
254
+ - name : Check for changes
254
255
id : check_should_commit
255
256
run : |
256
257
echo "Full git status"
258
+ git add .
257
259
git status
258
260
echo "===================="
259
261
if git status --porcelain | grep -qv '/REVISION'; then
260
262
echo "Changes detected"
263
+ echo "===== Changes ====="
264
+ git --no-pager diff -U0 | grep '^[+-]' | head -n 50
265
+ echo "==================="
261
266
echo "should_commit=true" >> "$GITHUB_OUTPUT"
262
267
else
263
268
echo "No Changes detected"
@@ -322,17 +327,109 @@ jobs:
322
327
grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "No files found with $CURRENT_VERSION"
323
328
grep -rl "$CURRENT_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$CURRENT_VERSION/$LAST_VERSION/g"
324
329
grep -rl "$CURRENT_VERSION" ./compiled-rn || echo "Version reverted"
325
- - name : Check if only the REVISION file has changed
326
- id : check_should_commit
330
+ - name : Check changes before signing
327
331
run : |
328
332
echo "Full git status"
333
+ git add .
329
334
git status
330
335
echo "===================="
331
- echo "Checking for changes"
332
- # Check if there are changes in the files other than REVISION or @generated headers
333
- # We also filter out the file name lines with "---" and "+++".
334
- if git diff -- . ':(exclude)*REVISION' | grep -vE "^(@@|diff|index|\-\-\-|\+\+\+|@generated SignedSource)" | grep "^[+-]" > /dev/null; then
336
+ if git status --porcelain | grep -qv '/REVISION'; then
337
+ echo "Changes detected"
338
+ echo "===== Changes ====="
339
+ git --no-pager diff -U0 --cached | grep '^[+-]' | head -n 50
340
+ echo "==================="
341
+ else
342
+ echo "No Changes detected"
343
+ fi
344
+ - name : Revert signatures
345
+ uses : actions/github-script@v6
346
+ with :
347
+ script : |
348
+ // TODO: Move this to a script file.
349
+ // We currently can't call scripts from the repo because
350
+ // at this point in the workflow, we're on the compiled
351
+ // artifact branch (so the scripts don't exist).
352
+ // We can fix this with a composite action in the main repo.
353
+ // This script is duplicated below.
354
+ const fs = require('fs');
355
+ const crypto = require('crypto');
356
+ const {execSync} = require('child_process');
357
+
358
+ // TODO: when we move this to a script, we can use this from npm.
359
+ // Copy of signedsource since we can't install deps on this branch
360
+ const GENERATED = '@' + 'generated';
361
+ const NEWTOKEN = '<<SignedSource::*O*zOeWoEQle#+L!plEphiEmie@IsG>>';
362
+ const PATTERN = new RegExp(`${GENERATED} (?:SignedSource<<([a-f0-9]{32})>>)`);
363
+
364
+ const TokenNotFoundError = new Error(
365
+ `SignedSource.signFile(...): Cannot sign file without token: ${NEWTOKEN}`
366
+ );
367
+
368
+ function hash(data, encoding) {
369
+ const md5sum = crypto.createHash('md5');
370
+ md5sum.update(data, encoding);
371
+ return md5sum.digest('hex');
372
+ }
373
+
374
+ const SignedSource = {
375
+ getSigningToken() {
376
+ return `${GENERATED} ${NEWTOKEN}`;
377
+ },
378
+ isSigned(data) {
379
+ return PATTERN.exec(data) != null;
380
+ },
381
+ signFile(data) {
382
+ if (!data.includes(NEWTOKEN)) {
383
+ if (SignedSource.isSigned(data)) {
384
+ // Signing a file that was previously signed.
385
+ data = data.replace(PATTERN, SignedSource.getSigningToken());
386
+ } else {
387
+ throw TokenNotFoundError;
388
+ }
389
+ }
390
+ return data.replace(NEWTOKEN, `SignedSource<<${hash(data, 'utf8')}>>`);
391
+ },
392
+ };
393
+
394
+ const directory = './compiled-rn';
395
+ console.log('Signing files in directory:', directory);
396
+ try {
397
+ const result = execSync(`git status --porcelain ${directory}`, {encoding: 'utf8'});
398
+
399
+ // Parse the git status output to get file paths
400
+ const files = result.split('\n').filter(file => file.endsWith('.js'));
401
+
402
+ if (files.length === 0) {
403
+ throw new Error(
404
+ 'git status returned no files to sign. this job should not have run.'
405
+ );
406
+ } else {
407
+ files.forEach(line => {
408
+ const file = line.slice(3).trim();
409
+ if (file) {
410
+ console.log(' Signing file:', file);
411
+ const originalContents = fs.readFileSync(file, 'utf8');
412
+ const signedContents = SignedSource.signFile(originalContents);
413
+ fs.writeFileSync(file, signedContents, 'utf8');
414
+ }
415
+ });
416
+ }
417
+ } catch (e) {
418
+ process.exitCode = 1;
419
+ console.error('Error signing files:', e);
420
+ }
421
+ - name : Check for changes
422
+ id : check_should_commit
423
+ run : |
424
+ echo "Full git status"
425
+ git add .
426
+ git status --porcelain
427
+ echo "===================="
428
+ if git status --porcelain | grep -qv '/REVISION'; then
335
429
echo "Changes detected"
430
+ echo "===== Changes ====="
431
+ git --no-pager diff -U0 --cached | grep '^[+-]' | head -n 50
432
+ echo "==================="
336
433
echo "should_commit=true" >> "$GITHUB_OUTPUT"
337
434
else
338
435
echo "No Changes detected"
@@ -348,10 +445,92 @@ jobs:
348
445
grep -rl "$LAST_VERSION" ./compiled-rn || echo "No files found with $LAST_VERSION"
349
446
grep -rl "$LAST_VERSION" ./compiled-rn | xargs -r sed -i -e "s/$LAST_VERSION/$CURRENT_VERSION/g"
350
447
grep -rl "$LAST_VERSION" ./compiled-rn || echo "Version re-applied"
351
- - name : Will commit these changes
448
+ - name : Add files
352
449
if : steps.check_should_commit.outputs.should_commit == 'true'
353
450
run : |
354
451
echo ":"
452
+ git add .
453
+ - name : Signing files
454
+ if : steps.check_should_commit.outputs.should_commit == 'true'
455
+ uses : actions/github-script@v6
456
+ with :
457
+ script : |
458
+ // TODO: Move this to a script file.
459
+ // We currently can't call scripts from the repo because
460
+ // at this point in the workflow, we're on the compiled
461
+ // artifact branch (so the scripts don't exist).
462
+ // We can fix this with a composite action in the main repo.
463
+ // This script is duplicated above.
464
+ const fs = require('fs');
465
+ const crypto = require('crypto');
466
+ const {execSync} = require('child_process');
467
+
468
+ // TODO: when we move this to a script, we can use this from npm.
469
+ // Copy of signedsource since we can't install deps on this branch.
470
+ const GENERATED = '@' + 'generated';
471
+ const NEWTOKEN = '<<SignedSource::*O*zOeWoEQle#+L!plEphiEmie@IsG>>';
472
+ const PATTERN = new RegExp(`${GENERATED} (?:SignedSource<<([a-f0-9]{32})>>)`);
473
+
474
+ const TokenNotFoundError = new Error(
475
+ `SignedSource.signFile(...): Cannot sign file without token: ${NEWTOKEN}`
476
+ );
477
+
478
+ function hash(data, encoding) {
479
+ const md5sum = crypto.createHash('md5');
480
+ md5sum.update(data, encoding);
481
+ return md5sum.digest('hex');
482
+ }
483
+
484
+ const SignedSource = {
485
+ getSigningToken() {
486
+ return `${GENERATED} ${NEWTOKEN}`;
487
+ },
488
+ isSigned(data) {
489
+ return PATTERN.exec(data) != null;
490
+ },
491
+ signFile(data) {
492
+ if (!data.includes(NEWTOKEN)) {
493
+ if (SignedSource.isSigned(data)) {
494
+ // Signing a file that was previously signed.
495
+ data = data.replace(PATTERN, SignedSource.getSigningToken());
496
+ } else {
497
+ throw TokenNotFoundError;
498
+ }
499
+ }
500
+ return data.replace(NEWTOKEN, `SignedSource<<${hash(data, 'utf8')}>>`);
501
+ },
502
+ };
503
+
504
+ const directory = './compiled-rn';
505
+ console.log('Signing files in directory:', directory);
506
+ try {
507
+ const result = execSync(`git status --porcelain ${directory}`, {encoding: 'utf8'});
508
+
509
+ // Parse the git status output to get file paths
510
+ const files = result.split('\n').filter(file => file.endsWith('.js'));
511
+
512
+ if (files.length === 0) {
513
+ throw new Error(
514
+ 'git status returned no files to sign. this job should not have run.'
515
+ );
516
+ } else {
517
+ files.forEach(line => {
518
+ const file = line.slice(3).trim();
519
+ if (file) {
520
+ console.log(' Signing file:', file);
521
+ const originalContents = fs.readFileSync(file, 'utf8');
522
+ const signedContents = SignedSource.signFile(originalContents);
523
+ fs.writeFileSync(file, signedContents, 'utf8');
524
+ }
525
+ });
526
+ }
527
+ } catch (e) {
528
+ process.exitCode = 1;
529
+ console.error('Error signing files:', e);
530
+ }
531
+ - name : Will commit these changes
532
+ if : steps.check_should_commit.outputs.should_commit == 'true'
533
+ run : |
355
534
git status -u
356
535
- name : Commit changes to branch
357
536
if : steps.check_should_commit.outputs.should_commit == 'true'
0 commit comments