Skip to content
Closed
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
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,32 @@ jobs:
- run: which jq
- run: jq --version

rust_cache_setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Setup mise with Rust cache paths
uses: ./
with:
install: false
cache_save: false
cache_key: "rust-cache-setup-${{ github.run_id }}"
cache_rust: true
- name: Check Rust cache paths
run: |
if [ -n "${MISE_DATA_DIR:-}" ]; then
mise_data_dir="$MISE_DATA_DIR"
elif [ -n "${XDG_DATA_HOME:-}" ]; then
mise_data_dir="$XDG_DATA_HOME/mise"
else
mise_data_dir="$HOME/.local/share/mise"
fi

test "$MISE_RUSTUP_HOME" = "$mise_data_dir/rustup"
test "$MISE_CARGO_HOME" = "$mise_data_dir/cargo"
test -d "$MISE_RUSTUP_HOME"
test -d "$MISE_CARGO_HOME"

fetch_from_github:
runs-on: ubuntu-latest
steps:
Expand All @@ -153,6 +179,7 @@ jobs:
- specific_version
- checksum_failure
- custom_cache_key
- rust_cache_setup
- fetch_from_github
runs-on: ubuntu-latest
timeout-minutes: 1
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
install: true # [default: true] run `mise install`
install_args: "bun" # [default: ""] additional arguments to `mise install`
cache: true # [default: true] cache mise using GitHub's cache
cache_rust: false # [default: false] also cache Rust toolchains installed by mise
experimental: true # [default: false] enable experimental features
log_level: debug # [default: info] log level
# automatically write this .tool-versions file
Expand Down Expand Up @@ -72,6 +73,7 @@ Available template variables:
- `{{file_hash}}` - Hash of all mise configuration files
- `{{mise_env}}` - The MISE_ENV environment variable value
- `{{install_args_hash}}` - SHA256 hash of the sorted tools from install args
- `{{cache_rust}}` - Whether the Rust toolchain cache integration is enabled
- `{{default}}` - The processed default cache key (useful for extending)

Conditional logic is also supported using Handlebars syntax like `{{#if version}}...{{/if}}`.
Expand All @@ -94,6 +96,38 @@ You can also extend the default cache key:

This gives you full control over cache invalidation based on the specific aspects that matter to your workflow.

### Rust Toolchain Cache

By default, mise-action only caches mise's data directory. Rust is different from most mise tools because mise delegates Rust installation to rustup, which stores toolchains in `RUSTUP_HOME` and cargo/rustup proxy binaries in `CARGO_HOME/bin`. That state may live outside the mise data directory, so a restored mise cache can otherwise make `mise install` think Rust is present while components such as `rustfmt` or `clippy` are missing.

If mise is responsible for installing Rust in your workflow, opt in to Rust toolchain caching:

```yaml
- uses: jdx/mise-action@v4
with:
cache_rust: true
```

When enabled, the action exports `MISE_RUSTUP_HOME` and `MISE_CARGO_HOME` to directories under the mise data dir before cache restore and install. Those directories are then restored and saved with the normal mise cache. With the default `env: true`, mise may also export `RUSTUP_HOME` and `CARGO_HOME` for later workflow steps so plain `cargo`, `rustfmt`, and `clippy` commands use the same cached homes. The default cache key includes a `-rust` segment when this option is enabled so Rust-enabled caches do not reuse older mise-only caches. If you override `cache_key`, include `{{cache_rust}}` or otherwise invalidate that key when enabling this option.

This cache is intended for the Rust toolchain state that mise needs to restore: rustup toolchains and metadata in `RUSTUP_HOME`, plus cargo/rustup proxy binaries and Cargo-installed tool metadata in `CARGO_HOME`. `CARGO_HOME` can also contain registry and git dependency caches, but the mise-action cache key is based on mise configuration, not `Cargo.lock`, and mise-action saves before later workflow build steps run. Do not use `cache_rust` as a replacement for a Cargo dependency or `target` cache.

Use `cache_rust` with `Swatinem/rust-cache` when mise installs Rust and you want rust-cache to manage Cargo registry, git dependency, and `target` build artifact caching:

```yaml
- uses: jdx/mise-action@v4
with:
cache_rust: true

- uses: Swatinem/rust-cache@v2
with:
# Let mise-action own rustup/cargo proxy binaries and Cargo tools installed by mise.
# Remove this line if you want rust-cache to cache Cargo binaries installed later in the job.
cache-bin: "false"
```

Put `Swatinem/rust-cache` after mise-action so it sees the Rust version and `CARGO_HOME` exported by mise. Leave `cache_rust` as `false` when Rust is installed by another action such as `rustup` or `actions-rust-lang/setup-rust-toolchain`, and you use mise only for non-Rust tools.

## GitHub API Rate Limits

When installing tools hosted on GitHub (like `gh`, `node`, `bun`, etc.), mise needs to make API calls to GitHub's releases API. Without authentication, these calls are subject to GitHub's rate limit of 60 requests per hour, which can cause installation failures.
Expand Down
25 changes: 24 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,31 @@ inputs:
description: |
Override the complete cache key (ignores all other cache key options).
Supports template variables: {{version}}, {{cache_key_prefix}}, {{platform}}, {{file_hash}},
{{mise_env}}, {{install_args_hash}}, {{default}}, {{env.VAR_NAME}} for environment variables,
{{mise_env}}, {{install_args_hash}}, {{cache_rust}}, {{default}}, {{env.VAR_NAME}} for environment variables,
and conditional logic like {{#if version}}...{{/if}}
cache_rust:
required: false
default: "false"
description: |
Opt in to caching Rust toolchains installed by mise's Rust backend.

When `true`, the action exports `MISE_RUSTUP_HOME` and `MISE_CARGO_HOME`
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use asdf-rust for this behavior

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't use rustup, so it can't support components or other options.
I can make a vfox plugin and use it, but I think it's better if we can support Rust in mise-action. Currently, it just doesn't work properly.
Should we fix mise itself to detect broken Rust in installs/rust? I'm not sure if we can, but it might be better; I can cache the default RUSTUP_HOME and CARGO_HOME if I would like to.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk, but I don't think "cache rust" is really communicating what this is doing. I don't think I want to support this model in any case though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'll have a look at some other solutions.

to directories under the mise data dir before restoring the mise cache.
This lets the existing mise cache save/restore rustup toolchains,
rustup metadata, and cargo/rustup proxy binaries that mise needs for
Rust components such as rustfmt and clippy.

With the default `env: true`, mise may also export `RUSTUP_HOME` and
`CARGO_HOME` for later workflow steps so plain `cargo`, `rustfmt`, and
`clippy` commands use the same cached homes.

This is a Rust toolchain/proxy cache, not a Cargo dependency or build
cache. Use it with Swatinem/rust-cache when mise installs Rust and
rust-cache should own Cargo registry, git dependency, and target caches.

Default `false` keeps existing workflows unchanged, especially jobs that
install Rust with rustup, setup-rust-toolchain, or another standard Rust
action and use mise only for other tools.
experimental:
required: false
default: "false"
Expand Down
91 changes: 86 additions & 5 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.

Loading
Loading