Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
[tools]
shellcheck = "0.9.0"
working_directory: app # [default: .] directory to run mise in
reshim: false # [default: false] run `mise reshim --all`
reshim: false # [default: false] run `mise reshim -f`
github_token: ${{ secrets.GITHUB_TOKEN }} # [default: ${{ github.token }}] GitHub token for API authentication
- run: shellcheck scripts/*.sh
test:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ inputs:
GitHub token for API authentication to avoid rate limits when installing GitHub-hosted tools.
Defaults to the automatic GitHub token.
default: ${{ github.token }}
fetch_from_github:
required: false
default: "true"
description: If true (default), fetch the mise binary from GitHub. If false and using the latest version, fetch from mise.jdx.dev instead.
outputs:
cache-hit:
description: A boolean value to indicate if a cache was hit.
Expand Down
35 changes: 14 additions & 21 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tasks.version = "npm version"

[tools]
node = '24'

45 changes: 16 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,6 @@ import * as os from 'os'
import * as path from 'path'
import axios, { isAxiosError } from 'axios'

function validateVersion(version: string): string {
if (!version) {
throw new Error('Version cannot be empty')
}

// Allow only numbers and dots for mise versions (e.g., 2024.12.7, 2.8.0)
if (!/^[0-9.]+$/.test(version)) {
throw new Error(
`Invalid version format: ${version}. Only numbers and dots are allowed.`
)
}

// Additional length check to prevent excessive input
if (version.length > 20) {
throw new Error('Version string too long')
}

return version.replace(/^v/, '') // Remove 'v' prefix if present
}

async function validateSubscription(): Promise<void> {
const API_URL = `https://agent.api.stepsecurity.io/v1/github/${process.env.GITHUB_REPOSITORY}/actions/subscription`

Expand Down Expand Up @@ -60,7 +40,8 @@ async function run(): Promise<void> {
}

const version = core.getInput('version')
await setupMise(version)
const fetchFromGitHub = core.getBooleanInput('fetch_from_github')
await setupMise(version, fetchFromGitHub)
await setEnvVars()
if (core.getBooleanInput('reshim')) {
await miseReshim()
Expand Down Expand Up @@ -178,7 +159,10 @@ async function restoreMiseCache(): Promise<string | undefined> {
core.info(`mise cache restored from key: ${cacheKey}`)
}

async function setupMise(version: string): Promise<void> {
async function setupMise(
version: string,
fetchFromGitHub = false
): Promise<void> {
const miseBinDir = path.join(miseDir(), 'bin')
const miseBinPath = path.join(
miseBinDir,
Expand All @@ -195,12 +179,15 @@ async function setupMise(version: string): Promise<void> {
: (await zstdInstalled())
? '.tar.zst'
: '.tar.gz'

// Validate version input to prevent injection attacks
const rawVersion = version || (await latestMiseVersion())
const validatedVersion = validateVersion(rawVersion)

const url = `https://github.com/jdx/mise/releases/download/v${validatedVersion}/mise-v${validatedVersion}-${await getTarget()}${ext}`
let resolvedVersion = version || (await latestMiseVersion())
resolvedVersion = resolvedVersion.replace(/^v/, '')
let url: string
if (!fetchFromGitHub && !version) {
// Only for latest version
url = `https://mise.jdx.dev/mise-latest-${await getTarget()}${ext}`
} else {
url = `https://github.com/jdx/mise/releases/download/v${resolvedVersion}/mise-v${resolvedVersion}-${await getTarget()}${ext}`
}
const archivePath = path.join(os.tmpdir(), `mise${ext}`)
switch (ext) {
case '.zip':
Expand Down Expand Up @@ -277,7 +264,7 @@ const testMise = async (): Promise<number> => mise(['--version'])
const miseInstall = async (): Promise<number> =>
mise([`install ${core.getInput('install_args')}`])
const miseLs = async (): Promise<number> => mise([`ls`])
const miseReshim = async (): Promise<number> => mise([`reshim`, `--all`])
const miseReshim = async (): Promise<number> => mise([`reshim`, `-f`])
const mise = async (args: string[]): Promise<number> =>
core.group(`Running mise ${args.join(' ')}`, async () => {
const cwd =
Expand Down
Loading