Skip to content

Commit 066e45c

Browse files
authored
Add more error logging to Actions (#143)
2 parents 3fc822d + 584eedd commit 066e45c

File tree

4 files changed

+60
-56
lines changed

4 files changed

+60
-56
lines changed

.github/actions/auth/bootstrap.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
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+
function spawnPromisified(command, args, {quiet = false, ...options} = {}) {
99
return new Promise((resolve, reject) => {
1010
const proc = spawn(command, args, options)
1111
proc.stdout.setEncoding('utf8')
12-
proc.stdout.on('data', (data) => {
12+
proc.stdout.on('data', data => {
1313
if (!quiet) {
1414
console.log(data)
1515
}
1616
})
1717
proc.stderr.setEncoding('utf8')
18-
proc.stderr.on('data', (data) => {
18+
proc.stderr.on('data', data => {
1919
console.error(data)
2020
})
21-
proc.on('close', (code) => {
21+
proc.on('close', code => {
2222
if (code !== 0) {
2323
reject(code)
2424
} else {
@@ -31,31 +31,32 @@ function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
3131
await (async () => {
3232
// If dependencies are not vendored-in, install them at runtime.
3333
try {
34-
await fs.accessSync(
35-
url.fileURLToPath(new URL('./node_modules', import.meta.url)),
36-
fs.constants.R_OK
37-
)
34+
await fs.accessSync(url.fileURLToPath(new URL('./node_modules', import.meta.url)), fs.constants.R_OK)
3835
} catch {
3936
try {
4037
await spawnPromisified('npm', ['ci'], {
4138
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
42-
quiet: true
39+
quiet: true,
4340
})
44-
} catch {
41+
} catch (error) {
42+
console.error(`npm ci failed: ${error}`)
4543
process.exit(1)
4644
}
4745
} finally {
46+
const core = await import('@actions/core')
4847
// Compile TypeScript.
4948
try {
5049
await spawnPromisified('npm', ['run', 'build'], {
5150
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
52-
quiet: true
51+
quiet: true,
5352
})
54-
} catch {
53+
} catch (error) {
54+
core.setFailed(`npm run build (TypeScript compilation) failed: ${error}`)
5555
process.exit(1)
5656
}
5757
// Run the main script.
58+
core.info('Running auth Action index.js...')
5859
const action = await import('./dist/index.js')
5960
await action.default()
6061
}
61-
})()
62+
})()

.github/actions/file/bootstrap.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
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+
function spawnPromisified(command, args, {quiet = false, ...options} = {}) {
99
return new Promise((resolve, reject) => {
1010
const proc = spawn(command, args, options)
1111
proc.stdout.setEncoding('utf8')
12-
proc.stdout.on('data', (data) => {
12+
proc.stdout.on('data', data => {
1313
if (!quiet) {
1414
console.log(data)
1515
}
1616
})
1717
proc.stderr.setEncoding('utf8')
18-
proc.stderr.on('data', (data) => {
18+
proc.stderr.on('data', data => {
1919
console.error(data)
2020
})
21-
proc.on('close', (code) => {
21+
proc.on('close', code => {
2222
if (code !== 0) {
2323
reject(code)
2424
} else {
@@ -31,31 +31,32 @@ function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
3131
await (async () => {
3232
// If dependencies are not vendored-in, install them at runtime.
3333
try {
34-
await fs.accessSync(
35-
url.fileURLToPath(new URL('./node_modules', import.meta.url)),
36-
fs.constants.R_OK
37-
)
34+
await fs.accessSync(url.fileURLToPath(new URL('./node_modules', import.meta.url)), fs.constants.R_OK)
3835
} catch {
3936
try {
4037
await spawnPromisified('npm', ['ci'], {
4138
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
42-
quiet: true
39+
quiet: true,
4340
})
44-
} catch {
41+
} catch (error) {
42+
console.error(`npm ci failed: ${error}`)
4543
process.exit(1)
4644
}
4745
} finally {
46+
const core = await import('@actions/core')
4847
// Compile TypeScript.
4948
try {
5049
await spawnPromisified('npm', ['run', 'build'], {
5150
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
52-
quiet: true
51+
quiet: true,
5352
})
54-
} catch {
53+
} catch (error) {
54+
core.setFailed(`npm run build (TypeScript compilation) failed: ${error}`)
5555
process.exit(1)
5656
}
5757
// Run the main script.
58+
core.info('Running file Action index.js...')
5859
const action = await import('./dist/index.js')
5960
await action.default()
6061
}
61-
})()
62+
})()

.github/actions/find/bootstrap.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
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+
function spawnPromisified(command, args, {quiet = false, ...options} = {}) {
99
return new Promise((resolve, reject) => {
1010
const proc = spawn(command, args, options)
1111
proc.stdout.setEncoding('utf8')
12-
proc.stdout.on('data', (data) => {
12+
proc.stdout.on('data', data => {
1313
if (!quiet) {
1414
console.log(data)
1515
}
1616
})
1717
proc.stderr.setEncoding('utf8')
18-
proc.stderr.on('data', (data) => {
18+
proc.stderr.on('data', data => {
1919
console.error(data)
2020
})
21-
proc.on('close', (code) => {
21+
proc.on('close', code => {
2222
if (code !== 0) {
2323
reject(code)
2424
} else {
@@ -31,31 +31,32 @@ function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
3131
await (async () => {
3232
// If dependencies are not vendored-in, install them at runtime.
3333
try {
34-
await fs.accessSync(
35-
url.fileURLToPath(new URL('./node_modules', import.meta.url)),
36-
fs.constants.R_OK
37-
)
34+
await fs.accessSync(url.fileURLToPath(new URL('./node_modules', import.meta.url)), fs.constants.R_OK)
3835
} catch {
3936
try {
4037
await spawnPromisified('npm', ['ci'], {
4138
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
42-
quiet: true
39+
quiet: true,
4340
})
44-
} catch {
41+
} catch (error) {
42+
console.error(`npm ci failed: ${error}`)
4543
process.exit(1)
4644
}
4745
} finally {
46+
const core = await import('@actions/core')
4847
// Compile TypeScript.
4948
try {
5049
await spawnPromisified('npm', ['run', 'build'], {
5150
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
52-
quiet: true
51+
quiet: true,
5352
})
54-
} catch {
53+
} catch (error) {
54+
core.setFailed(`npm run build (TypeScript compilation) failed: ${error}`)
5555
process.exit(1)
5656
}
5757
// Run the main script.
58+
core.info('Running find Action index.js...')
5859
const action = await import('./dist/index.js')
5960
await action.default()
6061
}
61-
})()
62+
})()

.github/actions/fix/bootstrap.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
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+
function spawnPromisified(command, args, {quiet = false, ...options} = {}) {
99
return new Promise((resolve, reject) => {
1010
const proc = spawn(command, args, options)
1111
proc.stdout.setEncoding('utf8')
12-
proc.stdout.on('data', (data) => {
12+
proc.stdout.on('data', data => {
1313
if (!quiet) {
1414
console.log(data)
1515
}
1616
})
1717
proc.stderr.setEncoding('utf8')
18-
proc.stderr.on('data', (data) => {
18+
proc.stderr.on('data', data => {
1919
console.error(data)
2020
})
21-
proc.on('close', (code) => {
21+
proc.on('close', code => {
2222
if (code !== 0) {
2323
reject(code)
2424
} else {
@@ -31,31 +31,32 @@ function spawnPromisified(command, args, { quiet = false, ...options } = {}) {
3131
await (async () => {
3232
// If dependencies are not vendored-in, install them at runtime.
3333
try {
34-
await fs.accessSync(
35-
url.fileURLToPath(new URL('./node_modules', import.meta.url)),
36-
fs.constants.R_OK
37-
)
34+
await fs.accessSync(url.fileURLToPath(new URL('./node_modules', import.meta.url)), fs.constants.R_OK)
3835
} catch {
3936
try {
4037
await spawnPromisified('npm', ['ci'], {
4138
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
42-
quiet: true
39+
quiet: true,
4340
})
44-
} catch {
41+
} catch (error) {
42+
console.error(`npm ci failed: ${error}`)
4543
process.exit(1)
4644
}
4745
} finally {
46+
const core = await import('@actions/core')
4847
// Compile TypeScript.
4948
try {
5049
await spawnPromisified('npm', ['run', 'build'], {
5150
cwd: url.fileURLToPath(new URL('.', import.meta.url)),
52-
quiet: true
51+
quiet: true,
5352
})
54-
} catch {
53+
} catch (error) {
54+
core.setFailed(`npm run build (TypeScript compilation) failed: ${error}`)
5555
process.exit(1)
5656
}
5757
// Run the main script.
58+
core.info('Running fix Action index.js...')
5859
const action = await import('./dist/index.js')
5960
await action.default()
6061
}
61-
})()
62+
})()

0 commit comments

Comments
 (0)