Skip to content

Commit d53c31b

Browse files
authored
feat: add configurable cache key with template variable support (#246)
I closed [this PR](#235) by mistake so I'm reopening it.
1 parent c0b8518 commit d53c31b

9 files changed

Lines changed: 11498 additions & 2864 deletions

File tree

.github/workflows/test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ jobs:
105105
exit 1
106106
if: ${{ steps.bad.outcome != 'failure' }}
107107

108+
custom_cache_key:
109+
runs-on: ubuntu-latest
110+
steps:
111+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
112+
- name: Setup mise with custom cache key
113+
uses: ./
114+
with:
115+
cache_key: "custom-{{platform}}-{{install_args_hash}}-${{ github.run_id }}"
116+
install_args: "jq@1.7.1"
117+
mise_toml: |
118+
[tools]
119+
jq = "1.7.1"
120+
- run: mise --version
121+
- run: mise x jq -- jq --version
122+
- run: which jq
123+
- run: jq --version
124+
108125
fetch_from_github:
109126
runs-on: ubuntu-latest
110127
steps:

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,58 @@ jobs:
4242
- run: node ./my_app.js
4343
```
4444
45+
## Cache Configuration
46+
47+
You can customize the cache key used by the action:
48+
49+
```yaml
50+
- uses: jdx/mise-action@v2
51+
with:
52+
cache_key: "my-custom-cache-key" # Override the entire cache key
53+
cache_key_prefix: "mise-v1" # Or just change the prefix (default: "mise-v0")
54+
```
55+
56+
### Template Variables in Cache Keys
57+
58+
When using `cache_key`, you can use template variables to reference internal values:
59+
60+
```yaml
61+
- uses: jdx/mise-action@v2
62+
with:
63+
cache_key: "mise-{{platform}}-{{version}}-{{file_hash}}"
64+
version: "2024.10.0"
65+
install_args: "node python"
66+
```
67+
68+
Available template variables:
69+
- `{{version}}` - The mise version (from the `version` input)
70+
- `{{cache_key_prefix}}` - The cache key prefix (from `cache_key_prefix` input or default)
71+
- `{{platform}}` - The target platform (e.g., "linux-x64", "macos-arm64")
72+
- `{{file_hash}}` - Hash of all mise configuration files
73+
- `{{mise_env}}` - The MISE_ENV environment variable value
74+
- `{{install_args_hash}}` - SHA256 hash of the sorted tools from install args
75+
- `{{default}}` - The processed default cache key (useful for extending)
76+
77+
Conditional logic is also supported using Handlebars syntax like `{{#if version}}...{{/if}}`.
78+
79+
Example using multiple variables:
80+
```yaml
81+
- uses: jdx/mise-action@v2
82+
with:
83+
cache_key: "mise-v1-{{platform}}-{{install_args_hash}}-{{file_hash}}"
84+
install_args: "node@20 python@3.12"
85+
```
86+
87+
You can also extend the default cache key:
88+
```yaml
89+
- uses: jdx/mise-action@v2
90+
with:
91+
cache_key: "{{default}}-custom-suffix"
92+
install_args: "node@20 python@3.12"
93+
```
94+
95+
This gives you full control over cache invalidation based on the specific aspects that matter to your workflow.
96+
4597
## GitHub API Rate Limits
4698

4799
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.

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ inputs:
4545
required: false
4646
default: "mise-v0"
4747
description: The prefix key to use for the cache, change this to invalidate the cache
48+
cache_key:
49+
required: false
50+
description: |
51+
Override the complete cache key (ignores all other cache key options).
52+
Supports template variables: {{version}}, {{cache_key_prefix}}, {{platform}}, {{file_hash}},
53+
{{mise_env}}, {{install_args_hash}}, {{default}} and conditional logic like {{#if version}}...{{/if}}
4854
experimental:
4955
required: false
5056
default: "false"

dist/index.js

Lines changed: 11151 additions & 2740 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/licenses.txt

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)