fix: use tar.gz if zstd is not available (#159)

Fixes #155
This commit is contained in:
jdx 2024-12-30 10:44:25 -06:00 committed by GitHub
parent 249c01ba27
commit b82835fe1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 61 additions and 25 deletions

43
dist/index.js generated vendored
View file

@ -71596,30 +71596,47 @@ async function setupMise(version) {
? '.zip' ? '.zip'
: version && version.startsWith('2024') : version && version.startsWith('2024')
? '' ? ''
: '.tar.zst'; : (await zstdInstalled())
? '.tar.zst'
: '.tar.gz';
version = (version || (await latestMiseVersion())).replace(/^v/, ''); 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}-${getOS()}-${os.arch()}${ext}`;
const archivePath = path.join(os.tmpdir(), `mise${ext}`); const archivePath = path.join(os.tmpdir(), `mise${ext}`);
if (getOS() === 'windows') { switch (ext) {
await exec.exec('curl', ['-fsSL', url, '--output', archivePath]); case '.zip':
await exec.exec('unzip', [archivePath, '-d', os.tmpdir()]); await exec.exec('curl', ['-fsSL', url, '--output', archivePath]);
await io.mv(path.join(os.tmpdir(), 'mise/bin/mise.exe'), miseBinPath); await exec.exec('unzip', [archivePath, '-d', os.tmpdir()]);
} await io.mv(path.join(os.tmpdir(), 'mise/bin/mise.exe'), miseBinPath);
else { break;
if (ext === '') { case '.tar.zst':
await exec.exec('sh', ['-c', `curl -fsSL ${url} > ${miseBinPath}`]);
await exec.exec('chmod', ['+x', miseBinPath]);
}
else {
await exec.exec('sh', [ await exec.exec('sh', [
'-c', '-c',
`curl -fsSL ${url} | tar --zstd -xf - -C ${os.tmpdir()} && mv ${os.tmpdir()}/mise/bin/mise ${miseBinPath}` `curl -fsSL ${url} | tar --zstd -xf - -C ${os.tmpdir()} && mv ${os.tmpdir()}/mise/bin/mise ${miseBinPath}`
]); ]);
} break;
case '.tar.gz':
await exec.exec('sh', [
'-c',
`curl -fsSL ${url} | tar -xzf - -C ${os.tmpdir()} && mv ${os.tmpdir()}/mise/bin/mise ${miseBinPath}`
]);
break;
default:
await exec.exec('sh', ['-c', `curl -fsSL ${url} > ${miseBinPath}`]);
await exec.exec('chmod', ['+x', miseBinPath]);
break;
} }
} }
core.addPath(miseBinDir); core.addPath(miseBinDir);
} }
async function zstdInstalled() {
try {
await exec.exec('zstd', ['--version']);
return true;
}
catch {
return false;
}
}
async function latestMiseVersion() { async function latestMiseVersion() {
const rsp = await exec.getExecOutput('curl', [ const rsp = await exec.getExecOutput('curl', [
'-fsSL', '-fsSL',

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -135,29 +135,48 @@ async function setupMise(version: string): Promise<void> {
? '.zip' ? '.zip'
: version && version.startsWith('2024') : version && version.startsWith('2024')
? '' ? ''
: '.tar.zst' : (await zstdInstalled())
? '.tar.zst'
: '.tar.gz'
version = (version || (await latestMiseVersion())).replace(/^v/, '') 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}-${getOS()}-${os.arch()}${ext}`
const archivePath = path.join(os.tmpdir(), `mise${ext}`) const archivePath = path.join(os.tmpdir(), `mise${ext}`)
if (getOS() === 'windows') { switch (ext) {
await exec.exec('curl', ['-fsSL', url, '--output', archivePath]) case '.zip':
await exec.exec('unzip', [archivePath, '-d', os.tmpdir()]) await exec.exec('curl', ['-fsSL', url, '--output', archivePath])
await io.mv(path.join(os.tmpdir(), 'mise/bin/mise.exe'), miseBinPath) await exec.exec('unzip', [archivePath, '-d', os.tmpdir()])
} else { await io.mv(path.join(os.tmpdir(), 'mise/bin/mise.exe'), miseBinPath)
if (ext === '') { break
await exec.exec('sh', ['-c', `curl -fsSL ${url} > ${miseBinPath}`]) case '.tar.zst':
await exec.exec('chmod', ['+x', miseBinPath])
} else {
await exec.exec('sh', [ await exec.exec('sh', [
'-c', '-c',
`curl -fsSL ${url} | tar --zstd -xf - -C ${os.tmpdir()} && mv ${os.tmpdir()}/mise/bin/mise ${miseBinPath}` `curl -fsSL ${url} | tar --zstd -xf - -C ${os.tmpdir()} && mv ${os.tmpdir()}/mise/bin/mise ${miseBinPath}`
]) ])
} break
case '.tar.gz':
await exec.exec('sh', [
'-c',
`curl -fsSL ${url} | tar -xzf - -C ${os.tmpdir()} && mv ${os.tmpdir()}/mise/bin/mise ${miseBinPath}`
])
break
default:
await exec.exec('sh', ['-c', `curl -fsSL ${url} > ${miseBinPath}`])
await exec.exec('chmod', ['+x', miseBinPath])
break
} }
} }
core.addPath(miseBinDir) core.addPath(miseBinDir)
} }
async function zstdInstalled(): Promise<boolean> {
try {
await exec.exec('zstd', ['--version'])
return true
} catch {
return false
}
}
async function latestMiseVersion(): Promise<string> { async function latestMiseVersion(): Promise<string> {
const rsp = await exec.getExecOutput('curl', [ const rsp = await exec.getExecOutput('curl', [
'-fsSL', '-fsSL',