-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbootstrap.js
More file actions
62 lines (59 loc) · 1.64 KB
/
bootstrap.js
File metadata and controls
62 lines (59 loc) · 1.64 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
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
//@ts-check
import fs from 'node:fs'
import * as url from 'node:url'
import {spawn} from 'node:child_process'
function spawnPromisified(command, args, {quiet = false, ...options} = {}) {
return new Promise((resolve, reject) => {
const proc = spawn(command, args, options)
proc.stdout.setEncoding('utf8')
proc.stdout.on('data', data => {
if (!quiet) {
console.log(data)
}
})
proc.stderr.setEncoding('utf8')
proc.stderr.on('data', data => {
console.error(data)
})
proc.on('close', code => {
if (code !== 0) {
reject(code)
} else {
resolve(code)
}
})
})
}
await (async () => {
// If dependencies are not vendored-in, install them at runtime.
try {
await fs.accessSync(url.fileURLToPath(new URL('./node_modules', import.meta.url)), fs.constants.R_OK)
} catch {
try {
await spawnPromisified('npm', ['ci'], {
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
quiet: true,
})
} catch (error) {
console.error(`npm ci failed: ${error}`)
process.exit(1)
}
} finally {
const core = await import('@actions/core')
// Compile TypeScript.
try {
await spawnPromisified('npm', ['run', 'build'], {
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
quiet: true,
})
} catch (error) {
core.setFailed(`npm run build (TypeScript compilation) failed: ${error}`)
process.exit(1)
}
// Run the main script.
core.info('Running auth Action index.js...')
const action = await import('./dist/index.js')
await action.default()
}
})()