feat: support windows (#122)

This commit is contained in:
jdx 2024-09-25 16:27:52 -05:00 committed by GitHub
parent bd6a003a27
commit 5d3e058edf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 3835 additions and 3537 deletions

View file

@ -1,4 +1,5 @@
import * as cache from '@actions/cache'
import * as io from '@actions/io'
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as glob from '@actions/glob'
@ -91,23 +92,29 @@ async function restoreMiseCache(): Promise<void> {
async function setupMise(version: string | undefined): Promise<void> {
core.startGroup(version ? `Setup mise@${version}` : 'Setup mise')
const miseBinDir = path.join(miseDir(), 'bin')
await fs.promises.mkdir(miseBinDir, { recursive: true })
const url = version
? `https://mise.jdx.dev/v${version}/mise-v${version}-${getOS()}-${os.arch()}`
: `https://mise.jdx.dev/mise-latest-${getOS()}-${os.arch()}`
await fs.promises.mkdir(miseBinDir, { recursive: true })
await exec.exec('curl', [
'-fsSL',
url,
'--output',
path.join(miseBinDir, 'mise')
])
await exec.exec('chmod', ['+x', path.join(miseBinDir, 'mise')])
if (getOS() === 'windows') {
const zipPath = path.join(os.tmpdir(), 'mise.zip')
await exec.exec('curl', ['-fsSL', `${url}.zip`, '--output', zipPath])
await exec.exec('unzip', [zipPath, '-d', os.tmpdir()])
await io.mv(
path.join(os.tmpdir(), 'mise/bin/mise.exe'),
path.join(miseBinDir, 'mise.exe')
)
} else {
const output = path.join(miseBinDir, 'mise')
await exec.exec('curl', ['-fsSL', url, '--output', output])
await exec.exec('chmod', ['+x', path.join(miseBinDir, 'mise')])
}
core.addPath(miseBinDir)
}
function getExperimental(): boolean {
const experimentalString = core.getInput('experimental')
return experimentalString === 'true' ? true : false
return experimentalString === 'true'
}
async function setToolVersions(): Promise<void> {
@ -120,7 +127,7 @@ async function setToolVersions(): Promise<void> {
async function setMiseToml(): Promise<void> {
const toml = core.getInput('mise_toml')
if (toml) {
await writeFile('.mise.toml', toml)
await writeFile('mise.toml', toml)
}
}
@ -128,6 +135,8 @@ function getOS(): string {
switch (process.platform) {
case 'darwin':
return 'macos'
case 'win32':
return 'windows'
default:
return process.platform
}

View file

@ -6,9 +6,11 @@ export function miseDir(): string {
const dir = core.getState('MISE_DIR')
if (dir) return dir
const { MISE_DATA_DIR, XDG_DATA_HOME } = process.env
const { MISE_DATA_DIR, XDG_DATA_HOME, LOCALAPPDATA } = process.env
if (MISE_DATA_DIR) return MISE_DATA_DIR
if (XDG_DATA_HOME) return path.join(XDG_DATA_HOME, 'mise')
if (process.platform === 'win32' && LOCALAPPDATA)
return path.join(LOCALAPPDATA, 'mise')
return path.join(os.homedir(), '.local/share/mise')
return path.join(os.homedir(), '.local', 'share', 'mise')
}