mirror of
https://github.com/jdx/mise-action.git
synced 2026-05-15 06:10:32 +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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue