Merge pull request #100 from aminya/fedora [skip ci]

This commit is contained in:
Amin Yahyaabadi 2022-07-10 19:20:33 -07:00 committed by GitHub
commit a910f0daaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 251 additions and 92 deletions

View File

@ -92,6 +92,7 @@ jobs:
- "ubuntu_node.dockerfile" - "ubuntu_node.dockerfile"
- "ubuntu_20.04_node.dockerfile" - "ubuntu_20.04_node.dockerfile"
- "arch_node.dockerfile" - "arch_node.dockerfile"
- "fedora_node.dockerfile"
node: node:
- 14 - 14
pnpm: pnpm:

View File

@ -2,20 +2,13 @@
FROM archlinux as base FROM archlinux as base
RUN pacman -Syuu --noconfirm RUN pacman -Syuu --noconfirm
RUN pacman-db-upgrade
# Install packages available from standard repos # nodejs
RUN pacman-db-upgrade && \ RUN pacman -S --noconfirm --needed nodejs
pacman -S --noconfirm --needed \
wget curl pkg-config zip unzip tar git && \
pacman -S --noconfirm \
nodejs && \
pacman -Scc --noconfirm
# install yay # curl for downloading setup-cpp
#RUN useradd -m -G nobody -s /bin/bash yay && passwd -d yay && echo "yay ALL=(ALL) ALL" >> /etc/sudoers RUN pacman -S --noconfirm --needed curl
#RUN git clone --depth 1 https://aur.archlinux.org/yay.git /opt/yay && cd /opt/yay && \
# chown -R yay:root . && chmod -R 775 . && \
# runuser -l yay -c "cd /opt/yay && makepkg -si --noprogressbar --noconfirm"
# add setup_cpp.js # add setup_cpp.js
COPY "./dist/" "/" COPY "./dist/" "/"
@ -26,7 +19,6 @@ RUN node ./setup_cpp.js --compiler llvm --cmake true --ninja true --cppcheck tru
# clean up # clean up
RUN pacman -Scc --noconfirm RUN pacman -Scc --noconfirm
#RUN rm -rf /home/yay/.cache/*
RUN rm -rf /tmp/* RUN rm -rf /tmp/*
CMD source ~/.cpprc CMD source ~/.cpprc

View File

@ -0,0 +1,36 @@
## base image
FROM fedora as base
# nodejs
RUN dnf -y install nodejs
# curl for downloading setup-cpp
RUN dnf -y install curl
# add setup_cpp.js
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
# clean up
RUN rm -rf /tmp/*
CMD source ~/.cpprc
ENTRYPOINT [ "/bin/bash" ]
#### Building
FROM base AS builder
COPY ./dev/cpp_vcpkg_project /home/app
WORKDIR /home/app
RUN bash -c 'source ~/.cpprc \
&& task build'
### Running environment
# use a distroless image or ubuntu:22.04 if you wish
FROM gcr.io/distroless/cc
# copy the built binaries and their runtime dependencies
COPY --from=builder /home/app/build/my_exe/Release/ /home/app/
WORKDIR /home/app/
ENTRYPOINT ["./my_exe"]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/setup_cpp.mjs vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,9 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { isArch } from "../utils/env/isArch" import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupCcache(version: string, _setupDir: string, _arch: string) { export function setupCcache(version: string, _setupDir: string, _arch: string) {
@ -16,8 +19,12 @@ export function setupCcache(version: string, _setupDir: string, _arch: string) {
case "linux": { case "linux": {
if (isArch()) { if (isArch()) {
return setupPacmanPack("ccache", version) return setupPacmanPack("ccache", version)
} else if (hasDnf()) {
return setupDnfPack("ccache", version)
} else if (isUbuntu()) {
return setupAptPack("ccache", version)
} }
return setupAptPack("ccache", version) throw new Error(`Unsupported linux distribution`)
} }
default: { default: {
throw new Error(`Unsupported platform`) throw new Error(`Unsupported platform`)

View File

@ -1,6 +1,6 @@
import { setupCmake } from "../cmake" import { setupCmake } from "../cmake"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers" import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { isGitHubCI } from "../../utils/env/isci" import { isGitHubCI } from "../../utils/env/isCI"
import { getVersion } from "../../default_versions" import { getVersion } from "../../default_versions"
jest.setTimeout(300000) jest.setTimeout(300000)

View File

@ -4,6 +4,9 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { isArch } from "../utils/env/isArch" import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupCppcheck(version: string | undefined, _setupDir: string, _arch: string) { export async function setupCppcheck(version: string | undefined, _setupDir: string, _arch: string) {
@ -19,8 +22,12 @@ export async function setupCppcheck(version: string | undefined, _setupDir: stri
case "linux": { case "linux": {
if (isArch()) { if (isArch()) {
return setupPacmanPack("cppcheck", version) return setupPacmanPack("cppcheck", version)
} else if (hasDnf()) {
return setupDnfPack("ccache", version)
} else if (isUbuntu()) {
return setupAptPack("cppcheck", version)
} }
return setupAptPack("cppcheck", version) throw new Error(`Unsupported linux distribution`)
} }
default: { default: {
throw new Error(`Unsupported platform`) throw new Error(`Unsupported platform`)

View File

@ -12,6 +12,9 @@ import { getVersion } from "../default_versions"
import { existsSync } from "fs" import { existsSync } from "fs"
import { join } from "path" import { join } from "path"
import { isArch } from "../utils/env/isArch" import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
/** Get the platform data for cmake */ /** Get the platform data for cmake */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ -58,25 +61,27 @@ export async function setupDoxygen(version: string, setupDir: string, arch: stri
} }
case "linux": { case "linux": {
let installationInfo: InstallationInfo let installationInfo: InstallationInfo
if (version === "") { if (version === "" || isArch() || hasDnf()) {
if (isArch()) { if (isArch()) {
installationInfo = setupPacmanPack("doxygen", undefined) installationInfo = setupPacmanPack("doxygen", version)
} else if (hasDnf()) {
return setupDnfPack("doxygen", version)
} else if (isUbuntu()) {
installationInfo = setupAptPack("doxygen", version)
} else { } else {
throw new Error(`Unsupported linux distributions`)
}
} else if (isUbuntu()) {
try {
// doxygen on stable Ubuntu repositories is very old. So, we use get the binary from the website itself
installationInfo = await setupBin("doxygen", version, getDoxygenPackageInfo, setupDir, arch)
setupAptPack("libclang-cpp9")
} catch (err) {
notice(`Failed to download doxygen binary. ${err}. Falling back to apt-get.`)
installationInfo = setupAptPack("doxygen", undefined) installationInfo = setupAptPack("doxygen", undefined)
} }
} else { } else {
if (isArch()) { throw new Error(`Unsupported linux distributions`)
installationInfo = setupPacmanPack("doxygen", version)
} else {
try {
// doxygen on stable Ubuntu repositories is very old. So, we use get the binary from the website itself
installationInfo = await setupBin("doxygen", version, getDoxygenPackageInfo, setupDir, arch)
setupAptPack("libclang-cpp9")
} catch (err) {
notice(`Failed to download doxygen binary. ${err}. Falling back to apt-get.`)
installationInfo = setupAptPack("doxygen", undefined)
}
}
} }
await setupGraphviz(getVersion("graphviz", undefined), "", arch) await setupGraphviz(getVersion("graphviz", undefined), "", arch)
return installationInfo return installationInfo

View File

@ -9,12 +9,14 @@ import semverCoerce from "semver/functions/coerce"
import { setupMacOSSDK } from "../macos-sdk/macos-sdk" import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
import path from "path" import path from "path"
import { warning, info } from "../utils/io/io" import { warning, info } from "../utils/io/io"
import { isGitHubCI } from "../utils/env/isci" import { isGitHubCI } from "../utils/env/isCI"
import { addBinExtension } from "../utils/extension/extension" import { addBinExtension } from "../utils/extension/extension"
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin" import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
import { extract7Zip } from "../utils/setup/extract" import { extract7Zip } from "../utils/setup/extract"
import { isArch } from "../utils/env/isArch" import { isArch } from "../utils/env/isArch"
import { isUbuntu } from "../utils/env/isUbuntu" import { isUbuntu } from "../utils/env/isUbuntu"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
interface MingwInfo { interface MingwInfo {
releaseName: string releaseName: string
@ -84,7 +86,11 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
if (arch === "x64") { if (arch === "x64") {
if (isArch()) { if (isArch()) {
installationInfo = setupPacmanPack("gcc", version) installationInfo = setupPacmanPack("gcc", version)
} else { } else if (hasDnf()) {
installationInfo = setupDnfPack("gcc", version)
setupDnfPack("gcc-c++", version)
setupDnfPack("libstdc++-devel", undefined)
} else if (isUbuntu()) {
setupAptPack("gcc", version, ["ppa:ubuntu-toolchain-r/test"]) setupAptPack("gcc", version, ["ppa:ubuntu-toolchain-r/test"])
installationInfo = setupAptPack("g++", version, []) installationInfo = setupAptPack("g++", version, [])
} }
@ -92,7 +98,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string)
info(`Install g++-multilib because gcc for ${arch} was requested`) info(`Install g++-multilib because gcc for ${arch} was requested`)
if (isArch()) { if (isArch()) {
setupPacmanPack("gcc-multilib", version) setupPacmanPack("gcc-multilib", version)
} else { } else if (isUbuntu()) {
setupAptPack("gcc-multilib", version, ["ppa:ubuntu-toolchain-r/test"]) setupAptPack("gcc-multilib", version, ["ppa:ubuntu-toolchain-r/test"])
} }
} }

View File

@ -5,6 +5,9 @@ import { InstallationInfo } from "../utils/setup/setupBin"
import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { isArch } from "../utils/env/isArch" import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupGraphviz(version: string, _setupDir: string, _arch: string) { export async function setupGraphviz(version: string, _setupDir: string, _arch: string) {
@ -19,8 +22,12 @@ export async function setupGraphviz(version: string, _setupDir: string, _arch: s
case "linux": { case "linux": {
if (isArch()) { if (isArch()) {
return setupPacmanPack("graphviz", version) return setupPacmanPack("graphviz", version)
} else if (hasDnf()) {
return setupDnfPack("graphviz", version)
} else if (isUbuntu()) {
return setupAptPack("graphviz", version)
} }
return setupAptPack("graphviz", version) throw new Error(`Unsupported linux distribution`)
} }
default: { default: {
throw new Error(`Unsupported platform`) throw new Error(`Unsupported platform`)

View File

@ -11,6 +11,9 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack" import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { PackageInfo, setupBin } from "../utils/setup/setupBin" import { PackageInfo, setupBin } from "../utils/setup/setupBin"
import { isArch } from "../utils/env/isArch" import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
function getKcovPackageInfo(version: string): PackageInfo { function getKcovPackageInfo(version: string): PackageInfo {
const version_number = parseInt(version.replace(/^v/, ""), 10) const version_number = parseInt(version.replace(/^v/, ""), 10)
@ -47,7 +50,10 @@ async function buildKcov(file: string, dest: string) {
if (isArch()) { if (isArch()) {
setupPacmanPack("libdwarf") setupPacmanPack("libdwarf")
setupPacmanPack("libcurl-openssl") setupPacmanPack("libcurl-openssl")
} else { } else if (hasDnf()) {
setupDnfPack("libdwarf-devel")
setupDnfPack("libcurl-devel")
} else if (isUbuntu()) {
setupAptPack("libdw-dev") setupAptPack("libdw-dev")
setupAptPack("libcurl4-openssl-dev") setupAptPack("libcurl4-openssl-dev")
} }
@ -61,14 +67,14 @@ async function buildKcov(file: string, dest: string) {
export async function setupKcov(version: string, setupDir: string, arch: string) { export async function setupKcov(version: string, setupDir: string, arch: string) {
switch (process.platform) { switch (process.platform) {
case "linux": { case "linux": {
if (isArch()) {
// TODO install kcov ? setupPacmanPack("kcov")
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
setupPacmanPack("binutils")
return installationInfo
}
const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch) const installationInfo = await setupBin("kcov", version, getKcovPackageInfo, setupDir, arch)
setupAptPack("libbinutils") if (isArch()) {
setupPacmanPack("binutils")
} else if (hasDnf()) {
setupDnfPack("binutils")
} else if (isUbuntu()) {
setupAptPack("libbinutils")
}
return installationInfo return installationInfo
} }
default: { default: {

View File

@ -2,7 +2,7 @@ import { setupLLVM, VERSIONS, getUrl, setupClangTools, getLinuxUrl } from "../ll
import { getSpecificVersionAndUrl } from "../../utils/setup/version" import { getSpecificVersionAndUrl } from "../../utils/setup/version"
import { isValidUrl } from "../../utils/http/validate_url" import { isValidUrl } from "../../utils/http/validate_url"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers" import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { isGitHubCI } from "../../utils/env/isci" import { isGitHubCI } from "../../utils/env/isCI"
import execa from "execa" import execa from "execa"
import path from "path" import path from "path"
import { addBinExtension } from "../../utils/extension/extension" import { addBinExtension } from "../../utils/extension/extension"

View File

@ -17,7 +17,7 @@ import { setOutput } from "@actions/core"
import { setupAptPack, updateAptAlternatives } from "../utils/setup/setupAptPack" import { setupAptPack, updateAptAlternatives } from "../utils/setup/setupAptPack"
import { info, warning } from "../utils/io/io" import { info, warning } from "../utils/io/io"
import { existsSync } from "fs" import { existsSync } from "fs"
import { isGitHubCI } from "../utils/env/isci" import { isGitHubCI } from "../utils/env/isCI"
import { setupGcc } from "../gcc/gcc" import { setupGcc } from "../gcc/gcc"
import { getVersion } from "../default_versions" import { getVersion } from "../default_versions"
import { isArch } from "../utils/env/isArch" import { isArch } from "../utils/env/isArch"
@ -290,7 +290,7 @@ async function _setupLLVM(version: string, setupDir: string, arch: string) {
if (isArch()) { if (isArch()) {
// setupPacmanPack("ncurses") // setupPacmanPack("ncurses")
// TODO: install libtinfo ? // TODO: install libtinfo ?
} else { } else if (isUbuntu()) {
setupAptPack("libtinfo-dev") setupAptPack("libtinfo-dev")
} }
} }

View File

@ -17,7 +17,7 @@ import { setupOpencppcoverage } from "./opencppcoverage/opencppcoverage"
import { setupPython } from "./python/python" import { setupPython } from "./python/python"
import mri from "mri" import mri from "mri"
import { untildify_user as untildify } from "./utils/path/untildify" import { untildify_user as untildify } from "./utils/path/untildify"
import { isGitHubCI } from "./utils/env/isci" import { isGitHubCI } from "./utils/env/isCI"
import * as timeDelta from "time-delta" import * as timeDelta from "time-delta"
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore

View File

@ -4,6 +4,9 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { isArch } from "../utils/env/isArch" import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupMake(version: string, _setupDir: string, _arch: string) { export async function setupMake(version: string, _setupDir: string, _arch: string) {
@ -19,8 +22,12 @@ export async function setupMake(version: string, _setupDir: string, _arch: strin
case "linux": { case "linux": {
if (isArch()) { if (isArch()) {
return setupPacmanPack("make", version) return setupPacmanPack("make", version)
} else if (hasDnf()) {
return setupDnfPack("make", version)
} else if (isUbuntu()) {
return setupAptPack("make", version)
} }
return setupAptPack("make", version) throw new Error(`Unsupported linux distribution`)
} }
default: { default: {
throw new Error(`Unsupported platform`) throw new Error(`Unsupported platform`)

View File

@ -3,7 +3,7 @@ import { setupVCVarsall } from "../vcvarsall/vcvarsall"
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
import { vsversion_to_versionnumber, findVcvarsall } from "msvc-dev-cmd/lib.js" import { vsversion_to_versionnumber, findVcvarsall } from "msvc-dev-cmd/lib.js"
import { isGitHubCI } from "../utils/env/isci" import { isGitHubCI } from "../utils/env/isCI"
import path from "path" import path from "path"
import { existsSync } from "fs" import { existsSync } from "fs"
import { error, info, warning } from "../utils/io/io" import { error, info, warning } from "../utils/io/io"

View File

@ -1,6 +1,6 @@
import { setupNinja } from "../ninja" import { setupNinja } from "../ninja"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers" import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { isGitHubCI } from "../../utils/env/isci" import { isGitHubCI } from "../../utils/env/isCI"
import { getVersion } from "../../default_versions" import { getVersion } from "../../default_versions"
jest.setTimeout(300000) jest.setTimeout(300000)

View File

@ -2,7 +2,7 @@ import { setupPython } from "../python"
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers" import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { getVersion } from "../../default_versions" import { getVersion } from "../../default_versions"
import { ubuntuVersion } from "../../utils/env/ubuntu_version" import { ubuntuVersion } from "../../utils/env/ubuntu_version"
import { isGitHubCI } from "../../utils/env/isci" import { isGitHubCI } from "../../utils/env/isCI"
import { info } from "../../utils/io/io" import { info } from "../../utils/io/io"
jest.setTimeout(300000) jest.setTimeout(300000)

View File

@ -4,7 +4,7 @@ import { existsSync } from "fs"
import { info, warning } from "../utils/io/io" import { info, warning } from "../utils/io/io"
import { debug } from "@actions/core" import { debug } from "@actions/core"
import path from "path" import path from "path"
import { isGitHubCI } from "../utils/env/isci" import { isGitHubCI } from "../utils/env/isCI"
import { isCacheFeatureAvailable, IS_LINUX, IS_WINDOWS } from "setup-python/src/utils" import { isCacheFeatureAvailable, IS_LINUX, IS_WINDOWS } from "setup-python/src/utils"
import { getCacheDistributor } from "setup-python/src/cache-distributions/cache-factory" import { getCacheDistributor } from "setup-python/src/cache-distributions/cache-factory"

View File

@ -3,12 +3,15 @@ import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack" import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { isGitHubCI } from "../utils/env/isci" import { isGitHubCI } from "../utils/env/isCI"
import { warning, info } from "../utils/io/io" import { warning, info } from "../utils/io/io"
import { isArch } from "../utils/env/isArch" import { isArch } from "../utils/env/isArch"
import which from "which" import which from "which"
import { InstallationInfo } from "../utils/setup/setupBin" import { InstallationInfo } from "../utils/setup/setupBin"
import { dirname, join } from "path" import { dirname, join } from "path"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
export async function setupPython(version: string, setupDir: string, arch: string) { export async function setupPython(version: string, setupDir: string, arch: string) {
if (!isGitHubCI()) { if (!isGitHubCI()) {
@ -52,13 +55,19 @@ export async function setupPythonViaSystem(
return setupBrewPack("python3", version) return setupBrewPack("python3", version)
} }
case "linux": { case "linux": {
let installInfo: InstallationInfo
if (isArch()) { if (isArch()) {
const installInfo = setupPacmanPack("python", version) installInfo = setupPacmanPack("python", version)
setupPacmanPack("python-pip") setupPacmanPack("python-pip")
return installInfo } else if (hasDnf()) {
installInfo = setupDnfPack("python3", version)
setupDnfPack("python3-pip")
} else if (isUbuntu()) {
installInfo = setupAptPack("python3", version)
setupAptPack("python3-pip")
} else {
throw new Error(`Unsupported linux distributions`)
} }
const installInfo = setupAptPack("python3", version)
setupAptPack("python3-pip")
return installInfo return installInfo
} }
default: { default: {

View File

@ -3,6 +3,9 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack" import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { isArch } from "../utils/env/isArch" import { isArch } from "../utils/env/isArch"
import { hasDnf } from "../utils/env/hasDnf"
import { setupDnfPack } from "../utils/setup/setupDnfPack"
import { isUbuntu } from "../utils/env/isUbuntu"
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupSevenZip(version: string, _setupDir: string, _arch: string) { export function setupSevenZip(version: string, _setupDir: string, _arch: string) {
@ -16,8 +19,13 @@ export function setupSevenZip(version: string, _setupDir: string, _arch: string)
case "linux": { case "linux": {
if (isArch()) { if (isArch()) {
return setupPacmanPack("p7zip", version) return setupPacmanPack("p7zip", version)
} else if (hasDnf()) {
setupDnfPack("p7zip", version)
return setupDnfPack("p7zip-plugins", version)
} else if (isUbuntu()) {
return setupAptPack("p7zip-full", version)
} }
return setupAptPack("p7zip-full", version) throw new Error(`Unsupported linux distribution`)
} }
default: { default: {
throw new Error(`Unsupported platform`) throw new Error(`Unsupported platform`)

View File

@ -1,6 +1,6 @@
import { setupTask } from "../task" import { setupTask } from "../task"
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers" import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
import { isGitHubCI } from "../../utils/env/isci" import { isGitHubCI } from "../../utils/env/isCI"
import { getVersion } from "../../default_versions" import { getVersion } from "../../default_versions"
jest.setTimeout(300000) jest.setTimeout(300000)

View File

@ -1,5 +1,5 @@
import { exportVariable, addPath as ghAddPath, info, setFailed } from "@actions/core" import { exportVariable, addPath as ghAddPath, info, setFailed } from "@actions/core"
import { isGitHubCI } from "./isci" import { isGitHubCI } from "./isCI"
import { untildify_user as untildify } from "../path/untildify" import { untildify_user as untildify } from "../path/untildify"
import { appendFileSync, existsSync, readFileSync } from "fs" import { appendFileSync, existsSync, readFileSync } from "fs"
import { error, warning } from "../io/io" import { error, warning } from "../io/io"

14
src/utils/env/hasDnf.ts vendored Normal file
View File

@ -0,0 +1,14 @@
import which from "which"
let hasDnfCache: undefined | boolean = undefined
export function hasDnf(): boolean {
if (process.platform !== "linux") {
return false
}
if (hasDnfCache === undefined) {
hasDnfCache = which.sync("dnf", { nothrow: true }) !== null
}
return hasDnfCache
}

View File

@ -0,0 +1,13 @@
import { isRoot } from "../env/sudo"
import { execSudo } from "../exec/sudo"
/// change the owner to the SUDO_USER. This is required so the user can use the folder without sudo
export function folderUserAccess(folder: string) {
if (
(process.platform === "linux" || process.platform === "darwin") &&
isRoot() &&
process.env.SUDO_USER !== undefined
) {
execSudo("chown", ["-R", process.env.SUDO_USER, folder], folder)
}
}

View File

@ -1,5 +1,5 @@
import * as core from "@actions/core" import * as core from "@actions/core"
import { isGitHubCI } from "../env/isci" import { isGitHubCI } from "../env/isCI"
export function error(err: string | Error) { export function error(err: string | Error) {
return isGitHubCI() ? core.error(err) : console.log(`\x1b[31m${err}\x1b[0m`) return isGitHubCI() ? core.error(err) : console.log(`\x1b[31m${err}\x1b[0m`)

View File

@ -3,6 +3,7 @@ import { mkdirP } from "@actions/io"
import which from "which" import which from "which"
import { setupSevenZip } from "../../sevenzip/sevenzip" import { setupSevenZip } from "../../sevenzip/sevenzip"
import { warning } from "../io/io" import { warning } from "../io/io"
import { folderUserAccess } from "../fs/userAccess"
export { extractTar, extractXar } from "@actions/tool-cache" export { extractTar, extractXar } from "@actions/tool-cache"
let sevenZip: string | undefined let sevenZip: string | undefined
@ -10,6 +11,7 @@ let sevenZip: string | undefined
/// Extract 7z using 7z /// Extract 7z using 7z
export async function extract7Zip(file: string, dest: string) { export async function extract7Zip(file: string, dest: string) {
await execa(await getSevenZip(), ["x", file, `-o${dest}`, "-y"], { stdio: "inherit" }) await execa(await getSevenZip(), ["x", file, `-o${dest}`, "-y"], { stdio: "inherit" })
folderUserAccess(dest)
return dest return dest
} }
@ -53,5 +55,6 @@ export async function extractTarByExe(file: string, dest: string, flags = ["--st
} }
} }
folderUserAccess(dest)
return dest return dest
} }

View File

@ -3,7 +3,7 @@ import { InstallationInfo } from "./setupBin"
import { execSudo } from "../exec/sudo" import { execSudo } from "../exec/sudo"
import { info } from "@actions/core" import { info } from "@actions/core"
import { warning } from "../io/io" import { warning } from "../io/io"
import { isGitHubCI } from "../env/isci" import { isGitHubCI } from "../env/isCI"
import { cpprc_path, setupCppInProfile } from "../env/addEnv" import { cpprc_path, setupCppInProfile } from "../env/addEnv"
import { appendFileSync } from "fs" import { appendFileSync } from "fs"
@ -29,9 +29,6 @@ export function setupAptPack(
if (!didInit) { if (!didInit) {
// install apt utils and certificates (usually missing from docker containers) // install apt utils and certificates (usually missing from docker containers)
// set time - zone
// TZ = Canada / Pacific
// ln - snf / usr / share / zoneinfo / $TZ / etc / localtime && echo $TZ > /etc/timezone
execSudo(apt, [ execSudo(apt, [
"install", "install",
"--fix-broken", "--fix-broken",

View File

@ -4,10 +4,13 @@ import { addPath } from "../env/addEnv"
import { join } from "path" import { join } from "path"
import { existsSync } from "fs" import { existsSync } from "fs"
import { tmpdir } from "os" import { tmpdir } from "os"
import { isGitHubCI } from "../env/isci" import { isGitHubCI } from "../env/isCI"
import { setupAptPack } from "./setupAptPack" import { setupAptPack } from "./setupAptPack"
import { setupPacmanPack } from "./setupPacmanPack" import { setupPacmanPack } from "./setupPacmanPack"
import { isArch } from "../env/isArch" import { isArch } from "../env/isArch"
import { hasDnf } from "../env/hasDnf"
import { setupDnfPack } from "./setupDnfPack"
import { isUbuntu } from "../env/isUbuntu"
/** A type that describes a package */ /** A type that describes a package */
export type PackageInfo = { export type PackageInfo = {
@ -94,7 +97,11 @@ export async function setupBin(
setupPacmanPack("unzip") setupPacmanPack("unzip")
setupPacmanPack("tar") setupPacmanPack("tar")
setupPacmanPack("xz") setupPacmanPack("xz")
} else { } else if (hasDnf()) {
setupDnfPack("unzip")
setupDnfPack("tar")
setupDnfPack("xz")
} else if (isUbuntu()) {
setupAptPack("unzip") setupAptPack("unzip")
setupAptPack("tar") setupAptPack("tar")
setupAptPack("xz-utils") setupAptPack("xz-utils")

View File

@ -0,0 +1,31 @@
/* eslint-disable require-atomic-updates */
import { InstallationInfo } from "./setupBin"
import { execSudo } from "../exec/sudo"
import { info, warning } from "../io/io"
// let didUpdate: boolean = false
/** A function that installs a package using dnf */
export function setupDnfPack(name: string, version?: string): InstallationInfo {
info(`Installing ${name} ${version ?? ""} via dnf`)
const dnf = "dnf"
// if (!didUpdate) {
// execSudo(dnf, ["-y", "check-update"])
// didUpdate = true
// }
if (version !== undefined && version !== "") {
try {
execSudo(dnf, ["-y", "install", `${name}-${version}`])
} catch (err) {
warning(`${(err as Error).toString()}\nInstalling the default version available via dnf`)
execSudo(dnf, ["-y", "install", name])
}
} else {
execSudo(dnf, ["-y", "install", name])
}
return { binDir: "/usr/bin/" }
}

View File

@ -18,10 +18,6 @@ export function setupPacmanPack(name: string, version?: string, aur?: string): I
} }
if (!didInit) { if (!didInit) {
// set time - zone
// TZ = Canada / Pacific
// ln - snf / usr / share / zoneinfo / $TZ / etc / localtime && echo $TZ > /etc/timezone
// install base-devel // install base-devel
execSudo(pacman, ["-Sy", "--noconfirm", "base-devel"]) execSudo(pacman, ["-Sy", "--noconfirm", "base-devel"])
didInit = true didInit = true

View File

@ -12,6 +12,9 @@ import { InstallationInfo } from "./setupBin"
import { setupAptPack } from "./setupAptPack" import { setupAptPack } from "./setupAptPack"
import { setupPacmanPack } from "./setupPacmanPack" import { setupPacmanPack } from "./setupPacmanPack"
import { isArch } from "../env/isArch" import { isArch } from "../env/isArch"
import { isUbuntu } from "../env/isUbuntu"
import { hasDnf } from "../env/hasDnf"
import { setupDnfPack } from "./setupDnfPack"
let python: string | undefined let python: string | undefined
let binDir: string | undefined let binDir: string | undefined
@ -46,7 +49,9 @@ export async function setupPipPack(name: string, version?: string): Promise<Inst
// ensure that pip is installed on Linux (happens when python is found but pip not installed) // ensure that pip is installed on Linux (happens when python is found but pip not installed)
if (isArch()) { if (isArch()) {
setupPacmanPack("python-pip") setupPacmanPack("python-pip")
} else { } else if (hasDnf()) {
setupDnfPack("python3-pip")
} else if (isUbuntu()) {
setupAptPack("python3-pip") setupAptPack("python3-pip")
} }
} }

View File

@ -3,14 +3,16 @@ import { existsSync } from "fs"
import { dirname, join } from "path" import { dirname, join } from "path"
import which from "which" import which from "which"
import { addPath } from "../utils/env/addEnv" import { addPath } from "../utils/env/addEnv"
import { isRoot } from "../utils/env/sudo"
import { execSudo } from "../utils/exec/sudo"
import { addShellExtension, addShellHere } from "../utils/extension/extension" import { addShellExtension, addShellHere } from "../utils/extension/extension"
import { notice } from "../utils/io/io" import { notice } from "../utils/io/io"
import { setupAptPack } from "../utils/setup/setupAptPack" import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack" import { setupPacmanPack } from "../utils/setup/setupPacmanPack"
import { InstallationInfo } from "../utils/setup/setupBin" import { InstallationInfo } from "../utils/setup/setupBin"
import { isArch } from "../utils/env/isArch" 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 { folderUserAccess } from "../utils/fs/userAccess"
let hasVCPKG = false let hasVCPKG = false
@ -26,7 +28,14 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
setupPacmanPack("tar") setupPacmanPack("tar")
setupPacmanPack("git") setupPacmanPack("git")
setupPacmanPack("pkg-config") setupPacmanPack("pkg-config")
} else { } else if (hasDnf()) {
setupDnfPack("curl")
setupDnfPack("zip")
setupDnfPack("unzip")
setupDnfPack("tar")
setupDnfPack("git")
setupDnfPack("pkg-config")
} else if (isUbuntu()) {
setupAptPack("curl") setupAptPack("curl")
setupAptPack("zip") setupAptPack("zip")
setupAptPack("unzip") setupAptPack("unzip")
@ -44,14 +53,7 @@ export async function setupVcpkg(_version: string, setupDir: string, _arch: stri
execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true, stdio: "inherit" }) execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true, stdio: "inherit" })
// change the owner to the SUDO_USER in setupDir. vcpkg requires this so it can install things without sudo folderUserAccess(setupDir)
if (
(process.platform === "linux" || process.platform === "darwin") &&
isRoot() &&
process.env.SUDO_USER !== undefined
) {
execSudo("chown", ["-R", process.env.SUDO_USER, setupDir], setupDir)
}
await addPath(setupDir) await addPath(setupDir)
// eslint-disable-next-line require-atomic-updates // eslint-disable-next-line require-atomic-updates