Skip to content

Commit 665d0d0

Browse files
committed
Check if ibmcloud already exists before installing
Signed-off-by: Jason Frey <[email protected]>
1 parent 1082c34 commit 665d0d0

File tree

6 files changed

+57
-25
lines changed

6 files changed

+57
-25
lines changed

.github/workflows/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ jobs:
199199
ibmcloud target | grep -q '^Region:\s\+us-south$' &&
200200
ibmcloud target | grep -q '^Resource group:\s\+default$'
201201
202+
test-already-installed:
203+
strategy:
204+
matrix:
205+
os:
206+
- ubuntu-latest
207+
- macos-latest
208+
- windows-latest
209+
fail-fast: false
210+
runs-on: ${{ matrix.os }}
211+
steps:
212+
- uses: actions/checkout@v5
213+
- name: Set up ibmcloud CLI
214+
uses: ./
215+
- name: Set up ibmcloud CLI (again)
216+
uses: ./
217+
- name: Check basic CLI function
218+
run: ibmcloud --version
219+
202220
test-multiple-platforms:
203221
strategy:
204222
matrix:

dist/index.js

Lines changed: 16 additions & 10 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.

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
"package": "ncc build src/index.js -o dist --source-map --license licenses.txt"
2525
},
2626
"dependencies": {
27-
"@actions/core": "^1.10.0",
28-
"@actions/exec": "^1.1.1"
27+
"@actions/core": "^1.11.1",
28+
"@actions/exec": "^1.1.1",
29+
"@actions/io": "^1.1.3"
2930
},
3031
"devDependencies": {
3132
"@vercel/ncc": "^0.38.1"

src/main.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const core = require('@actions/core')
22
const 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

1516
async 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() {
101107
async 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

Comments
 (0)