mirror of
https://github.com/jdx/mise-action.git
synced 2026-05-14 13:50:33 +00:00
Merge d6d59bb04f into 1c5f70fd40
This commit is contained in:
commit
24024dd6c5
7 changed files with 235 additions and 3 deletions
111
.github/workflows/test.yml
vendored
111
.github/workflows/test.yml
vendored
|
|
@ -147,6 +147,116 @@ jobs:
|
|||
- run: which jq
|
||||
- run: jq --version
|
||||
|
||||
mise_environment_test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
|
||||
# Test 1: Basic environment input
|
||||
- name: Setup mise with environment input
|
||||
uses: ./
|
||||
with:
|
||||
environment: preview
|
||||
mise_toml: |
|
||||
[tools]
|
||||
jq = "1.7.1"
|
||||
|
||||
[env]
|
||||
TEST_VAR = "test-value"
|
||||
|
||||
- name: Verify MISE_ENV is set in subsequent steps
|
||||
run: |
|
||||
if [ "$MISE_ENV" != "preview" ]; then
|
||||
echo "MISE_ENV not set correctly: got '$MISE_ENV', expected 'preview'"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ MISE_ENV correctly set to: $MISE_ENV"
|
||||
|
||||
- name: Verify mise environment variables are loaded
|
||||
run: |
|
||||
if [ "$TEST_VAR" != "test-value" ]; then
|
||||
echo "Environment variable not loaded: got '$TEST_VAR'"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ Environment variables loaded correctly"
|
||||
|
||||
# Test 2: MISE_ENV environment variable takes precedence
|
||||
# Clear MISE_ENV first since it persists from previous test
|
||||
- name: Clear MISE_ENV from previous test
|
||||
run: |
|
||||
echo "MISE_ENV=production" >> $GITHUB_ENV
|
||||
|
||||
- name: Setup mise with both env var and input
|
||||
uses: ./
|
||||
with:
|
||||
environment: staging
|
||||
mise_toml: |
|
||||
[tools]
|
||||
jq = "1.7.1"
|
||||
|
||||
[env]
|
||||
PROD_VAR = "production-value"
|
||||
|
||||
- name: Verify existing MISE_ENV takes precedence
|
||||
run: |
|
||||
if [ "$MISE_ENV" != "production" ]; then
|
||||
echo "MISE_ENV should be 'production' (from env var), got '$MISE_ENV'"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ Existing MISE_ENV correctly took precedence"
|
||||
|
||||
- name: Verify environment variables are loaded
|
||||
run: |
|
||||
if [ "$PROD_VAR" != "production-value" ]; then
|
||||
echo "Environment variable not loaded: got '$PROD_VAR'"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ Environment variables loaded correctly"
|
||||
|
||||
# Test 3: Cache key includes environment
|
||||
- name: Clear MISE_ENV for cache test
|
||||
run: echo "MISE_ENV=test-env" >> $GITHUB_ENV
|
||||
|
||||
- name: Setup mise with environment (cache test)
|
||||
uses: ./
|
||||
with:
|
||||
environment: test-env
|
||||
cache_key: "test-{{mise_env}}-{{platform}}-${{ github.run_id }}"
|
||||
mise_toml: |
|
||||
[tools]
|
||||
jq = "1.7.1"
|
||||
|
||||
- name: Verify environment persists
|
||||
run: |
|
||||
if [ "$MISE_ENV" != "test-env" ]; then
|
||||
echo "MISE_ENV not persisted correctly: got '$MISE_ENV'"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ MISE_ENV persisted correctly for cache test"
|
||||
|
||||
# Test 4: Respect env=false input
|
||||
- name: Clear MISE_ENV for next test
|
||||
run: echo "MISE_ENV=no-export" >> $GITHUB_ENV
|
||||
|
||||
- name: Setup mise with env=false
|
||||
uses: ./
|
||||
with:
|
||||
environment: no-export
|
||||
env: false
|
||||
install: false
|
||||
mise_toml: |
|
||||
[tools]
|
||||
jq = "1.7.1"
|
||||
|
||||
- name: Verify MISE_ENV is set even with env=false
|
||||
run: |
|
||||
# MISE_ENV should be set by the action
|
||||
if [ "$MISE_ENV" != "no-export" ]; then
|
||||
echo "MISE_ENV should be set to 'no-export', got '$MISE_ENV'"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ MISE_ENV set even with env=false"
|
||||
|
||||
final:
|
||||
needs:
|
||||
- build
|
||||
|
|
@ -155,6 +265,7 @@ jobs:
|
|||
- checksum_failure
|
||||
- custom_cache_key
|
||||
- fetch_from_github
|
||||
- mise_environment_test
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 1
|
||||
if: always()
|
||||
|
|
|
|||
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -1,5 +1,16 @@
|
|||
# Changelog
|
||||
|
||||
---
|
||||
## [Unreleased]
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- Add `environment` input to automatically set and export MISE_ENV (#447)
|
||||
- Simplifies multi-environment workflows by eliminating manual export step
|
||||
- Respects existing MISE_ENV environment variable (takes precedence)
|
||||
- Automatically included in cache key generation via {{mise_env}} template variable
|
||||
- Exports to GITHUB_ENV making it available to all subsequent workflow steps
|
||||
|
||||
---
|
||||
## [4.0.1](https://github.com/jdx/mise-action/compare/v4.0.0..v4.0.1) - 2026-03-22
|
||||
|
||||
|
|
|
|||
71
README.md
71
README.md
|
|
@ -94,6 +94,77 @@ 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.
|
||||
|
||||
## Multi-Environment Workflows
|
||||
|
||||
Mise supports multiple environments through the `MISE_ENV` variable. The action provides an `environment` input to simplify multi-environment workflows:
|
||||
|
||||
```yaml
|
||||
- name: Setup mise for preview environment
|
||||
uses: jdx/mise-action@v4
|
||||
with:
|
||||
environment: preview # Automatically sets and exports MISE_ENV
|
||||
mise_toml: |
|
||||
[tools]
|
||||
node = "24"
|
||||
|
||||
[env.preview]
|
||||
API_URL = "https://preview.example.com"
|
||||
|
||||
[env.production]
|
||||
API_URL = "https://api.example.com"
|
||||
|
||||
- name: Deploy (MISE_ENV is available)
|
||||
run: mise run deploy
|
||||
# The preview environment is active, API_URL is set to preview URL
|
||||
```
|
||||
|
||||
**Before (manual approach)**:
|
||||
```yaml
|
||||
- name: Export MISE_ENV
|
||||
run: echo "MISE_ENV=preview" >> $GITHUB_ENV
|
||||
|
||||
- name: Setup mise
|
||||
uses: jdx/mise-action@v4
|
||||
env:
|
||||
MISE_ENV: preview
|
||||
```
|
||||
|
||||
**After (with environment input)**:
|
||||
```yaml
|
||||
- name: Setup mise
|
||||
uses: jdx/mise-action@v4
|
||||
with:
|
||||
environment: preview
|
||||
```
|
||||
|
||||
### Environment Variable Precedence
|
||||
|
||||
If `MISE_ENV` is already set (e.g., at the job level), it takes precedence over the `environment` input:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
deploy:
|
||||
env:
|
||||
MISE_ENV: production # This takes precedence
|
||||
steps:
|
||||
- uses: jdx/mise-action@v4
|
||||
with:
|
||||
environment: staging # This will be ignored
|
||||
```
|
||||
|
||||
### Cache Keys and Environments
|
||||
|
||||
The cache key automatically includes the environment when using the default cache key template. You can also reference it explicitly:
|
||||
|
||||
```yaml
|
||||
- uses: jdx/mise-action@v4
|
||||
with:
|
||||
environment: preview
|
||||
cache_key: "mise-{{platform}}-{{mise_env}}-{{file_hash}}"
|
||||
```
|
||||
|
||||
This ensures different environments maintain separate caches.
|
||||
|
||||
## 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.
|
||||
|
|
|
|||
|
|
@ -85,6 +85,13 @@ inputs:
|
|||
description: "Automatically load mise env vars into GITHUB_ENV. Note that PATH modifications are not part of this."
|
||||
required: false
|
||||
default: "true"
|
||||
environment:
|
||||
required: false
|
||||
description: |
|
||||
The mise environment to use (e.g., "preview", "production").
|
||||
When set, this value will be exported to GITHUB_ENV, making it available
|
||||
to all subsequent workflow steps.
|
||||
Note: If MISE_ENV is already set in the environment, it takes precedence over this input.
|
||||
outputs:
|
||||
cache-hit:
|
||||
description: A boolean value to indicate if a cache was hit.
|
||||
|
|
|
|||
15
dist/index.js
generated
vendored
15
dist/index.js
generated
vendored
|
|
@ -84959,6 +84959,16 @@ async function setEnvVars() {
|
|||
exportVariable(k, v);
|
||||
}
|
||||
};
|
||||
// Set MISE_ENV from 'environment' input if provided
|
||||
// Note: existing MISE_ENV environment variable takes precedence
|
||||
const environmentInput = getInput('environment');
|
||||
if (environmentInput && !process.env.MISE_ENV) {
|
||||
info(`Setting MISE_ENV=${environmentInput}`);
|
||||
exportVariable('MISE_ENV', environmentInput);
|
||||
}
|
||||
else if (environmentInput && process.env.MISE_ENV) {
|
||||
info(`MISE_ENV already set to '${process.env.MISE_ENV}', ignoring 'environment' input`);
|
||||
}
|
||||
if (getBooleanInput('experimental'))
|
||||
set('MISE_EXPERIMENTAL', '1');
|
||||
const logLevel = getInput('log_level');
|
||||
|
|
@ -85179,7 +85189,10 @@ async function processCacheKeyTemplate(template) {
|
|||
const version = getInput('version');
|
||||
const installArgs = getInput('install_args');
|
||||
const cacheKeyPrefix = getInput('cache_key_prefix') || 'mise-v1';
|
||||
const miseEnv = process.env.MISE_ENV?.replace(/,/g, '-');
|
||||
// Match the precedence in setEnvVars(): process.env.MISE_ENV takes precedence over environment input
|
||||
// This ensures the cache key matches the runtime MISE_ENV value
|
||||
const environmentInput = getInput('environment');
|
||||
const miseEnv = (process.env.MISE_ENV || environmentInput || '').replace(/,/g, '-');
|
||||
const platform = await getTarget();
|
||||
// Calculate file hash
|
||||
const fileHash = await hashFiles(MISE_CONFIG_FILE_PATTERNS.join('\n'));
|
||||
|
|
|
|||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
21
src/index.ts
21
src/index.ts
|
|
@ -177,6 +177,19 @@ async function setEnvVars(): Promise<void> {
|
|||
core.exportVariable(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Set MISE_ENV from 'environment' input if provided
|
||||
// Note: existing MISE_ENV environment variable takes precedence
|
||||
const environmentInput = core.getInput('environment')
|
||||
if (environmentInput && !process.env.MISE_ENV) {
|
||||
core.info(`Setting MISE_ENV=${environmentInput}`)
|
||||
core.exportVariable('MISE_ENV', environmentInput)
|
||||
} else if (environmentInput && process.env.MISE_ENV) {
|
||||
core.info(
|
||||
`MISE_ENV already set to '${process.env.MISE_ENV}', ignoring 'environment' input`
|
||||
)
|
||||
}
|
||||
|
||||
if (core.getBooleanInput('experimental')) set('MISE_EXPERIMENTAL', '1')
|
||||
|
||||
const logLevel = core.getInput('log_level')
|
||||
|
|
@ -443,7 +456,13 @@ async function processCacheKeyTemplate(template: string): Promise<string> {
|
|||
const version = core.getInput('version')
|
||||
const installArgs = core.getInput('install_args')
|
||||
const cacheKeyPrefix = core.getInput('cache_key_prefix') || 'mise-v1'
|
||||
const miseEnv = process.env.MISE_ENV?.replace(/,/g, '-')
|
||||
// Match the precedence in setEnvVars(): process.env.MISE_ENV takes precedence over environment input
|
||||
// This ensures the cache key matches the runtime MISE_ENV value
|
||||
const environmentInput = core.getInput('environment')
|
||||
const miseEnv = (process.env.MISE_ENV || environmentInput || '').replace(
|
||||
/,/g,
|
||||
'-'
|
||||
)
|
||||
const platform = await getTarget()
|
||||
|
||||
// Calculate file hash
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue