diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 01600df..22bce1a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -200,7 +200,6 @@ jobs: exit 1 fi shell: bash - test-malformed-pyproject-file-fallback: runs-on: ubuntu-latest steps: @@ -212,3 +211,13 @@ jobs: pyproject-file: "__tests__/fixtures/malformed-pyproject-toml-project/pyproject.toml" - run: uv sync working-directory: __tests__/fixtures/uv-project + test-musl: + runs-on: ubuntu-latest + container: alpine + steps: + - uses: actions/checkout@v4 + - name: Install latest version + uses: ./ + - run: apk add python3 + - run: uv sync + working-directory: __tests__/fixtures/uv-project diff --git a/dist/save-cache/index.js b/dist/save-cache/index.js index c15d9e9..a97eb47 100644 --- a/dist/save-cache/index.js +++ b/dist/save-cache/index.js @@ -91494,7 +91494,8 @@ async function computeKeys() { } const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : ""; const pythonVersion = await getPythonVersion(); - return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${pythonVersion}${cacheDependencyPathHash}${suffix}`; + const platform = await (0, platforms_1.getPlatform)(); + return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${platform}-${pythonVersion}${cacheDependencyPathHash}${suffix}`; } async function getPythonVersion() { if (inputs_1.pythonVersion !== "") { @@ -91847,13 +91848,48 @@ function expandTilde(input) { /***/ }), /***/ 8361: -/***/ ((__unused_webpack_module, exports) => { +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getArch = getArch; exports.getPlatform = getPlatform; +const exec = __importStar(__nccwpck_require__(5236)); +const core = __importStar(__nccwpck_require__(7484)); function getArch() { const arch = process.arch; const archMapping = { @@ -91867,15 +91903,46 @@ function getArch() { return archMapping[arch]; } } -function getPlatform() { - const platform = process.platform; +async function getPlatform() { + const processPlatform = process.platform; const platformMapping = { linux: "unknown-linux-gnu", darwin: "apple-darwin", win32: "pc-windows-msvc", }; - if (platform in platformMapping) { - return platformMapping[platform]; + 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() { + let stdOutput = ""; + let errOutput = ""; + const options = { + silent: !core.isDebug(), + listeners: { + stdout: (data) => { + stdOutput += data.toString(); + }, + stderr: (data) => { + 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; + core.warning(`Failed to determine glibc or musl. Falling back to glibc. Error: ${err.message}`); + return false; } } diff --git a/dist/setup/index.js b/dist/setup/index.js index 29ddfc2..713fe51 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -92397,7 +92397,8 @@ async function computeKeys() { } const suffix = inputs_1.cacheSuffix ? `-${inputs_1.cacheSuffix}` : ""; const pythonVersion = await getPythonVersion(); - return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${(0, platforms_1.getPlatform)()}-${pythonVersion}${cacheDependencyPathHash}${suffix}`; + const platform = await (0, platforms_1.getPlatform)(); + return `setup-uv-${CACHE_VERSION}-${(0, platforms_1.getArch)()}-${platform}-${pythonVersion}${cacheDependencyPathHash}${suffix}`; } async function getPythonVersion() { if (inputs_1.pythonVersion !== "") { @@ -95383,7 +95384,7 @@ const exec = __importStar(__nccwpck_require__(5236)); const node_fs_1 = __importDefault(__nccwpck_require__(3024)); const pyproject_1 = __nccwpck_require__(3929); async function run() { - const platform = (0, platforms_1.getPlatform)(); + const platform = await (0, platforms_1.getPlatform)(); const arch = (0, platforms_1.getArch)(); try { if (platform === undefined) { @@ -95635,13 +95636,48 @@ function expandTilde(input) { /***/ }), /***/ 8361: -/***/ ((__unused_webpack_module, exports) => { +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getArch = getArch; exports.getPlatform = getPlatform; +const exec = __importStar(__nccwpck_require__(5236)); +const core = __importStar(__nccwpck_require__(7484)); function getArch() { const arch = process.arch; const archMapping = { @@ -95655,15 +95691,46 @@ function getArch() { return archMapping[arch]; } } -function getPlatform() { - const platform = process.platform; +async function getPlatform() { + const processPlatform = process.platform; const platformMapping = { linux: "unknown-linux-gnu", darwin: "apple-darwin", win32: "pc-windows-msvc", }; - if (platform in platformMapping) { - return platformMapping[platform]; + 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() { + let stdOutput = ""; + let errOutput = ""; + const options = { + silent: !core.isDebug(), + listeners: { + stdout: (data) => { + stdOutput += data.toString(); + }, + stderr: (data) => { + 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; + core.warning(`Failed to determine glibc or musl. Falling back to glibc. Error: ${err.message}`); + return false; } } diff --git a/src/cache/restore-cache.ts b/src/cache/restore-cache.ts index 76a616d..8309f59 100644 --- a/src/cache/restore-cache.ts +++ b/src/cache/restore-cache.ts @@ -53,7 +53,8 @@ async function computeKeys(): Promise { } const suffix = cacheSuffix ? `-${cacheSuffix}` : ""; const pythonVersion = await getPythonVersion(); - return `setup-uv-${CACHE_VERSION}-${getArch()}-${getPlatform()}-${pythonVersion}${cacheDependencyPathHash}${suffix}`; + const platform = await getPlatform(); + return `setup-uv-${CACHE_VERSION}-${getArch()}-${platform}-${pythonVersion}${cacheDependencyPathHash}${suffix}`; } async function getPythonVersion(): Promise { diff --git a/src/setup-uv.ts b/src/setup-uv.ts index a7ff66e..c6e1df9 100644 --- a/src/setup-uv.ts +++ b/src/setup-uv.ts @@ -30,7 +30,7 @@ import fs from "node:fs"; import { getUvVersionFromConfigFile } from "./utils/pyproject"; async function run(): Promise { - const platform = getPlatform(); + const platform = await getPlatform(); const arch = getArch(); try { diff --git a/src/utils/platforms.ts b/src/utils/platforms.ts index b81078a..4604407 100644 --- a/src/utils/platforms.ts +++ b/src/utils/platforms.ts @@ -1,3 +1,5 @@ +import * as exec from "@actions/exec"; +import * as core from "@actions/core"; export type Platform = | "unknown-linux-gnu" | "unknown-linux-musl" @@ -26,15 +28,49 @@ export function getArch(): Architecture | undefined { } } -export function getPlatform(): Platform | undefined { - const platform = process.platform; +export async function getPlatform(): Promise { + const processPlatform = process.platform; const platformMapping: { [key: string]: Platform } = { linux: "unknown-linux-gnu", darwin: "apple-darwin", win32: "pc-windows-msvc", }; - if (platform in platformMapping) { - return platformMapping[platform]; + 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 { + 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; } }