Files
setup-uv/src/utils/platforms.ts
Kevin Stillhammer e2e9087257
Some checks failed
test-cache-windows / test-setup-cache (push) Waiting to run
test-cache-windows / test-restore-cache (push) Blocked by required conditions
Release Drafter / ✏️ Draft release (push) Failing after 12s
test-windows / test-default-version (push) Waiting to run
test-cache / test-setup-cache (auto, ubuntu-latest) (push) Successful in 29s
test-cache / test-setup-cache (false, ubuntu-latest) (push) Failing after 31s
test-cache / test-setup-cache (true, ubuntu-latest) (push) Successful in 41s
test-cache / test-setup-cache-requirements-txt (push) Failing after 31s
Check dist/ / check-dist (push) Successful in 1m36s
test-cache / test-no-python-version (push) Failing after 30s
test-cache / test-setup-cache-dependency-glob (push) Successful in 51s
test / test-default-version (ubuntu-latest) (push) Failing after 31s
test / test-specific-version (0.3) (push) Successful in 49s
test / test-specific-version (0.3.0) (push) Failing after 30s
test / build (push) Successful in 1m29s
test / test-specific-version (0.3.2) (push) Failing after 30s
test / test-semver-range (push) Failing after 4s
test / test-specific-version (>=0.3.0) (push) Successful in 39s
test / test-specific-version (0.3.x) (push) Successful in 44s
test / test-pyproject-file-version (push) Failing after 4s
test / test-with-explicit-token (push) Failing after 3s
test / test-uvx (push) Failing after 3s
test / test-tool-install (ubuntu-latest) (push) Failing after 4s
test / test-python-version (macos-latest) (push) Failing after 5s
test / test-uv-file-version (push) Successful in 30s
test / test-python-version (ubuntu-latest) (push) Failing after 5s
test / test-malformed-pyproject-file-fallback (push) Failing after 4s
test / test-checksum (4d9279ad5ca596b1e2d703901d508430eb07564dc4d8837de9e2fca9c90f8ecd, ubuntu-latest) (push) Successful in 48s
test / test-musl (push) Failing after 0s
test-cache / test-restore-cache-dependency-glob (push) Failing after 5s
test / test-python-version (windows-latest) (push) Successful in 1m17s
CodeQL / Analyze (TypeScript) (push) Failing after 5m54s
Update known checksums / build (push) Failing after 21s
test-cache / test-setup-cache (auto, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-setup-cache (false, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-setup-cache (true, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-setup-cache-local (push) Has been cancelled
test-cache / test-tilde-expansion-cache-local-path (push) Has been cancelled
test-cache / test-tilde-expansion-cache-dependency-glob (push) Has been cancelled
test / test-default-version (macos-14) (push) Has been cancelled
test / test-default-version (macos-latest) (push) Has been cancelled
test / test-checksum (a70cbfbf3bb5c08b2f84963b4f12c94e08fbb2468ba418a3bfe1066fbe9e7218, macos-latest) (push) Has been cancelled
test / test-tool-install (macos-14) (push) Has been cancelled
test / test-tool-install (macos-latest) (push) Has been cancelled
test / test-tool-install (windows-latest) (push) Has been cancelled
test / test-tilde-expansion-tool-dirs (push) Has been cancelled
test-cache / test-restore-cache (auto, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-restore-cache (auto, ubuntu-latest) (push) Has been cancelled
test-cache / test-restore-cache (false, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-restore-cache (false, ubuntu-latest) (push) Has been cancelled
test-cache / test-restore-cache (true, selfhosted-ubuntu-arm64) (push) Has been cancelled
test-cache / test-restore-cache (true, ubuntu-latest) (push) Has been cancelled
test-cache / test-restore-cache-requirements-txt (push) Has been cancelled
test-cache / test-restore-cache-local (push) Has been cancelled
test-cache / cleanup-tilde-expansion-tests (push) Has been cancelled
Support OS using musl (#284)
Fixes: #278
2025-02-17 10:32:34 +01:00

77 lines
1.9 KiB
TypeScript

import * as exec from "@actions/exec";
import * as core from "@actions/core";
export type Platform =
| "unknown-linux-gnu"
| "unknown-linux-musl"
| "unknown-linux-musleabihf"
| "apple-darwin"
| "pc-windows-msvc";
export type Architecture =
| "i686"
| "x86_64"
| "aarch64"
| "s390x"
| "powerpc64le";
export function getArch(): Architecture | undefined {
const arch = process.arch;
const archMapping: { [key: string]: Architecture } = {
ia32: "i686",
x64: "x86_64",
arm64: "aarch64",
s390x: "s390x",
ppc64: "powerpc64le",
};
if (arch in archMapping) {
return archMapping[arch];
}
}
export async function getPlatform(): Promise<Platform | undefined> {
const processPlatform = process.platform;
const platformMapping: { [key: string]: Platform } = {
linux: "unknown-linux-gnu",
darwin: "apple-darwin",
win32: "pc-windows-msvc",
};
if (processPlatform in platformMapping) {
const platform = platformMapping[processPlatform];
if (platform === "unknown-linux-gnu") {
const isMusl = await isMuslOs();
return isMusl ? "unknown-linux-musl" : platform;
}
return platform;
}
}
async function isMuslOs(): Promise<boolean> {
let stdOutput = "";
let errOutput = "";
const options: exec.ExecOptions = {
silent: !core.isDebug(),
listeners: {
stdout: (data: Buffer) => {
stdOutput += data.toString();
},
stderr: (data: Buffer) => {
errOutput += data.toString();
},
},
ignoreReturnCode: true,
};
try {
const execArgs = ["--version"];
await exec.exec("ldd", execArgs, options);
return stdOutput.includes("musl") || errOutput.includes("musl");
} catch (error) {
const err = error as Error;
core.warning(
`Failed to determine glibc or musl. Falling back to glibc. Error: ${err.message}`,
);
return false;
}
}