rtx -> mise

This commit is contained in:
Jeff Dickey 2024-01-02 16:16:49 -06:00
parent b2bd646a01
commit 2c307d8ed6
No known key found for this signature in database
GPG key ID: 584DADE86724B407
10 changed files with 118 additions and 118 deletions

View file

@ -1,18 +1,18 @@
import * as cache from '@actions/cache'
import * as core from '@actions/core'
import * as fs from 'fs'
import { rtxDir } from './utils'
import { miseDir } from './utils'
export async function run(): Promise<void> {
try {
await cacheRTXTools()
await cacheMiseTools()
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
else throw error
}
}
async function cacheRTXTools(): Promise<void> {
async function cacheMiseTools(): Promise<void> {
if (!core.getState('CACHE')) {
core.info('Skipping saving cache')
return
@ -20,7 +20,7 @@ async function cacheRTXTools(): Promise<void> {
const state = core.getState('CACHE_KEY')
const primaryKey = core.getState('PRIMARY_KEY')
const cachePath = rtxDir()
const cachePath = miseDir()
if (!fs.existsSync(cachePath)) {
throw new Error(`Cache folder path does not exist on disk: ${cachePath}`)

View file

@ -5,23 +5,23 @@ import * as glob from '@actions/glob'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import { rtxDir } from './utils'
import { miseDir } from './utils'
async function run(): Promise<void> {
try {
await setToolVersions()
await setRtxToml()
await setMiseToml()
if (core.getBooleanInput('cache')) {
await restoreRTXCache()
await restoreMiseCache()
} else {
core.setOutput('cache-hit', false)
}
const version = core.getInput('version')
await setupRTX(version)
await setupMise(version)
await setEnvVars()
await testRTX()
await testMise()
if (core.getBooleanInput('install')) {
await rtxInstall()
}
@ -39,53 +39,53 @@ async function setEnvVars(): Promise<void> {
core.exportVariable(k, v)
}
}
set('RTX_TRUSTED_CONFIG_PATHS', process.cwd())
set('RTX_YES', '1')
set('RTX_EXPERIMENTAL', getExperimental() ? '1' : '0')
set('MISE_TRUSTED_CONFIG_PATHS', process.cwd())
set('MISE_YES', '1')
set('MISE_EXPERIMENTAL', getExperimental() ? '1' : '0')
const shimsDir = path.join(rtxDir(), 'shims')
const shimsDir = path.join(miseDir(), 'shims')
core.info(`Adding ${shimsDir} to PATH`)
core.addPath(shimsDir)
}
async function restoreRTXCache(): Promise<void> {
core.startGroup('Restoring rtx cache')
const cachePath = rtxDir()
const fileHash = await glob.hashFiles(`**/.tool-versions\n**/.rtx.toml`)
const prefix = core.getInput('cache_key_prefix') || 'rtx-v0'
async function restoreMiseCache(): Promise<void> {
core.startGroup('Restoring mise cache')
const cachePath = miseDir()
const fileHash = await glob.hashFiles(`**/.tool-versions\n**/.mise.toml`)
const prefix = core.getInput('cache_key_prefix') || 'mise-v0'
const primaryKey = `${prefix}-${getOS()}-${os.arch()}-${fileHash}`
core.saveState('CACHE', core.getBooleanInput('cache_save') ?? true)
core.saveState('PRIMARY_KEY', primaryKey)
core.saveState('RTX_DIR', cachePath)
core.saveState('MISE_DIR', cachePath)
const cacheKey = await cache.restoreCache([cachePath], primaryKey)
core.setOutput('cache-hit', Boolean(cacheKey))
if (!cacheKey) {
core.info(`rtx cache not found for ${primaryKey}`)
core.info(`mise cache not found for ${primaryKey}`)
return
}
core.saveState('CACHE_KEY', cacheKey)
core.info(`rtx cache restored from key: ${cacheKey}`)
core.info(`mise cache restored from key: ${cacheKey}`)
}
async function setupRTX(version: string | undefined): Promise<void> {
core.startGroup(version ? `Setup rtx@${version}` : 'Setup rtx')
const rtxBinDir = path.join(rtxDir(), 'bin')
async function setupMise(version: string | undefined): Promise<void> {
core.startGroup(version ? `Setup mise@${version}` : 'Setup mise')
const miseBinDir = path.join(miseDir(), 'bin')
const url = version
? `https://rtx.jdx.dev/v${version}/rtx-v${version}-${getOS()}-${os.arch()}`
: `https://rtx.jdx.dev/rtx-latest-${getOS()}-${os.arch()}`
await fs.promises.mkdir(rtxBinDir, { recursive: true })
? `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(rtxBinDir, 'rtx')
path.join(miseBinDir, 'mise')
])
await exec.exec('chmod', ['+x', path.join(rtxBinDir, 'rtx')])
core.addPath(rtxBinDir)
await exec.exec('chmod', ['+x', path.join(miseBinDir, 'mise')])
core.addPath(miseBinDir)
}
function getExperimental(): boolean {
@ -100,10 +100,10 @@ async function setToolVersions(): Promise<void> {
}
}
async function setRtxToml(): Promise<void> {
const toml = core.getInput('rtx_toml')
async function setMiseToml(): Promise<void> {
const toml = core.getInput('mise_toml')
if (toml) {
await writeFile('.rtx.toml', toml)
await writeFile('.mise.toml', toml)
}
}
@ -116,12 +116,12 @@ function getOS(): string {
}
}
const testRTX = async (): Promise<number> => rtx(['--version'])
const rtxInstall = async (): Promise<number> => rtx(['install'])
const rtx = async (args: string[]): Promise<number> =>
core.group(`Running rtx ${args.join(' ')}`, async () => {
const testMise = async (): Promise<number> => mise(['--version'])
const rtxInstall = async (): Promise<number> => mise(['install'])
const mise = async (args: string[]): Promise<number> =>
core.group(`Running mise ${args.join(' ')}`, async () => {
const cwd = core.getInput('install_dir') || process.cwd()
return exec.exec('rtx', args, { cwd })
return exec.exec('mise', args, { cwd })
})
const writeFile = async (p: fs.PathLike, body: string): Promise<void> =>

View file

@ -2,13 +2,13 @@ import * as core from '@actions/core'
import * as os from 'os'
import * as path from 'path'
export function rtxDir(): string {
const dir = core.getState('RTX_DIR')
export function miseDir(): string {
const dir = core.getState('MISE_DIR')
if (dir) return dir
const { RTX_DATA_DIR, XDG_DATA_HOME } = process.env
if (RTX_DATA_DIR) return RTX_DATA_DIR
if (XDG_DATA_HOME) return path.join(XDG_DATA_HOME, 'rtx')
const { MISE_DATA_DIR, XDG_DATA_HOME } = process.env
if (MISE_DATA_DIR) return MISE_DATA_DIR
if (XDG_DATA_HOME) return path.join(XDG_DATA_HOME, 'mise')
return path.join(os.homedir(), '.local/share/rtx')
return path.join(os.homedir(), '.local/share/mise')
}