A GitHub Action to load multiple .env files in a specific order. Files loaded later override variables from earlier files, allowing for cascading configuration (e.g., common → environment-specific).
Check out the Quick Start Guide to get up and running in 5 minutes!
- ✅ Load multiple
.envfiles in order - ✅ Skip missing files automatically (or fail if desired)
- ✅ Later files override earlier ones
- ✅ Clean summary output
- ✅ Optional variable name logging for debugging
- ✅ Supports comments and empty lines in
.envfiles
- name: Load environment variables
uses: kezios/load-multiple-env-files-action@v1
with:
files: |
.env.common
.env.production- name: Load environment variables
uses: kezios/load-multiple-env-files-action@v1
with:
files: |
.env.common
${{ github.ref_name == 'main' && '.env.staging' || '.env.production' }}
apps/api/.env.common
${{ github.ref_name == 'main' && 'apps/api/.env.staging' || 'apps/api/.env.production' }}
log-variables: truename: Deploy Application
on:
push:
branches:
- main
- prod
env:
IS_STAGING: ${{ github.ref_name == 'main' }}
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Load environment variables
uses: kezios/load-multiple-env-files-action@v1
with:
files: |
.env.common
${{ env.IS_STAGING == 'true' && '.env.staging' || '.env.production' }}
apps/front/.env.common
${{ env.IS_STAGING == 'true' && 'apps/front/.env.staging' || 'apps/front/.env.production' }}
- name: Build application
run: npm run build
# All variables from .env files are now available in $GITHUB_ENV| Input | Description | Required | Default |
|---|---|---|---|
files |
List of .env files to load (one per line). Files are loaded in order. |
Yes | - |
log-variables |
Whether to log loaded variable names (not values) for debugging | No | false |
fail-on-missing |
Whether to fail if any file is missing | No | false |
This action doesn't have explicit outputs, but it loads all variables into $GITHUB_ENV, making them available to all subsequent steps in the job.
- File Order: Files are processed in the order they appear in the
filesinput - Variable Override: If the same variable exists in multiple files, the last one wins
- Comments: Lines starting with
#are ignored - Empty Lines: Empty lines are skipped
- Missing Files: By default, missing files are skipped with a warning. Set
fail-on-missing: trueto fail instead
🔧 Loading environment files...
✓ Loading: .env.common
Loaded 5 variable(s)
✓ Loading: .env.production
Loaded 3 variable(s)
⚠ Skipping (not found): .env.local
✓ Loading: apps/front/.env.common
Loaded 7 variable(s)
📊 Summary:
• Files loaded: 3
• Files skipped: 1
• Total variables: 15
✅ Done!
Load common variables first, then override with environment-specific ones:
with:
files: |
.env.common
.env.${{ env.ENVIRONMENT }}Load workspace-level config, then app-specific config:
with:
files: |
.env.common
.env.production
apps/api/.env.common
apps/api/.env.production
apps/frontend/.env.common
apps/frontend/.env.productionEnable variable name logging to see what's being loaded:
with:
files: |
.env.common
.env.production
log-variables: trueOutput:
✓ Loading: .env.common
→ DATABASE_URL
→ API_KEY
→ LOG_LEVEL
Loaded 3 variable(s)
Your .env files should follow the standard format:
# This is a comment
VARIABLE_NAME=value
ANOTHER_VAR=another value
# Empty lines are fine
DATABASE_URL=postgresql://localhost:5432/db- Order Matters: List files from most general to most specific
- Optional Files: Missing files are skipped by default, so you can safely list optional files
- Variable Expansion: This action doesn't expand variables (e.g.,
${VAR}). Variables are loaded as-is - Multiline Values: This action doesn't support multiline values (use secrets for complex values)
MIT
Contributions welcome! Please open an issue or PR.
- xom9ikk/dotenv - Load a single .env file
- cardinalby/export-env-action - Export variables from files
- falti/dotenv-action - Another dotenv loader