Skip to content

Commit ffaf236

Browse files
committed
Fix xplat sync
1 parent a0e99f7 commit ffaf236

File tree

1 file changed

+5
-80
lines changed

1 file changed

+5
-80
lines changed

.github/workflows/commit_artifacts.yml

Lines changed: 5 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -341,94 +341,19 @@ jobs:
341341
else
342342
echo "No Changes detected"
343343
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-
}
421344
- name: Check for changes
422345
id: check_should_commit
423346
run: |
424347
echo "Full git status"
425348
git add .
426-
git status --porcelain
427349
echo "===================="
428-
if git status --porcelain | grep -qv '/REVISION'; then
350+
# Ignore REVISION or lines removing @generated headers.
351+
if git diff -- . ':(exclude)*REVISION' | grep -vE "^(@@|diff|index|\-\-\-|\+\+\+|\- \* @generated SignedSource)" | grep "^[+-]" > /dev/null; then
429352
echo "Changes detected"
430353
echo "===== Changes ====="
431-
git --no-pager diff -U0 --cached | grep '^[+-]' | head -n 50
354+
git --no-pager diff -- . ':(exclude)*REVISION' | grep -vE "^(@@|diff|index|\-\-\-|\+\+\+|\- \* @generated SignedSource)" | grep "^[+-]"
355+
echo "=== All Changes ==="
356+
git --no-pager diff -U0 | grep '^[+-]' | head -n 50
432357
echo "==================="
433358
echo "should_commit=true" >> "$GITHUB_OUTPUT"
434359
else

0 commit comments

Comments
 (0)