Skip to content

Commit 2b83ed4

Browse files
committed
Add error checking to exec calls
Signed-off-by: Jason Frey <fryguy9@gmail.com>
1 parent ad1bef0 commit 2b83ed4

5 files changed

Lines changed: 33 additions & 11 deletions

File tree

dist/index.js

Lines changed: 3 additions & 3 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/install-linux.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,30 @@ async function installLinux() {
5353
core.info('Checksum verified successfully')
5454

5555
core.info('Extracting installer...')
56-
await exec.exec('tar', ['-xzvf', tarballPath, '-C', tmpDir])
56+
let exitCode = await exec.exec('tar', ['-xzvf', tarballPath, '-C', tmpDir])
57+
if (exitCode !== 0) {
58+
throw new Error(`Failed to extract installer (exit code: ${exitCode})`)
59+
}
5760

5861
const extractDir = join(tmpDir, 'Bluemix_CLI')
5962
core.info('Running installer...')
6063
const installScript = join(extractDir, 'install')
61-
await exec.exec('chmod', ['755', installScript])
62-
await exec.exec(installScript, ['-q'])
64+
exitCode = await exec.exec('chmod', ['755', installScript])
65+
if (exitCode !== 0) {
66+
throw new Error(`Failed to set permissions on install script (exit code: ${exitCode})`)
67+
}
68+
69+
exitCode = await exec.exec(installScript, ['-q'])
70+
if (exitCode !== 0) {
71+
throw new Error(`Installation failed (exit code: ${exitCode})`)
72+
}
6373

6474
core.info('Cleaning up temporary files...')
6575
fs.unlinkSync(tarballPath)
66-
await exec.exec('rm', ['-rf', extractDir])
76+
exitCode = await exec.exec('rm', ['-rf', extractDir])
77+
if (exitCode !== 0) {
78+
core.warning(`Failed to clean up temporary directory (exit code: ${exitCode})`)
79+
}
6780

6881
core.info('IBM Cloud CLI installed successfully')
6982
}

src/install-macos.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ async function installMacOS() {
5050
core.info('Checksum verified successfully')
5151

5252
core.info('Running installer...')
53-
await exec.exec('sudo', ['installer', '-pkg', pkgPath, '-target', '/'])
53+
const exitCode = await exec.exec('sudo', ['installer', '-pkg', pkgPath, '-target', '/'])
54+
if (exitCode !== 0) {
55+
throw new Error(`Installation failed (exit code: ${exitCode})`)
56+
}
5457

5558
core.info('Cleaning up temporary files...')
5659
fs.unlinkSync(pkgPath)

src/install-windows.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,21 @@ async function installWindows() {
5050
core.info('Checksum verified successfully')
5151

5252
core.info('Running installer...')
53-
await exec.exec('powershell', ['-command', `& "${installerPath}" /s /v"REBOOT=ReallySuppress /qn"`])
53+
let exitCode = await exec.exec('powershell', ['-command', `& "${installerPath}" /s /v"REBOOT=ReallySuppress /qn"`])
54+
if (exitCode !== 0) {
55+
throw new Error(`Installation failed (exit code: ${exitCode})`)
56+
}
5457

5558
core.info('Cleaning up temporary files...')
5659
fs.unlinkSync(installerPath)
5760

5861
// Add to PATH for the current step
5962
process.env.PATH += ';C:\\Program Files\\IBM\\Cloud\\bin'
6063
// Add to GITHUB_PATH for future steps
61-
await exec.exec('powershell', ['-command', `Add-Content $env:GITHUB_PATH 'C:\\Program Files\\IBM\\Cloud\\bin'`])
64+
exitCode = await exec.exec('powershell', ['-command', `Add-Content $env:GITHUB_PATH 'C:\\Program Files\\IBM\\Cloud\\bin'`])
65+
if (exitCode !== 0) {
66+
core.warning(`Failed to add IBM Cloud CLI to GITHUB_PATH (exit code: ${exitCode})`)
67+
}
6268

6369
core.info('IBM Cloud CLI installed successfully')
6470
}

0 commit comments

Comments
 (0)