Skip to content

Commit 71774c8

Browse files
committed
Add more error logging to Actions
Looks like we need to explicitly call `core.setFailed` before `process.exit(1)` (aka what we use if anything goes wrong) if we want this to be readable in Actions logs.
1 parent cc39faf commit 71774c8

4 files changed

Lines changed: 64 additions & 56 deletions

File tree

.github/actions/auth/bootstrap.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33

44
import fs from 'node:fs'
55
import * as url from 'node:url'
6-
import { spawn } from 'node:child_process'
6+
import {spawn} from 'node:child_process'
77

8-
function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
8+
import * as core from '@actions/core'
9+
10+
function spawnPromisified(command, args, {quiet = false, ...options} = {}) {
911
return new Promise((resolve, reject) => {
1012
const proc = spawn(command, args, options)
1113
proc.stdout.setEncoding('utf8')
12-
proc.stdout.on('data', (data) => {
14+
proc.stdout.on('data', data => {
1315
if (!quiet) {
1416
console.log(data)
1517
}
1618
})
1719
proc.stderr.setEncoding('utf8')
18-
proc.stderr.on('data', (data) => {
20+
proc.stderr.on('data', data => {
1921
console.error(data)
2022
})
21-
proc.on('close', (code) => {
23+
proc.on('close', code => {
2224
if (code !== 0) {
2325
reject(code)
2426
} else {
@@ -31,31 +33,31 @@ function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
3133
await (async () => {
3234
// If dependencies are not vendored-in, install them at runtime.
3335
try {
34-
await fs.accessSync(
35-
url.fileURLToPath(new URL('./node_modules', import.meta.url)),
36-
fs.constants.R_OK
37-
)
36+
await fs.accessSync(url.fileURLToPath(new URL('./node_modules', import.meta.url)), fs.constants.R_OK)
3837
} catch {
3938
try {
4039
await spawnPromisified('npm', ['ci'], {
4140
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
42-
quiet: true
41+
quiet: true,
4342
})
44-
} catch {
43+
} catch (error) {
44+
core.setFailed(`npm ci failed: ${error}`)
4545
process.exit(1)
4646
}
4747
} finally {
4848
// Compile TypeScript.
4949
try {
5050
await spawnPromisified('npm', ['run', 'build'], {
5151
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
52-
quiet: true
52+
quiet: true,
5353
})
54-
} catch {
54+
} catch (error) {
55+
core.setFailed(`npm run build (TypeScript compilation) failed: ${error}`)
5556
process.exit(1)
5657
}
5758
// Run the main script.
59+
core.info('Running auth Action index.js...')
5860
const action = await import('./dist/index.js')
5961
await action.default()
6062
}
61-
})()
63+
})()

.github/actions/file/bootstrap.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33

44
import fs from 'node:fs'
55
import * as url from 'node:url'
6-
import { spawn } from 'node:child_process'
6+
import {spawn} from 'node:child_process'
77

8-
function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
8+
import * as core from '@actions/core'
9+
10+
function spawnPromisified(command, args, {quiet = false, ...options} = {}) {
911
return new Promise((resolve, reject) => {
1012
const proc = spawn(command, args, options)
1113
proc.stdout.setEncoding('utf8')
12-
proc.stdout.on('data', (data) => {
14+
proc.stdout.on('data', data => {
1315
if (!quiet) {
1416
console.log(data)
1517
}
1618
})
1719
proc.stderr.setEncoding('utf8')
18-
proc.stderr.on('data', (data) => {
20+
proc.stderr.on('data', data => {
1921
console.error(data)
2022
})
21-
proc.on('close', (code) => {
23+
proc.on('close', code => {
2224
if (code !== 0) {
2325
reject(code)
2426
} else {
@@ -31,31 +33,31 @@ function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
3133
await (async () => {
3234
// If dependencies are not vendored-in, install them at runtime.
3335
try {
34-
await fs.accessSync(
35-
url.fileURLToPath(new URL('./node_modules', import.meta.url)),
36-
fs.constants.R_OK
37-
)
36+
await fs.accessSync(url.fileURLToPath(new URL('./node_modules', import.meta.url)), fs.constants.R_OK)
3837
} catch {
3938
try {
4039
await spawnPromisified('npm', ['ci'], {
4140
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
42-
quiet: true
41+
quiet: true,
4342
})
44-
} catch {
43+
} catch (error) {
44+
core.setFailed(`npm ci failed: ${error}`)
4545
process.exit(1)
4646
}
4747
} finally {
4848
// Compile TypeScript.
4949
try {
5050
await spawnPromisified('npm', ['run', 'build'], {
5151
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
52-
quiet: true
52+
quiet: true,
5353
})
54-
} catch {
54+
} catch (error) {
55+
core.setFailed(`npm run build (TypeScript compilation) failed: ${error}`)
5556
process.exit(1)
5657
}
5758
// Run the main script.
59+
core.info('Running file Action index.js...')
5860
const action = await import('./dist/index.js')
5961
await action.default()
6062
}
61-
})()
63+
})()

.github/actions/find/bootstrap.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33

44
import fs from 'node:fs'
55
import * as url from 'node:url'
6-
import { spawn } from 'node:child_process'
6+
import {spawn} from 'node:child_process'
77

8-
function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
8+
import * as core from '@actions/core'
9+
10+
function spawnPromisified(command, args, {quiet = false, ...options} = {}) {
911
return new Promise((resolve, reject) => {
1012
const proc = spawn(command, args, options)
1113
proc.stdout.setEncoding('utf8')
12-
proc.stdout.on('data', (data) => {
14+
proc.stdout.on('data', data => {
1315
if (!quiet) {
1416
console.log(data)
1517
}
1618
})
1719
proc.stderr.setEncoding('utf8')
18-
proc.stderr.on('data', (data) => {
20+
proc.stderr.on('data', data => {
1921
console.error(data)
2022
})
21-
proc.on('close', (code) => {
23+
proc.on('close', code => {
2224
if (code !== 0) {
2325
reject(code)
2426
} else {
@@ -31,31 +33,31 @@ function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
3133
await (async () => {
3234
// If dependencies are not vendored-in, install them at runtime.
3335
try {
34-
await fs.accessSync(
35-
url.fileURLToPath(new URL('./node_modules', import.meta.url)),
36-
fs.constants.R_OK
37-
)
36+
await fs.accessSync(url.fileURLToPath(new URL('./node_modules', import.meta.url)), fs.constants.R_OK)
3837
} catch {
3938
try {
4039
await spawnPromisified('npm', ['ci'], {
4140
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
42-
quiet: true
41+
quiet: true,
4342
})
44-
} catch {
43+
} catch (error) {
44+
console.error(`npm ci failed: ${error}`)
4545
process.exit(1)
4646
}
4747
} finally {
4848
// Compile TypeScript.
4949
try {
5050
await spawnPromisified('npm', ['run', 'build'], {
5151
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
52-
quiet: true
52+
quiet: true,
5353
})
54-
} catch {
54+
} catch (error) {
55+
console.error(`npm run build (TypeScript compilation) failed: ${error}`)
5556
process.exit(1)
5657
}
5758
// Run the main script.
59+
core.info('Running find Action index.js...')
5860
const action = await import('./dist/index.js')
5961
await action.default()
6062
}
61-
})()
63+
})()

.github/actions/fix/bootstrap.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33

44
import fs from 'node:fs'
55
import * as url from 'node:url'
6-
import { spawn } from 'node:child_process'
6+
import {spawn} from 'node:child_process'
77

8-
function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
8+
import * as core from '@actions/core'
9+
10+
function spawnPromisified(command, args, {quiet = false, ...options} = {}) {
911
return new Promise((resolve, reject) => {
1012
const proc = spawn(command, args, options)
1113
proc.stdout.setEncoding('utf8')
12-
proc.stdout.on('data', (data) => {
14+
proc.stdout.on('data', data => {
1315
if (!quiet) {
1416
console.log(data)
1517
}
1618
})
1719
proc.stderr.setEncoding('utf8')
18-
proc.stderr.on('data', (data) => {
20+
proc.stderr.on('data', data => {
1921
console.error(data)
2022
})
21-
proc.on('close', (code) => {
23+
proc.on('close', code => {
2224
if (code !== 0) {
2325
reject(code)
2426
} else {
@@ -31,31 +33,31 @@ function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
3133
await (async () => {
3234
// If dependencies are not vendored-in, install them at runtime.
3335
try {
34-
await fs.accessSync(
35-
url.fileURLToPath(new URL('./node_modules', import.meta.url)),
36-
fs.constants.R_OK
37-
)
36+
await fs.accessSync(url.fileURLToPath(new URL('./node_modules', import.meta.url)), fs.constants.R_OK)
3837
} catch {
3938
try {
4039
await spawnPromisified('npm', ['ci'], {
4140
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
42-
quiet: true
41+
quiet: true,
4342
})
44-
} catch {
43+
} catch (error) {
44+
core.setFailed(`npm ci failed: ${error}`)
4545
process.exit(1)
4646
}
4747
} finally {
4848
// Compile TypeScript.
4949
try {
5050
await spawnPromisified('npm', ['run', 'build'], {
5151
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
52-
quiet: true
52+
quiet: true,
5353
})
54-
} catch {
54+
} catch (error) {
55+
core.setFailed(`npm run build (TypeScript compilation) failed: ${error}`)
5556
process.exit(1)
5657
}
5758
// Run the main script.
59+
core.info('Running fix Action index.js...')
5860
const action = await import('./dist/index.js')
5961
await action.default()
6062
}
61-
})()
63+
})()

0 commit comments

Comments
 (0)