Skip to content

Commit 00ca5ee

Browse files
committed
try execAsync
1 parent c033645 commit 00ca5ee

File tree

5 files changed

+49
-19
lines changed

5 files changed

+49
-19
lines changed

__tests__/main.test.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const platformMock = jest.spyOn(os, 'platform').mockImplementation()
1616
const runMock = jest.spyOn(main, 'run')
1717

1818
// Mock the action's runScript function
19-
const runScriptMock = jest.spyOn(main, 'runScript')
19+
//const runScriptMock = jest.spyOn(main, 'runScript').mockImplementation()
2020

2121
describe('action', () => {
2222
beforeEach(() => {
@@ -59,11 +59,5 @@ describe('action', () => {
5959
expect(debugMock).toHaveBeenCalledWith('Script name is setup-rhino.ps1')
6060
})
6161

62-
it('runScript returns', async () => {
63-
runScriptMock.mockImplementation('', '')
64-
await main.runScript()
65-
expect(runScriptMock).toHaveReturned()
66-
})
67-
6862
// TODO: Add tests related to validating email address
6963
})

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 23 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const core = require('@actions/core')
22
const path = require('node:path')
33
const { exec } = require('node:child_process')
44
const os = require('node:os')
5+
const util = require('node:util')
6+
const execAsync = util.promisify(require('node:child_process').exec)
57

68
/**
79
* The main function for the action.
@@ -56,10 +58,11 @@ const run = async () => {
5658

5759
core.debug(`command: ${command}`)
5860

59-
const res = await runScript(command, shell)
61+
// const res = await runScript(command, shell)
6062

61-
core.debug(res)
63+
// core.debug(res)
6264

65+
/*
6366
if (
6467
Object.prototype.hasOwnProperty.call(res, 'message') &&
6568
(Object.prototype.hasOwnProperty.call(res.message, 'err') ||
@@ -70,15 +73,31 @@ const run = async () => {
7073
console.log(res.stdout)
7174
}
7275
76+
*/
77+
78+
const { stdout, stderr } = await execAsync(command, shell)
79+
if (stderr !== '' || stderr !== null) {
80+
core.setFailed(stderr)
81+
}
82+
83+
console.log(stdout)
84+
7385
core.debug(new Date().toTimeString())
7486
} catch (error) {
7587
// Fail the workflow run if an error occurs
7688
core.setFailed(error.message)
7789
}
7890
}
7991

92+
/*
8093
const runScript = async (command, shell) => {
8194
return new Promise((resolve, reject) => {
95+
if( !command ) {
96+
reject(new Error('command argument is empty, null, or undefined'))
97+
}
98+
if( !shell ) {
99+
reject(new Error('shell argument is empty, null, or undefined'))
100+
}
82101
exec(command, shell, (err, stdout, stderr) => {
83102
if (err || stderr) {
84103
reject(new Error({ err, stderr }))
@@ -88,8 +107,7 @@ const runScript = async (command, shell) => {
88107
})
89108
})
90109
}
91-
110+
*/
92111
module.exports = {
93-
run,
94-
runScript
112+
run
95113
}

0 commit comments

Comments
 (0)