mirror of
https://github.com/jdx/mise-action.git
synced 2026-05-14 22:00:34 +00:00
feat: add environment input to automatically set and export MISE_ENV
Add new 'environment' input parameter that simplifies multi-environment
workflows by automatically setting and exporting MISE_ENV to GITHUB_ENV.
Features:
- New optional 'environment' input (e.g., 'preview', 'production')
- Automatically exports MISE_ENV to GITHUB_ENV when env input is true
- Existing MISE_ENV environment variable takes precedence
- Automatically included in cache key via {{mise_env}} template variable
- Comprehensive test suite covering all edge cases
This eliminates the need for manual export steps in workflows and keeps
environment configuration within the action scope.
Closes #447
This commit is contained in:
parent
db69447ab3
commit
121c4fdeaf
7 changed files with 218 additions and 1 deletions
105
.github/workflows/test.yml
vendored
105
.github/workflows/test.yml
vendored
|
|
@ -147,6 +147,110 @@ 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.preview]
|
||||
PREVIEW_VAR = "preview-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 [ "$PREVIEW_VAR" != "preview-value" ]; then
|
||||
echo "Environment-specific variable not loaded: got '$PREVIEW_VAR'"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ Environment-specific variables loaded correctly"
|
||||
|
||||
# Test 2: MISE_ENV environment variable takes precedence
|
||||
- name: Setup mise with both env var and input
|
||||
uses: ./
|
||||
with:
|
||||
environment: staging
|
||||
mise_toml: |
|
||||
[tools]
|
||||
jq = "1.7.1"
|
||||
|
||||
[env.production]
|
||||
PROD_VAR = "production-value"
|
||||
env:
|
||||
MISE_ENV: production
|
||||
|
||||
- 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 production environment is active
|
||||
run: |
|
||||
if [ "$PROD_VAR" != "production-value" ]; then
|
||||
echo "Production environment not active: got '$PROD_VAR'"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ Production environment correctly active"
|
||||
|
||||
# Test 3: Cache key includes environment
|
||||
- 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=" >> $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 +259,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
|
||||
- Only exports to GITHUB_ENV when `env` input is true (default)
|
||||
|
||||
---
|
||||
## [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 (if env input is true),
|
||||
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.
|
||||
|
|
|
|||
10
dist/index.js
generated
vendored
10
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');
|
||||
|
|
|
|||
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
13
src/index.ts
13
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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue