-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvoke-binary.js
More file actions
53 lines (43 loc) · 1.42 KB
/
Copy pathinvoke-binary.js
File metadata and controls
53 lines (43 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const process = require('node:process');
const os = require('node:os');
const childProcess = require('node:child_process');
const path = require('node:path');
const PLATFORM = process.platform;
const CPU_ARCH = os.arch();
/**
* Selects the prebuilt action binary for the current GitHub Actions runner.
*
* The template ships Linux binaries because GitHub-hosted JavaScript actions
* execute on the runner where the workflow job is already running.
*
* @returns {'action-amd64' | 'action-arm64'} The binary name under dist/.
* @throws {Error} When the runner platform or CPU architecture is unsupported.
*/
function chooseBinary() {
if (PLATFORM !== 'linux') {
throw new Error('Only linux is supported');
}
if (CPU_ARCH !== 'x64' && CPU_ARCH !== 'arm64') {
throw new Error('Only x64 and arm64 are supported');
}
if (CPU_ARCH === 'x64') {
return 'action-amd64';
}
return 'action-arm64';
}
const binary = chooseBinary();
const mainScript = path.join(__dirname, 'dist', binary);
// Forward stdio so logs, annotations, prompts, and failures behave like native action output.
const spawnSyncReturns = childProcess.spawnSync(mainScript, {
stdio: 'inherit',
});
if (spawnSyncReturns.error) {
throw spawnSyncReturns.error;
}
if (spawnSyncReturns.signal) {
console.error(
`Action binary exited due to signal ${spawnSyncReturns.signal}`,
);
process.exit(1);
}
process.exit(spawnSyncReturns.status ?? 1);