mirror of https://github.com/aminya/setup-cpp
feat: support installing powershell
This commit is contained in:
parent
c56497d793
commit
6c025078c9
|
@ -15,7 +15,7 @@ COPY "./dist/" "/"
|
||||||
WORKDIR "/"
|
WORKDIR "/"
|
||||||
|
|
||||||
# run installation
|
# run installation
|
||||||
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true
|
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true --powershell true
|
||||||
|
|
||||||
# clean up
|
# clean up
|
||||||
RUN pacman -Scc --noconfirm
|
RUN pacman -Scc --noconfirm
|
||||||
|
|
|
@ -12,7 +12,7 @@ COPY "./dist/" "/"
|
||||||
WORKDIR "/"
|
WORKDIR "/"
|
||||||
|
|
||||||
# run installation
|
# run installation
|
||||||
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true
|
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true --powershell true
|
||||||
|
|
||||||
# clean up
|
# clean up
|
||||||
RUN rm -rf /tmp/*
|
RUN rm -rf /tmp/*
|
||||||
|
|
|
@ -8,7 +8,7 @@ COPY "./dist/" "/"
|
||||||
WORKDIR "/"
|
WORKDIR "/"
|
||||||
|
|
||||||
# run installation
|
# run installation
|
||||||
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true
|
RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck true --ccache true --vcpkg true --doxygen true --gcovr true --task true --powershell true
|
||||||
|
|
||||||
# clean up
|
# clean up
|
||||||
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
|
@ -44,6 +44,7 @@ import { setupSevenZip } from "./sevenzip/sevenzip"
|
||||||
import { setupGraphviz } from "./graphviz/graphviz"
|
import { setupGraphviz } from "./graphviz/graphviz"
|
||||||
import { setupNala } from "./nala/nala"
|
import { setupNala } from "./nala/nala"
|
||||||
import { setupBazel } from "./bazel/bazel"
|
import { setupBazel } from "./bazel/bazel"
|
||||||
|
import { setupPowershell } from "./powershell/powershell"
|
||||||
|
|
||||||
/** The setup functions */
|
/** The setup functions */
|
||||||
const setups = {
|
const setups = {
|
||||||
|
@ -61,6 +62,7 @@ const setups = {
|
||||||
gcc: setupGcc,
|
gcc: setupGcc,
|
||||||
choco: setupChocolatey,
|
choco: setupChocolatey,
|
||||||
brew: setupBrew,
|
brew: setupBrew,
|
||||||
|
powershell: setupPowershell,
|
||||||
ccache: setupCcache,
|
ccache: setupCcache,
|
||||||
doxygen: setupDoxygen,
|
doxygen: setupDoxygen,
|
||||||
graphviz: setupGraphviz,
|
graphviz: setupGraphviz,
|
||||||
|
@ -81,6 +83,7 @@ const tools: Array<keyof typeof setups> = [
|
||||||
"choco",
|
"choco",
|
||||||
"brew",
|
"brew",
|
||||||
"python",
|
"python",
|
||||||
|
"powershell",
|
||||||
"vcpkg",
|
"vcpkg",
|
||||||
"bazel",
|
"bazel",
|
||||||
"cmake",
|
"cmake",
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { setupPowershell } from "../powershell"
|
||||||
|
import { testBin } from "../../utils/tests/test-helpers"
|
||||||
|
import { getVersion } from "../../default_versions"
|
||||||
|
|
||||||
|
jest.setTimeout(300000)
|
||||||
|
describe("setup-powershell", () => {
|
||||||
|
it("should setup powershell", async () => {
|
||||||
|
const installInfo = await setupPowershell(getVersion("powershell", undefined), "", process.arch)
|
||||||
|
|
||||||
|
await testBin("pwsh", ["--version"], installInfo.binDir)
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,51 @@
|
||||||
|
import { addPath } from "../utils/env/addEnv"
|
||||||
|
import { addAptKeyViaDownload, setupAptPack } from "../utils/setup/setupAptPack"
|
||||||
|
import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
|
||||||
|
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
||||||
|
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||||
|
import { isArch } from "../utils/env/isArch"
|
||||||
|
import { hasDnf } from "../utils/env/hasDnf"
|
||||||
|
import { setupDnfPack } from "../utils/setup/setupDnfPack"
|
||||||
|
import { isUbuntu } from "../utils/env/isUbuntu"
|
||||||
|
import { execSudo } from "../utils/exec/sudo"
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
export async function setupPowershell(version: string | undefined, _setupDir: string, _arch: string) {
|
||||||
|
switch (process.platform) {
|
||||||
|
case "win32": {
|
||||||
|
await setupChocoPack("powershell", version)
|
||||||
|
const binDir = "C:/Program Files/PowerShell/7"
|
||||||
|
await addPath(binDir)
|
||||||
|
return { binDir }
|
||||||
|
}
|
||||||
|
case "darwin": {
|
||||||
|
return setupBrewPack("powershell", version, ["--cask"])
|
||||||
|
}
|
||||||
|
case "linux": {
|
||||||
|
if (isArch()) {
|
||||||
|
return setupPacmanPack("powershell-bin", version, "yay")
|
||||||
|
} else if (hasDnf()) {
|
||||||
|
setupDnfPack("curl")
|
||||||
|
execSudo("/bin/bash", [
|
||||||
|
"-c",
|
||||||
|
`curl https://packages.microsoft.com/config/rhel/8/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo`,
|
||||||
|
])
|
||||||
|
return setupDnfPack("powershell", version)
|
||||||
|
} else if (isUbuntu()) {
|
||||||
|
const keyFileName = await addAptKeyViaDownload(
|
||||||
|
"microsoft.asc",
|
||||||
|
"https://packages.microsoft.com/keys/microsoft.asc"
|
||||||
|
)
|
||||||
|
execSudo("/bin/bash", [
|
||||||
|
"-c",
|
||||||
|
`echo "deb [arch=amd64 signed-by=${keyFileName}] https://packages.microsoft.com/repos/microsoft-debian-bullseye-prod bullseye main" > /etc/apt/sources.list.d/microsoft.list`,
|
||||||
|
])
|
||||||
|
return setupAptPack("powershell", version)
|
||||||
|
}
|
||||||
|
throw new Error(`Unsupported linux distribution`)
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw new Error(`Unsupported platform`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ import { InstallationInfo } from "./setupBin"
|
||||||
let hasBrew = false
|
let hasBrew = false
|
||||||
|
|
||||||
/** A function that installs a package using brew */
|
/** A function that installs a package using brew */
|
||||||
export function setupBrewPack(name: string, version?: string): InstallationInfo {
|
export function setupBrewPack(name: string, version?: string, extraArgs: string[] = []): InstallationInfo {
|
||||||
info(`Installing ${name} ${version ?? ""} via brew`)
|
info(`Installing ${name} ${version ?? ""} via brew`)
|
||||||
|
|
||||||
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
|
if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
|
||||||
|
@ -17,7 +17,7 @@ export function setupBrewPack(name: string, version?: string): InstallationInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// brew is not thread-safe
|
// brew is not thread-safe
|
||||||
execa.sync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name], {
|
execa.sync("brew", ["install", version !== undefined && version !== "" ? `${name}@${version}` : name, ...extraArgs], {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue