|
| 1 | +name: Setup mise |
| 2 | +description: Install mise tools from SHA256-pinned binaries, with CI-layer caching. |
| 3 | +inputs: |
| 4 | + install-args: |
| 5 | + description: Tool names or extra arguments passed to mise install. --locked is added by default. |
| 6 | + required: false |
| 7 | + default: "" |
| 8 | + locked: |
| 9 | + description: Whether to pass --locked to mise install. |
| 10 | + required: false |
| 11 | + default: "true" |
| 12 | + cache-key-prefix: |
| 13 | + description: Prefix for mise tool cache keys. |
| 14 | + required: false |
| 15 | + default: mise-ci-v1 |
| 16 | + mise-version: |
| 17 | + description: mise version to install. |
| 18 | + required: false |
| 19 | + default: "2026.5.12" |
| 20 | + mise-sha256: |
| 21 | + description: SHA256 checksum for the mise binary. |
| 22 | + required: false |
| 23 | + default: "" |
| 24 | + use-cache: |
| 25 | + description: Whether to restore and save mise tool caches. |
| 26 | + required: false |
| 27 | + default: "true" |
| 28 | +runs: |
| 29 | + using: composite |
| 30 | + steps: |
| 31 | + - name: Compute mise cache key |
| 32 | + id: cache-key |
| 33 | + shell: bash |
| 34 | + env: |
| 35 | + CACHE_KEY_PREFIX: ${{ inputs.cache-key-prefix }} |
| 36 | + INPUT_INSTALL_ARGS: ${{ inputs.install-args }} |
| 37 | + INPUT_LOCKED: ${{ inputs.locked }} |
| 38 | + MISE_VERSION: ${{ inputs.mise-version }} |
| 39 | + RUNNER_ARCH: ${{ runner.arch }} |
| 40 | + RUNNER_OS: ${{ runner.os }} |
| 41 | + run: | |
| 42 | + set -euo pipefail |
| 43 | +
|
| 44 | + case "${INPUT_LOCKED}" in |
| 45 | + true) |
| 46 | + if [[ -n "${INPUT_INSTALL_ARGS}" ]]; then |
| 47 | + install_args="--locked ${INPUT_INSTALL_ARGS}" |
| 48 | + else |
| 49 | + install_args="--locked" |
| 50 | + fi |
| 51 | + ;; |
| 52 | + false) |
| 53 | + install_args="${INPUT_INSTALL_ARGS}" |
| 54 | + ;; |
| 55 | + *) |
| 56 | + echo "::error::locked must be true or false." |
| 57 | + exit 1 |
| 58 | + ;; |
| 59 | + esac |
| 60 | +
|
| 61 | + install_args_hash="$(printf '%s' "$install_args" | git hash-object --stdin)" |
| 62 | + files_hash="$(git hash-object mise.toml mise.lock | git hash-object --stdin)" |
| 63 | + key="${CACHE_KEY_PREFIX}-${RUNNER_OS}-${RUNNER_ARCH}-${MISE_VERSION}-${install_args_hash}-${files_hash}" |
| 64 | + restore_key="${CACHE_KEY_PREFIX}-${RUNNER_OS}-${RUNNER_ARCH}-${MISE_VERSION}-${install_args_hash}-" |
| 65 | +
|
| 66 | + { |
| 67 | + echo "install-args<<EOF" |
| 68 | + echo "${install_args}" |
| 69 | + echo "EOF" |
| 70 | + echo "key=$key" |
| 71 | + echo "restore-key=$restore_key" |
| 72 | + } >> "$GITHUB_OUTPUT" |
| 73 | +
|
| 74 | + - name: Select mise checksum |
| 75 | + id: checksum |
| 76 | + shell: bash |
| 77 | + env: |
| 78 | + CHECKSUMS_FILE: ${{ github.action_path }}/checksums.toml |
| 79 | + INPUT_MISE_SHA256: ${{ inputs.mise-sha256 }} |
| 80 | + MISE_CHECKSUM_SCRIPT: ${{ github.workspace }}/scripts/mise_checksum.sh |
| 81 | + MISE_VERSION: ${{ inputs.mise-version }} |
| 82 | + RUNNER_ARCH: ${{ runner.arch }} |
| 83 | + RUNNER_OS: ${{ runner.os }} |
| 84 | + run: | |
| 85 | + set -euo pipefail |
| 86 | +
|
| 87 | + checksum="${INPUT_MISE_SHA256}" |
| 88 | + if [[ -z "${checksum}" ]]; then |
| 89 | + case "${RUNNER_OS}-${RUNNER_ARCH}" in |
| 90 | + Linux-X64) |
| 91 | + target="linux-x64" |
| 92 | + ;; |
| 93 | + Linux-ARM64) |
| 94 | + target="linux-arm64" |
| 95 | + ;; |
| 96 | + macOS-X64) |
| 97 | + target="macos-x64" |
| 98 | + ;; |
| 99 | + macOS-ARM64) |
| 100 | + target="macos-arm64" |
| 101 | + ;; |
| 102 | + Windows-X64) |
| 103 | + target="windows-x64" |
| 104 | + ;; |
| 105 | + *) |
| 106 | + echo "::error::No mise checksum is pinned for ${RUNNER_OS}-${RUNNER_ARCH}." |
| 107 | + exit 1 |
| 108 | + ;; |
| 109 | + esac |
| 110 | +
|
| 111 | + checksum="$("${MISE_CHECKSUM_SCRIPT}" "${CHECKSUMS_FILE}" "${MISE_VERSION}" "${target}")" |
| 112 | + if [[ -z "${checksum}" ]]; then |
| 113 | + echo "::error::No mise checksum is pinned for mise ${MISE_VERSION} on ${target}." |
| 114 | + exit 1 |
| 115 | + fi |
| 116 | + fi |
| 117 | +
|
| 118 | + echo "sha256=${checksum}" >> "$GITHUB_OUTPUT" |
| 119 | +
|
| 120 | + - name: Configure mise data directory |
| 121 | + id: mise-data-dir |
| 122 | + shell: bash |
| 123 | + env: |
| 124 | + RUNNER_OS: ${{ runner.os }} |
| 125 | + run: | # zizmor: ignore[github-env] MISE_DATA_DIR uses only runner-provided paths. |
| 126 | + set -euo pipefail |
| 127 | +
|
| 128 | + if [[ "${RUNNER_OS}" == "Windows" ]]; then |
| 129 | + data_dir="${LOCALAPPDATA:-${USERPROFILE}\\AppData\\Local}\\mise" |
| 130 | + else |
| 131 | + data_dir="${RUNNER_TEMP}/mise-data" |
| 132 | + fi |
| 133 | +
|
| 134 | + { |
| 135 | + printf 'path=%s\n' "${data_dir}" |
| 136 | + } >> "$GITHUB_OUTPUT" |
| 137 | + printf 'MISE_DATA_DIR=%s\n' "${data_dir}" >> "$GITHUB_ENV" |
| 138 | +
|
| 139 | + - name: Cache mise tools |
| 140 | + if: ${{ inputs.use-cache == 'true' && github.ref == 'refs/heads/main' }} |
| 141 | + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 142 | + with: |
| 143 | + path: | |
| 144 | + ~/.cache/mise |
| 145 | + ${{ steps.mise-data-dir.outputs.path }} |
| 146 | + key: ${{ steps.cache-key.outputs.key }} |
| 147 | + restore-keys: | |
| 148 | + ${{ steps.cache-key.outputs.restore-key }} |
| 149 | +
|
| 150 | + - name: Restore mise tools |
| 151 | + if: ${{ inputs.use-cache == 'true' && github.ref != 'refs/heads/main' }} |
| 152 | + uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 153 | + with: |
| 154 | + path: | |
| 155 | + ~/.cache/mise |
| 156 | + ${{ steps.mise-data-dir.outputs.path }} |
| 157 | + key: ${{ steps.cache-key.outputs.key }} |
| 158 | + restore-keys: | |
| 159 | + ${{ steps.cache-key.outputs.restore-key }} |
| 160 | +
|
| 161 | + - name: Install mise tools |
| 162 | + uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4.0.1 |
| 163 | + with: |
| 164 | + version: ${{ inputs.mise-version }} |
| 165 | + sha256: ${{ steps.checksum.outputs.sha256 }} |
| 166 | + mise_dir: ${{ steps.mise-data-dir.outputs.path }} |
| 167 | + install_args: ${{ steps.cache-key.outputs.install-args }} |
| 168 | + cache: "false" |
0 commit comments