Skip to content

Commit

Permalink
try execAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
fraguada committed Jul 31, 2024
1 parent c033645 commit 00ca5ee
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 19 deletions.
8 changes: 1 addition & 7 deletions __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const platformMock = jest.spyOn(os, 'platform').mockImplementation()
const runMock = jest.spyOn(main, 'run')

// Mock the action's runScript function
const runScriptMock = jest.spyOn(main, 'runScript')
//const runScriptMock = jest.spyOn(main, 'runScript').mockImplementation()

describe('action', () => {
beforeEach(() => {
Expand Down Expand Up @@ -59,11 +59,5 @@ describe('action', () => {
expect(debugMock).toHaveBeenCalledWith('Script name is setup-rhino.ps1')
})

it('runScript returns', async () => {
runScriptMock.mockImplementation('', '')
await main.runScript()
expect(runScriptMock).toHaveReturned()
})

// TODO: Add tests related to validating email address
})
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 23 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const core = require('@actions/core')
const path = require('node:path')
const { exec } = require('node:child_process')
const os = require('node:os')
const util = require('node:util')
const execAsync = util.promisify(require('node:child_process').exec)

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

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

const res = await runScript(command, shell)
// const res = await runScript(command, shell)

core.debug(res)
// core.debug(res)

/*
if (
Object.prototype.hasOwnProperty.call(res, 'message') &&
(Object.prototype.hasOwnProperty.call(res.message, 'err') ||
Expand All @@ -70,15 +73,31 @@ const run = async () => {
console.log(res.stdout)
}
*/

const { stdout, stderr } = await execAsync(command, shell)
if (stderr !== '' || stderr !== null) {
core.setFailed(stderr)
}

console.log(stdout)

core.debug(new Date().toTimeString())
} catch (error) {
// Fail the workflow run if an error occurs
core.setFailed(error.message)
}
}

/*
const runScript = async (command, shell) => {
return new Promise((resolve, reject) => {
if( !command ) {
reject(new Error('command argument is empty, null, or undefined'))
}
if( !shell ) {
reject(new Error('shell argument is empty, null, or undefined'))
}
exec(command, shell, (err, stdout, stderr) => {
if (err || stderr) {
reject(new Error({ err, stderr }))
Expand All @@ -88,8 +107,7 @@ const runScript = async (command, shell) => {
})
})
}

*/
module.exports = {
run,
runScript
run
}

0 comments on commit 00ca5ee

Please sign in to comment.