fix(cache): exclude rust from mise cache

This commit is contained in:
Taku Kodma 2026-05-14 02:08:41 +10:00
parent 5780a89cf2
commit 1ddfb33729
No known key found for this signature in database
GPG key ID: 2FA149ECEAB1E16D
4 changed files with 86 additions and 11 deletions

View file

@ -96,9 +96,11 @@ This gives you full control over cache invalidation based on the specific aspect
### Rust and Cargo Caches
This action caches mise's own data, but it is not a replacement for a Cargo-aware
cache. For Rust projects, cache Cargo dependencies, build artifacts, and
Cargo-installed tools explicitly.
This action caches mise's own data, but it does not save Rust toolchains.
According to [mise's Rust documentation](https://mise.jdx.dev/lang/rust.html),
Rust is managed by rustup, uses `RUSTUP_HOME` and `CARGO_HOME`, and does not live
under mise's `installs` directory. For Rust projects, cache Cargo dependencies,
build artifacts, and Cargo-installed tools explicitly.
The usual setup is to run `Swatinem/rust-cache` after `mise-action`, so the cache
key can include the Rust/Cargo environment and Cargo lockfiles:

36
dist/index.js generated vendored
View file

@ -89243,6 +89243,7 @@ const MISE_CONFIG_FILE_PATTERNS = [
];
// Default cache key template
const DEFAULT_CACHE_KEY_TEMPLATE = '{{cache_key_prefix}}-{{platform}}{{#if version}}-{{version}}{{/if}}{{#if mise_env}}-{{mise_env}}{{/if}}{{#if install_args_hash}}-{{install_args_hash}}{{/if}}-{{#if file_hash}}{{file_hash}}{{else}}no-config{{/if}}';
const RUST_CACHE_PATHS = [path$1.join('installs', 'rust')];
async function run() {
try {
await setToolVersions();
@ -89612,12 +89613,39 @@ async function saveCache(cacheKey) {
if (!fs.existsSync(cachePath)) {
throw new Error(`Cache folder path does not exist on disk: ${cachePath}`);
}
const cacheId = await saveCache$1([cachePath], cacheKey);
if (cacheId === -1)
return;
info(`Cache saved from ${cachePath} with key: ${cacheKey}`);
const excludedPaths = await stageRustCachePaths(cachePath);
try {
const cacheId = await saveCache$1([cachePath], cacheKey);
if (cacheId === -1)
return;
info(`Cache saved from ${cachePath} with key: ${cacheKey}`);
}
finally {
await restoreRustCachePaths(excludedPaths);
}
});
}
async function stageRustCachePaths(cachePath) {
const stagedPaths = [];
for (const relativePath of RUST_CACHE_PATHS) {
const originalPath = path$1.join(cachePath, relativePath);
if (!fs.existsSync(originalPath))
continue;
const stagedPath = path$1.join(path$1.dirname(cachePath), `${path$1.basename(cachePath)}-excluded-${relativePath.replaceAll(path$1.sep, '-')}-${process.pid}-${Date.now()}`);
info(`Excluding ${originalPath} from mise cache`);
await fs.promises.rename(originalPath, stagedPath);
stagedPaths.push({ originalPath, stagedPath });
}
return stagedPaths;
}
async function restoreRustCachePaths(stagedPaths) {
for (const { originalPath, stagedPath } of stagedPaths.reverse()) {
if (!fs.existsSync(stagedPath))
continue;
await fs.promises.mkdir(path$1.dirname(originalPath), { recursive: true });
await fs.promises.rename(stagedPath, originalPath);
}
}
async function getTarget() {
const arch = process.arch === 'arm' ? 'armv7' : process.arch;
switch (process.platform) {

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -42,6 +42,8 @@ const MISE_CONFIG_FILE_PATTERNS = [
const DEFAULT_CACHE_KEY_TEMPLATE =
'{{cache_key_prefix}}-{{platform}}{{#if version}}-{{version}}{{/if}}{{#if mise_env}}-{{mise_env}}{{/if}}{{#if install_args_hash}}-{{install_args_hash}}{{/if}}-{{#if file_hash}}{{file_hash}}{{else}}no-config{{/if}}'
const RUST_CACHE_PATHS = [path.join('installs', 'rust')]
async function run(): Promise<void> {
try {
await setToolVersions()
@ -475,13 +477,56 @@ async function saveCache(cacheKey: string): Promise<void> {
throw new Error(`Cache folder path does not exist on disk: ${cachePath}`)
}
const cacheId = await cache.saveCache([cachePath], cacheKey)
if (cacheId === -1) return
const excludedPaths = await stageRustCachePaths(cachePath)
try {
const cacheId = await cache.saveCache([cachePath], cacheKey)
if (cacheId === -1) return
core.info(`Cache saved from ${cachePath} with key: ${cacheKey}`)
core.info(`Cache saved from ${cachePath} with key: ${cacheKey}`)
} finally {
await restoreRustCachePaths(excludedPaths)
}
})
}
type StagedCachePath = {
originalPath: string
stagedPath: string
}
async function stageRustCachePaths(
cachePath: string
): Promise<StagedCachePath[]> {
const stagedPaths: StagedCachePath[] = []
for (const relativePath of RUST_CACHE_PATHS) {
const originalPath = path.join(cachePath, relativePath)
if (!fs.existsSync(originalPath)) continue
const stagedPath = path.join(
path.dirname(cachePath),
`${path.basename(cachePath)}-excluded-${relativePath.replaceAll(path.sep, '-')}-${process.pid}-${Date.now()}`
)
core.info(`Excluding ${originalPath} from mise cache`)
await fs.promises.rename(originalPath, stagedPath)
stagedPaths.push({ originalPath, stagedPath })
}
return stagedPaths
}
async function restoreRustCachePaths(
stagedPaths: StagedCachePath[]
): Promise<void> {
for (const { originalPath, stagedPath } of stagedPaths.reverse()) {
if (!fs.existsSync(stagedPath)) continue
await fs.promises.mkdir(path.dirname(originalPath), { recursive: true })
await fs.promises.rename(stagedPath, originalPath)
}
}
async function getTarget(): Promise<string> {
const arch = process.arch === 'arm' ? 'armv7' : process.arch
switch (process.platform) {