Skip to content

Commit f87d264

Browse files
Saadnajmiclaude
andcommitted
refactor: replace inline node -e scripts with CLI entry point
Add a CLI interface to macosVersionResolver.js with two commands: - download-hermes: downloads upstream tarball, writes outputs to $GITHUB_OUTPUT - resolve-commit: resolves Hermes commit at merge base, writes to $GITHUB_OUTPUT This replaces the multi-step node -e / temp file / shell JSON parsing pattern in the workflow with clean one-liner script invocations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e6d8f81 commit f87d264

2 files changed

Lines changed: 45 additions & 22 deletions

File tree

.github/workflows/microsoft-resolve-hermes.yml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,12 @@ jobs:
4040
- name: Install npm dependencies
4141
run: yarn install
4242

43-
# Step 1: Try to download a prebuilt Hermes tarball from upstream Maven/Sonatype
43+
# Step 1: Try to download a prebuilt Hermes tarball from upstream Maven/Sonatype.
44+
# Writes tarball= and version= to $GITHUB_OUTPUT if successful.
4445
- name: Download upstream Hermes tarball
4546
id: download
4647
working-directory: packages/react-native
47-
run: |
48-
node -e "
49-
const {downloadUpstreamHermesTarball} = require('./scripts/ios-prebuild/macosVersionResolver');
50-
downloadUpstreamHermesTarball('Debug').then(r => {
51-
require('fs').writeFileSync('/tmp/hermes-download-result.json', JSON.stringify(r));
52-
});
53-
"
54-
RESULT=$(cat /tmp/hermes-download-result.json)
55-
if [ "$RESULT" != "null" ]; then
56-
TARBALL=$(node -e "console.log(JSON.parse(process.argv[1]).tarballPath)" "$RESULT")
57-
VERSION=$(node -e "console.log(JSON.parse(process.argv[1]).version)" "$RESULT")
58-
echo "tarball=$TARBALL" >> "$GITHUB_OUTPUT"
59-
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
60-
echo "Downloaded upstream Hermes tarball for version $VERSION"
61-
else
62-
echo "No upstream tarball available"
63-
fi
48+
run: node scripts/ios-prebuild/macosVersionResolver.js download-hermes Debug
6449

6550
# Step 2: If tarball found, recompose the xcframework to include the macOS slice.
6651
# Upstream tarballs contain a universal xcframework (iOS, simulator, catalyst,
@@ -134,10 +119,7 @@ jobs:
134119
if: steps.recompose.outputs.recomposed != 'true'
135120
id: resolve
136121
working-directory: packages/react-native
137-
run: |
138-
COMMIT=$(node -e "const {hermesCommitAtMergeBase} = require('./scripts/ios-prebuild/macosVersionResolver'); console.log(hermesCommitAtMergeBase().commit);" 2>&1 | grep -E '^[0-9a-f]{40}$')
139-
echo "hermes-commit=$COMMIT" >> "$GITHUB_OUTPUT"
140-
echo "Resolved Hermes commit: $COMMIT"
122+
run: node scripts/ios-prebuild/macosVersionResolver.js resolve-commit
141123

142124
- name: Restore Hermes cache
143125
if: steps.recompose.outputs.recomposed != 'true'

packages/react-native/scripts/ios-prebuild/macosVersionResolver.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,47 @@ function abort(message /*: string */) {
290290
throw new Error(message);
291291
}
292292

293+
/**
294+
* Appends a key=value pair to the GitHub Actions output file ($GITHUB_OUTPUT).
295+
* No-op if $GITHUB_OUTPUT is not set (e.g. running locally).
296+
*/
297+
function setActionOutput(key /*: string */, value /*: string */) {
298+
const outputFile = process.env.GITHUB_OUTPUT;
299+
if (outputFile) {
300+
fs.appendFileSync(outputFile, `${key}=${value}\n`);
301+
}
302+
}
303+
304+
// CLI entry point: `node macosVersionResolver.js download-hermes [buildType]`
305+
// Writes tarball/version to $GITHUB_OUTPUT for use in GitHub Actions workflows.
306+
if (require.main === module) {
307+
const [command, ...args] = process.argv.slice(2);
308+
309+
if (command === 'download-hermes') {
310+
const buildType = args[0] || 'Debug';
311+
downloadUpstreamHermesTarball(buildType).then(result => {
312+
if (result != null) {
313+
setActionOutput('tarball', result.tarballPath);
314+
setActionOutput('version', result.version);
315+
macosLog(
316+
`Downloaded upstream Hermes tarball for version ${result.version}`,
317+
);
318+
} else {
319+
macosLog('No upstream tarball available');
320+
}
321+
});
322+
} else if (command === 'resolve-commit') {
323+
const {commit} = hermesCommitAtMergeBase();
324+
setActionOutput('hermes-commit', commit);
325+
macosLog(`Resolved Hermes commit: ${commit}`);
326+
} else {
327+
console.error(
328+
`Unknown command: ${command ?? '(none)'}. Available: download-hermes, resolve-commit`,
329+
);
330+
process.exit(1);
331+
}
332+
}
333+
293334
module.exports = {
294335
findMatchingHermesVersion,
295336
hermesCommitAtMergeBase,

0 commit comments

Comments
 (0)