Skip to content

Commit 555cb15

Browse files
committed
feat: add binary-based powershell installation
1 parent 35ec48a commit 555cb15

File tree

8 files changed

+159
-88
lines changed

8 files changed

+159
-88
lines changed

dist/actions/setup-cpp.js

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

dist/actions/setup-cpp.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.

dist/legacy/setup-cpp.js

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

dist/legacy/setup-cpp.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.

dist/modern/setup-cpp.js

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

dist/modern/setup-cpp.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/powershell/powershell.ts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,88 @@
11
import { execRootSync } from "admina"
2+
import { error } from "ci-log"
23
import { addPath } from "envosman"
4+
import { addExeExt } from "patha"
35
import { installAptPack } from "setup-apt"
46
import { rcOptions } from "../cli-options.js"
57
import { hasDnf } from "../utils/env/hasDnf.js"
68
import { isArch } from "../utils/env/isArch.js"
79
import { isUbuntu } from "../utils/env/isUbuntu.js"
810
import { ubuntuVersion } from "../utils/env/ubuntu_version.js"
11+
import { extractTarByExe, extractZip } from "../utils/setup/extract.js"
12+
import { type PackageInfo, setupBin } from "../utils/setup/setupBin.js"
913
import { setupBrewPack } from "../utils/setup/setupBrewPack.js"
1014
import { setupChocoPack } from "../utils/setup/setupChocoPack.js"
1115
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
1216
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
1317

18+
/** Get the platform data for cmake */
19+
function getPowerShellPackageInfo(version: string, platform: NodeJS.Platform, arch: string): PackageInfo {
20+
const binFileName = addExeExt("pwsh")
21+
22+
switch (platform) {
23+
case "win32": {
24+
const osArchStr = (["ia32", "x86", "i386", "x32"].includes(arch))
25+
? "win-x86"
26+
: "win-x64"
27+
28+
return {
29+
binRelativeDir: "",
30+
binFileName,
31+
extractedFolderName: "",
32+
extractFunction: extractZip,
33+
url:
34+
`https://github.com/PowerShell/PowerShell/releases/download/v${version}/PowerShell-${version}-${osArchStr}.zip`,
35+
}
36+
}
37+
case "darwin": {
38+
const osArchStr = ["arm", "arm64"].includes(arch) ? "osx-arm64" : "osx-x64"
39+
40+
return {
41+
binRelativeDir: "",
42+
binFileName,
43+
extractedFolderName: "",
44+
extractFunction: extractTarByExe,
45+
url:
46+
`https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-${osArchStr}.tar.gz`,
47+
}
48+
}
49+
case "linux": {
50+
const archMap = {
51+
arm64: "linux-arm64",
52+
arm: "linux-arm64",
53+
arm32: "linux-arm32",
54+
aarch64: "linux-arm64",
55+
x64: "linux-x64",
56+
} as Record<string, string | undefined>
57+
const osArchStr = archMap[arch] ?? "linux-x64"
58+
// TODO support musl
59+
60+
return {
61+
binRelativeDir: "",
62+
binFileName,
63+
extractedFolderName: "",
64+
extractFunction: extractTarByExe,
65+
url:
66+
`https://github.com/PowerShell/PowerShell/releases/download/v${version}/powershell-${version}-${osArchStr}.tar.gz`,
67+
}
68+
}
69+
default:
70+
throw new Error(`Unsupported platform '${platform}'`)
71+
}
72+
}
73+
74+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
75+
export async function setupPowershell(version: string, setupDir: string, arch: string) {
76+
try {
77+
return await setupBin("pwsh", version, getPowerShellPackageInfo, setupDir, arch)
78+
} catch (err) {
79+
error(`Failed to setup pwsh via download: ${err}. Trying package managers...`)
80+
return setupPowershellSystem(version, setupDir, arch)
81+
}
82+
}
83+
1484
// eslint-disable-next-line @typescript-eslint/no-unused-vars
15-
export async function setupPowershell(version: string | undefined, _setupDir: string, _arch: string) {
85+
export async function setupPowershellSystem(version: string | undefined, _setupDir: string, _arch: string) {
1686
switch (process.platform) {
1787
case "win32": {
1888
await setupChocoPack("powershell-core", version)

src/versions/default_versions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const DefaultVersions: Record<string, string | undefined> = {
3232
doxygen: isArch() ? "1.11.0-4" : "1.11.0", // https://www.doxygen.nl/download.html // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=doxygen // https://formulae.brew.sh/formula/doxygen // https://archlinux.org/packages/extra/x86_64/doxygen/
3333
gcc: isArch() ? "13.2.1-3" : "13", // https://github.com/brechtsanders/winlibs_mingw/releases and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
3434
// mingw: isArch() ? "12.2.0-1" : "8", // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=mingw-w64 // https://archlinux.org/packages/extra/x86_64/mingw-w64-gcc/
35+
powershell: "7.4.5", // https://github.com/PowerShell/PowerShell/releases/tag/v7.4.5
3536
}
3637

3738
export const MinVersions: Record<string, string | undefined> = {

0 commit comments

Comments
 (0)