Fix alpine container installation (#189)

* Change test tool for future alpine CI testing

* replace node with jq as it doesnt require any build on alpine

* Fix alpine musl container install

* add tests around mise install in alpine container

* add support for musl os
Fixes: https://github.com/jdx/mise-action/issues/186

* alpine needs bash to run test.sh script

* remove unneeded logs

* Update test.yml

* Update test.yml
This commit is contained in:
Victor LEFEBVRE 2025-05-12 14:15:17 +02:00 committed by GitHub
parent d20b46e041
commit 923c9f44ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 86 additions and 42 deletions

View file

@ -24,27 +24,40 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
include:
- name: ubuntu
runs-on: ubuntu-latest
- name: macos
runs-on: macos-latest
- name: windows
runs-on: windows-latest
- name: alpine
runs-on: ubuntu-latest
container: alpine:latest
requirements: apk add --no-cache curl bash
name: ${{ matrix.name }}
runs-on: ${{ matrix.runs-on }}
container: ${{ matrix.container }}
steps:
- name: Install requirements
if: ${{ matrix.requirements }}
run: ${{ matrix.requirements }}
- uses: actions/checkout@v4
- name: Setup mise
uses: ./
with:
mise_toml: |
[tools]
node = "22.0.0"
jq = "1.7.1"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: mise --version
- run: mise x node -- node -v
- run: which node
- run: node --version
- run: mise x jq -- jq --version
- run: which jq
- run: jq --version
- run: . scripts/test.sh
shell: bash
specific_version:
runs-on: ubuntu-latest
steps:

42
dist/index.js generated vendored
View file

@ -66616,7 +66616,7 @@ async function restoreMiseCache() {
`**/.tool-versions`
].join('\n'));
const prefix = core.getInput('cache_key_prefix') || 'mise-v0';
let primaryKey = `${prefix}-${getOS()}-${os.arch()}-${fileHash}`;
let primaryKey = `${prefix}-${await getTarget()}-${fileHash}`;
if (version) {
primaryKey = `${primaryKey}-${version}`;
}
@ -66643,11 +66643,11 @@ async function restoreMiseCache() {
}
async function setupMise(version) {
const miseBinDir = path.join(miseDir(), 'bin');
const miseBinPath = path.join(miseBinDir, getOS() === 'windows' ? 'mise.exe' : 'mise');
const miseBinPath = path.join(miseBinDir, process.platform === 'win32' ? 'mise.exe' : 'mise');
if (!fs.existsSync(path.join(miseBinPath))) {
core.startGroup(version ? `Download mise@${version}` : 'Setup mise');
await fs.promises.mkdir(miseBinDir, { recursive: true });
const ext = getOS() === 'windows'
const ext = process.platform === 'win32'
? '.zip'
: version && version.startsWith('2024')
? ''
@ -66655,7 +66655,7 @@ async function setupMise(version) {
? '.tar.zst'
: '.tar.gz';
version = (version || (await latestMiseVersion())).replace(/^v/, '');
const url = `https://github.com/jdx/mise/releases/download/v${version}/mise-v${version}-${getOS()}-${os.arch()}${ext}`;
const url = `https://github.com/jdx/mise/releases/download/v${version}/mise-v${version}-${await getTarget()}${ext}`;
const archivePath = path.join(os.tmpdir(), `mise${ext}`);
switch (ext) {
case '.zip':
@ -66711,16 +66711,6 @@ async function setMiseToml() {
await writeFile('mise.toml', toml);
}
}
function getOS() {
switch (process.platform) {
case 'darwin':
return 'macos';
case 'win32':
return 'windows';
default:
return process.platform;
}
}
const testMise = async () => mise(['--version']);
const miseInstall = async () => mise([`install ${core.getInput('install_args')}`]);
const miseLs = async () => mise([`ls`]);
@ -66771,6 +66761,30 @@ async function saveCache(cacheKey) {
core.info(`Cache saved from ${cachePath} with key: ${cacheKey}`);
});
}
async function getTarget() {
let { arch } = process;
// quick overwrite to abide by release format
if (arch === 'arm')
arch = 'armv7';
switch (process.platform) {
case 'darwin':
return `macos-${arch}`;
case 'win32':
return `windows-${arch}`;
case 'linux':
return `linux-${arch}${(await isMusl()) ? '-musl' : ''}`;
default:
throw new Error(`Unsupported platform ${process.platform}`);
}
}
async function isMusl() {
// `ldd --version` always returns 1 and print to stderr
const { stderr } = await exec.getExecOutput('ldd', ['--version'], {
failOnStdErr: false,
ignoreReturnCode: true
});
return stderr.indexOf('musl') > -1;
}
/***/ }),

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -7,11 +7,12 @@ function assert_equal() {
return 1
fi
}
EXPECTED_OUTPUT="jq-1.7.1"
assert_equal "v22.0.0" "$(mise exec -- node --version)"
which node
assert_equal "$EXPECTED_OUTPUT" "$(mise exec -- jq --version)"
which jq
# windows bash does not seem to work with shims
if [[ "$(uname)" != "MINGW"* ]]; then
assert_equal "v22.0.0" "$(node --version)"
assert_equal "$EXPECTED_OUTPUT" "$(jq --version)"
fi

View file

@ -93,7 +93,7 @@ async function restoreMiseCache(): Promise<string | undefined> {
].join('\n')
)
const prefix = core.getInput('cache_key_prefix') || 'mise-v0'
let primaryKey = `${prefix}-${getOS()}-${os.arch()}-${fileHash}`
let primaryKey = `${prefix}-${await getTarget()}-${fileHash}`
if (version) {
primaryKey = `${primaryKey}-${version}`
}
@ -127,13 +127,13 @@ async function setupMise(version: string): Promise<void> {
const miseBinDir = path.join(miseDir(), 'bin')
const miseBinPath = path.join(
miseBinDir,
getOS() === 'windows' ? 'mise.exe' : 'mise'
process.platform === 'win32' ? 'mise.exe' : 'mise'
)
if (!fs.existsSync(path.join(miseBinPath))) {
core.startGroup(version ? `Download mise@${version}` : 'Setup mise')
await fs.promises.mkdir(miseBinDir, { recursive: true })
const ext =
getOS() === 'windows'
process.platform === 'win32'
? '.zip'
: version && version.startsWith('2024')
? ''
@ -141,7 +141,7 @@ async function setupMise(version: string): Promise<void> {
? '.tar.zst'
: '.tar.gz'
version = (version || (await latestMiseVersion())).replace(/^v/, '')
const url = `https://github.com/jdx/mise/releases/download/v${version}/mise-v${version}-${getOS()}-${os.arch()}${ext}`
const url = `https://github.com/jdx/mise/releases/download/v${version}/mise-v${version}-${await getTarget()}${ext}`
const archivePath = path.join(os.tmpdir(), `mise${ext}`)
switch (ext) {
case '.zip':
@ -201,17 +201,6 @@ async function setMiseToml(): Promise<void> {
}
}
function getOS(): string {
switch (process.platform) {
case 'darwin':
return 'macos'
case 'win32':
return 'windows'
default:
return process.platform
}
}
const testMise = async (): Promise<number> => mise(['--version'])
const miseInstall = async (): Promise<number> =>
mise([`install ${core.getInput('install_args')}`])
@ -271,3 +260,30 @@ async function saveCache(cacheKey: string): Promise<void> {
core.info(`Cache saved from ${cachePath} with key: ${cacheKey}`)
})
}
async function getTarget(): Promise<string> {
let { arch } = process
// quick overwrite to abide by release format
if (arch === 'arm') arch = 'armv7' as NodeJS.Architecture
switch (process.platform) {
case 'darwin':
return `macos-${arch}`
case 'win32':
return `windows-${arch}`
case 'linux':
return `linux-${arch}${(await isMusl()) ? '-musl' : ''}`
default:
throw new Error(`Unsupported platform ${process.platform}`)
}
}
async function isMusl() {
// `ldd --version` always returns 1 and print to stderr
const { stderr } = await exec.getExecOutput('ldd', ['--version'], {
failOnStdErr: false,
ignoreReturnCode: true
})
return stderr.indexOf('musl') > -1
}