Skip to content

Commit

Permalink
Merge pull request #113 from aminya/powershell [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Aug 8, 2022
2 parents c56497d + 1b9b071 commit c411e14
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dev/docker/fedora_node.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ COPY "./dist/" "/"
WORKDIR "/"

# 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
RUN rm -rf /tmp/*
Expand Down
2 changes: 1 addition & 1 deletion dev/docker/ubuntu_node.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY "./dist/" "/"
WORKDIR "/"

# 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
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
Expand Down
2 changes: 1 addition & 1 deletion dist/setup_cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.mjs.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { setupSevenZip } from "./sevenzip/sevenzip"
import { setupGraphviz } from "./graphviz/graphviz"
import { setupNala } from "./nala/nala"
import { setupBazel } from "./bazel/bazel"
import { setupPowershell } from "./powershell/powershell"

/** The setup functions */
const setups = {
Expand All @@ -61,6 +62,7 @@ const setups = {
gcc: setupGcc,
choco: setupChocolatey,
brew: setupBrew,
powershell: setupPowershell,
ccache: setupCcache,
doxygen: setupDoxygen,
graphviz: setupGraphviz,
Expand All @@ -81,6 +83,7 @@ const tools: Array<keyof typeof setups> = [
"choco",
"brew",
"python",
"powershell",
"vcpkg",
"bazel",
"cmake",
Expand Down
12 changes: 12 additions & 0 deletions src/powershell/__tests__/powershell.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
64 changes: 64 additions & 0 deletions src/powershell/powershell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { addPath } from "../utils/env/addEnv"
import { 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 { execRootSync } from "root-tools"
import { ubuntuVersion } from "../utils/env/ubuntu_version"

// 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-core", 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")
execRootSync("/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()) {
await setupAptPack("curl")
const ubuntuVerSplitted = (await ubuntuVersion())!
const ubuntuVersionString = `${ubuntuVerSplitted[0]}.0${ubuntuVerSplitted[1]}`

execRootSync("curl", [
"-LJO",
`https://packages.microsoft.com/config/ubuntu/${ubuntuVersionString}/packages-microsoft-prod.deb`,
])
execRootSync("dpkg", ["-i", "packages-microsoft-prod.deb"])

// TODO Debian
// const keyFileName = await addAptKeyViaDownload(
// "microsoft.asc",
// "https://packages.microsoft.com/keys/microsoft.asc"
// )
// execRootSync("/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, [], true)
}
throw new Error(`Unsupported linux distribution`)
}
default: {
throw new Error(`Unsupported platform`)
}
}
}
4 changes: 2 additions & 2 deletions src/utils/setup/setupBrewPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { InstallationInfo } from "./setupBin"
let hasBrew = false

/** 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`)

if (!hasBrew || which.sync("brew", { nothrow: true }) === null) {
Expand All @@ -17,7 +17,7 @@ export function setupBrewPack(name: string, version?: string): InstallationInfo
}

// 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",
})

Expand Down

0 comments on commit c411e14

Please sign in to comment.