Skip to content

Commit ad1bef0

Browse files
committed
Switch from 'curl | sh' style to a direct download for windows
Signed-off-by: Jason Frey <fryguy9@gmail.com>
1 parent e720ba7 commit ad1bef0

4 files changed

Lines changed: 69 additions & 10 deletions

File tree

dist/index.js

Lines changed: 1 addition & 1 deletion
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-windows.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import * as core from '@actions/core'
2+
import * as exec from '@actions/exec'
3+
import fs from 'fs'
4+
import { tmpdir } from 'os'
5+
import { join } from 'path'
6+
import { downloadFile, calculateSha256, getVersionMetadata } from './install-util.js'
7+
8+
function detectWindowsPlatform() {
9+
const arch = process.arch
10+
const platform = process.platform
11+
12+
if (platform !== 'win32') {
13+
throw new Error(`Unsupported platform: ${platform}`)
14+
}
15+
16+
// Map Node.js arch to IBM Cloud CLI platform identifiers
17+
const archMap = {
18+
'x64': 'win64',
19+
'ia32': 'win32'
20+
}
21+
22+
const mappedArch = archMap[arch]
23+
if (!mappedArch) {
24+
throw new Error(`Unsupported architecture: ${arch}`)
25+
}
26+
27+
return mappedArch
28+
}
29+
30+
async function installWindows() {
31+
const platform = detectWindowsPlatform()
32+
core.info(`Detected platform: ${platform}`)
33+
34+
core.info('Fetching version metadata...')
35+
const { version, installer, sha256 } = await getVersionMetadata(platform)
36+
core.info(`Latest version: ${version}`)
37+
core.info(`Download URL: ${installer}`)
38+
39+
const tmpDir = tmpdir()
40+
const installerPath = join(tmpDir, 'IBM_Cloud_CLI.exe')
41+
core.info('Downloading IBM Cloud CLI...')
42+
await downloadFile(installer, installerPath)
43+
44+
core.info('Verifying checksum...')
45+
const actualSha256 = await calculateSha256(installerPath)
46+
if (actualSha256 !== sha256) {
47+
fs.unlinkSync(installerPath)
48+
throw new Error(`Checksum mismatch! Expected: ${sha256}, Got: ${actualSha256}`)
49+
}
50+
core.info('Checksum verified successfully')
51+
52+
core.info('Running installer...')
53+
await exec.exec('powershell', ['-command', `& "${installerPath}" /s /v"REBOOT=ReallySuppress /qn"`])
54+
55+
core.info('Cleaning up temporary files...')
56+
fs.unlinkSync(installerPath)
57+
58+
// Add to PATH for the current step
59+
process.env.PATH += ';C:\\Program Files\\IBM\\Cloud\\bin'
60+
// Add to GITHUB_PATH for future steps
61+
await exec.exec('powershell', ['-command', `Add-Content $env:GITHUB_PATH 'C:\\Program Files\\IBM\\Cloud\\bin'`])
62+
63+
core.info('IBM Cloud CLI installed successfully')
64+
}
65+
66+
export { installWindows }

src/install.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ import * as exec from '@actions/exec'
33
import * as io from '@actions/io'
44
import { installLinux } from './install-linux.js'
55
import { installMacOS } from './install-macos.js'
6-
7-
async function installWindows() {
8-
await exec.exec(`powershell -command "iex (New-Object Net.WebClient).DownloadString('https://clis.cloud.ibm.com/install/powershell')"`)
9-
// Add to PATH for the current step
10-
process.env.PATH += ';C:\\Program Files\\IBM\\Cloud\\bin'
11-
// Add to GITHUB_PATH for future steps
12-
await exec.exec(`powershell -command "Add-Content $env:GITHUB_PATH 'C:\\Program Files\\IBM\\Cloud\\bin'"`)
13-
}
6+
import { installWindows } from './install-windows.js'
147

158
async function install() {
169
core.startGroup('Installing IBM Cloud CLI')

0 commit comments

Comments
 (0)