11const core = require ( '@actions/core' )
22const exec = require ( '@actions/exec' )
3+ const io = require ( '@actions/io' )
34
45/**
56 * Colorize a string with ANSI codes.
@@ -14,16 +15,21 @@ function colorize(string, color) {
1415
1516async function installCLI ( ) {
1617 core . startGroup ( 'Installing IBM Cloud CLI' )
17- if ( process . platform == 'win32' ) {
18- await exec . exec ( `powershell -command "iex (New-Object Net.WebClient).DownloadString('https://clis.cloud.ibm.com/install/powershell')"` )
19- // Add to PATH for the current step
20- process . env . PATH += ';C:\\Program Files\\IBM\\Cloud\\bin'
21- // Add to GITHUB_PATH for future steps
22- await exec . exec ( `powershell -command "Add-Content $env:GITHUB_PATH 'C:\\Program Files\\IBM\\Cloud\\bin'"` )
23- } else if ( process . platform == 'darwin' ) {
24- await exec . exec ( '/bin/bash -c "curl -fsSL https://clis.cloud.ibm.com/install/osx | sh"' )
18+ const cliPath = await io . which ( "ibmcloud" )
19+ if ( cliPath ) {
20+ core . info ( "IBM Cloud CLI is already installed." )
2521 } else {
26- await exec . exec ( '/bin/bash -c "curl -fsSL https://clis.cloud.ibm.com/install/linux | sh"' )
22+ if ( process . platform == 'win32' ) {
23+ await exec . exec ( `powershell -command "iex (New-Object Net.WebClient).DownloadString('https://clis.cloud.ibm.com/install/powershell')"` )
24+ // Add to PATH for the current step
25+ process . env . PATH += ';C:\\Program Files\\IBM\\Cloud\\bin'
26+ // Add to GITHUB_PATH for future steps
27+ await exec . exec ( `powershell -command "Add-Content $env:GITHUB_PATH 'C:\\Program Files\\IBM\\Cloud\\bin'"` )
28+ } else if ( process . platform == 'darwin' ) {
29+ await exec . exec ( '/bin/bash -c "curl -fsSL https://clis.cloud.ibm.com/install/osx | sh"' )
30+ } else {
31+ await exec . exec ( '/bin/bash -c "curl -fsSL https://clis.cloud.ibm.com/install/linux | sh"' )
32+ }
2733 }
2834 core . endGroup ( )
2935}
@@ -101,8 +107,8 @@ async function login() {
101107async function run ( ) {
102108 try {
103109 await installCLI ( )
104- await disableVersionChecking ( )
105110 await captureVersion ( )
111+ await disableVersionChecking ( )
106112 await installPlugins ( )
107113 await setApiEndpoint ( )
108114 await login ( )
0 commit comments