mirror of
https://github.com/jdx/mise-action.git
synced 2026-05-14 22:00:34 +00:00
Revert "fix(cache): isolate cache keys per working_directory in monorepos" (#364)
Reverts jdx/mise-action#360
https://github.com/jdx/mise-action/issues/363
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Reverts the monorepo cache isolation change and simplifies caching to
a single cache for the entire `mise` directory.
>
> - Replace binary/tools caches with a single cache via
`restoreMiseCache`/`saveCache`; set `cache-hit` from one restore
> - Default key template drops `dir_hash`; `file_hash` computed from
repo-wide glob patterns (no `working_directory`-specific config walk)
> - Persist `PRIMARY_KEY` and `MISE_DIR` in action state; `miseDir()`
reads from state
> - Remove monorepo cache isolation workflow `test-monorepo-cache.yml`;
minor cleanup in `AGENTS.md`
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
a157c4e176. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
This commit is contained in:
parent
c53b9236f0
commit
a836e1b817
5 changed files with 80 additions and 690 deletions
219
.github/workflows/test-monorepo-cache.yml
vendored
219
.github/workflows/test-monorepo-cache.yml
vendored
|
|
@ -1,219 +0,0 @@
|
|||
# Test monorepo cache isolation: when working_directory is set, each directory
|
||||
# should get its own cache key based on its config hierarchy, not all configs
|
||||
# in the repo. This prevents cache pollution between unrelated projects.
|
||||
name: "test-monorepo-cache"
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
# Simulates a monorepo with:
|
||||
# - Root config with shared tool (actionlint)
|
||||
# - Frontend with its own tool (shfmt)
|
||||
# - Backend with its own tool (shellcheck)
|
||||
# Frontend and backend both inherit the root config.
|
||||
SETUP_MONOREPO: |
|
||||
mkdir -p apps/frontend apps/backend
|
||||
echo '[tools]' > mise.toml
|
||||
echo 'actionlint = "1"' >> mise.toml
|
||||
echo '[tools]' > apps/frontend/mise.toml
|
||||
echo 'shfmt = "3"' >> apps/frontend/mise.toml
|
||||
echo '[tools]' > apps/backend/mise.toml
|
||||
echo 'shellcheck = "0.10"' >> apps/backend/mise.toml
|
||||
|
||||
# Simple single-tool config for mise_dir tests
|
||||
SETUP_SIMPLE: |
|
||||
echo '[tools]' > mise.toml
|
||||
echo 'actionlint = "1"' >> mise.toml
|
||||
|
||||
jobs:
|
||||
# Install ONLY backend tools and save cache.
|
||||
# This cache should NOT be shared with frontend.
|
||||
install-backend:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: ${{ env.SETUP_MONOREPO }}
|
||||
- uses: ./
|
||||
with:
|
||||
working_directory: apps/backend
|
||||
cache_key_prefix: monorepo-test-${{ github.run_id }}
|
||||
|
||||
# Try to restore frontend after backend cache exists - should be cache MISS
|
||||
# since frontend has a different working_directory and thus a different cache key.
|
||||
restore-frontend:
|
||||
needs: install-backend
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: ${{ env.SETUP_MONOREPO }}
|
||||
- uses: ./
|
||||
with:
|
||||
working_directory: apps/frontend
|
||||
install: false
|
||||
cache_key_prefix: monorepo-test-${{ github.run_id }}
|
||||
- name: Verify cache isolation
|
||||
run: |
|
||||
# With the fix, frontend has a different cache key, so cache miss = no tools
|
||||
# With the bug, frontend has same key as backend, so cache hit = has shellcheck but not shfmt
|
||||
if [ -f ~/.local/share/mise/shims/shellcheck ]; then
|
||||
echo "FAIL: shellcheck found - frontend got backend's cache (shared key bug)"
|
||||
exit 1
|
||||
fi
|
||||
echo "PASS: No backend tools found - cache keys are properly isolated"
|
||||
|
||||
# Install frontend and save cache (used by unrelated-change-no-bust)
|
||||
install-frontend:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: ${{ env.SETUP_MONOREPO }}
|
||||
- uses: ./
|
||||
with:
|
||||
working_directory: apps/frontend
|
||||
cache_key_prefix: unrelated-${{ github.run_id }}
|
||||
|
||||
# Test that changing an UNRELATED directory's config does NOT bust the cache.
|
||||
# Only configs affecting the working_directory are hashed.
|
||||
unrelated-change-no-bust:
|
||||
needs: install-frontend
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: ${{ env.SETUP_MONOREPO }}
|
||||
|
||||
# Modify BACKEND config (unrelated to frontend)
|
||||
- run: echo 'jq = "1"' >> apps/backend/mise.toml
|
||||
|
||||
# Try to restore frontend - should still be a cache HIT
|
||||
- uses: ./
|
||||
with:
|
||||
working_directory: apps/frontend
|
||||
install: false
|
||||
cache_key_prefix: unrelated-${{ github.run_id }}
|
||||
|
||||
- name: Verify cache still hits after unrelated change
|
||||
run: |
|
||||
if [ ! -f ~/.local/share/mise/shims/shfmt ]; then
|
||||
echo "FAIL: shfmt missing - unrelated backend change busted frontend cache"
|
||||
exit 1
|
||||
fi
|
||||
echo "PASS: Frontend cache survived unrelated backend change"
|
||||
|
||||
# Test that changing a parent config changes the child's cache key.
|
||||
# We modify the root mise.toml and verify the cache key is different
|
||||
# (cache miss on restore attempt).
|
||||
parent-config-change:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: ${{ env.SETUP_MONOREPO }}
|
||||
|
||||
# Install frontend with original root config
|
||||
- uses: ./
|
||||
with:
|
||||
working_directory: apps/frontend
|
||||
cache_key_prefix: parent-change-${{ github.run_id }}
|
||||
|
||||
# Clear local mise state to simulate a fresh restore
|
||||
- run: rm -rf ~/.local/share/mise/installs ~/.local/share/mise/shims
|
||||
|
||||
# Modify root config (add a new tool)
|
||||
- run: echo 'taplo = "0.9"' >> mise.toml
|
||||
|
||||
# Try to restore - should be a cache MISS because root config changed
|
||||
- uses: ./
|
||||
id: restore-after-change
|
||||
with:
|
||||
working_directory: apps/frontend
|
||||
install: false
|
||||
cache_key_prefix: parent-change-${{ github.run_id }}
|
||||
|
||||
# Verify cache miss (shfmt not present because we didn't install)
|
||||
- name: Verify cache miss after parent change
|
||||
run: |
|
||||
if [ -f ~/.local/share/mise/shims/shfmt ]; then
|
||||
echo "FAIL: shfmt found - cache should have missed after parent config change"
|
||||
exit 1
|
||||
fi
|
||||
echo "PASS: Cache missed as expected after parent config change"
|
||||
|
||||
# Test that changing a lock file changes the cache key.
|
||||
# Lock files pin exact versions, so changes should bust the cache.
|
||||
lock-file-change:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: |
|
||||
mkdir -p apps/project
|
||||
echo '[tools]' > apps/project/mise.toml
|
||||
echo 'shfmt = "3"' >> apps/project/mise.toml
|
||||
echo 'lockfile = "v1"' > apps/project/mise.lock
|
||||
|
||||
# Install with original lock file
|
||||
- uses: ./
|
||||
with:
|
||||
working_directory: apps/project
|
||||
cache_key_prefix: lock-change-${{ github.run_id }}
|
||||
|
||||
# Clear local mise state
|
||||
- run: rm -rf ~/.local/share/mise/installs ~/.local/share/mise/shims
|
||||
|
||||
# Modify lock file
|
||||
- run: echo 'lockfile = "v2"' > apps/project/mise.lock
|
||||
|
||||
# Try to restore - should be cache MISS because lock file changed
|
||||
- uses: ./
|
||||
with:
|
||||
working_directory: apps/project
|
||||
install: false
|
||||
cache_key_prefix: lock-change-${{ github.run_id }}
|
||||
|
||||
- name: Verify cache miss after lock file change
|
||||
run: |
|
||||
if [ -f ~/.local/share/mise/shims/shfmt ]; then
|
||||
echo "FAIL: shfmt found - cache should have missed after lock file change"
|
||||
exit 1
|
||||
fi
|
||||
echo "PASS: Cache missed as expected after lock file change"
|
||||
|
||||
# Test that IDENTICAL content in DIFFERENT paths produces DIFFERENT cache keys.
|
||||
# This prevents hash collisions from concatenating file contents without separators.
|
||||
install-identical-content-alpha:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: |
|
||||
mkdir -p apps/alpha
|
||||
echo '[tools]' > apps/alpha/mise.toml
|
||||
echo 'shfmt = "3"' >> apps/alpha/mise.toml
|
||||
- uses: ./
|
||||
with:
|
||||
working_directory: apps/alpha
|
||||
cache_key_prefix: identical-content-${{ github.run_id }}
|
||||
|
||||
# Try to restore with IDENTICAL content but DIFFERENT path - should be cache MISS
|
||||
restore-identical-content-beta:
|
||||
needs: install-identical-content-alpha
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: |
|
||||
mkdir -p apps/beta
|
||||
# Exact same content as alpha
|
||||
echo '[tools]' > apps/beta/mise.toml
|
||||
echo 'shfmt = "3"' >> apps/beta/mise.toml
|
||||
- uses: ./
|
||||
with:
|
||||
working_directory: apps/beta
|
||||
install: false
|
||||
cache_key_prefix: identical-content-${{ github.run_id }}
|
||||
- name: Verify different paths produce different cache keys
|
||||
run: |
|
||||
if [ -f ~/.local/share/mise/shims/shfmt ]; then
|
||||
echo "FAIL: shfmt found - identical content in different path caused cache collision"
|
||||
exit 1
|
||||
fi
|
||||
echo "PASS: Identical content in different paths correctly produced different cache keys"
|
||||
Loading…
Add table
Add a link
Reference in a new issue