This GitHub Action replaces environment variable placeholders defined in one or more input files (ENV_FILES) using repository secrets and vars. It also extracts the CloudFront distribution ID (CLOUDFRONT_DIST_ID) and outputs it for use in subsequent steps.
Ideal for AWS deployment workflows, environment-based configuration, and secrets-driven
.envgeneration.
- 🪧 Replaces placeholders like
'{MY_SECRET}'with actual values fromsecretsorvars - 🔄 Supports branch-prefixed variables (
main_MY_SECRET, etc.) - 📤 Exposes
CLOUDFRONT_DIST_IDas an output - 📄 Writes a ready-to-use
.envor configuration file
Each input file listed in ENV_FILES should contain lines with variables in this format:
API_KEY='{API_KEY}'
SOME_FLAG='true'Braces ('{...}') will be replaced with actual values from GitHub repository secrets or variables.
API_URL='{API_URL}'
SECRET_TOKEN='{SECRET_TOKEN}'You can define global or branch-specific variables, such as:
MASTER_API_URLDEV_SECRET_TOKEN
jobs:
generate_env:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Variable allocation & CLOUDFRONT_DIST_ID
id: variables_allocation
uses: matiascariboni/action-variables_allocation@v2.0.0
with:
ENV_FILES: |
[
["./.env.prod", "./.env"],
["./.npmrc.template", "./.npmrc"]
]
REPO_VARS: ${{ toJson(vars) }}
REPO_SECRETS: ${{ toJson(secrets) }}
- name: Print output
run: echo "CloudFront ID: ${{ steps.variables_allocation.outputs.CLOUDFRONT_DIST_ID }}"Each pair in ENV_FILES is processed sequentially: position 0 is the input template, position 1 is the resolved output file. Add as many pairs as needed to generate multiple files in a single run.
| Name | Description | Required |
|---|---|---|
ENV_FILES |
JSON array of [input, output] file path pairs, e.g. [["./.env.prod", "./.env"], ["./.npmrc.template", "./.npmrc"]]. Processed sequentially. |
✅ Yes |
REPO_VARS |
Variables allocated on current repo | ✅ Yes |
REPO_SECRETS |
Variables allocated on current secret | ✅ Yes |
CLOUDFRONT |
Enable resolving CLOUDFRONT_DIST_ID from vars/secrets (default: false) |
❌ No |
| Name | Description |
|---|---|
CLOUDFRONT_DIST_ID |
The resolved CloudFront distribution ID |
${BRANCH}_VAR_NAMEin secrets${BRANCH}_VAR_NAMEin varsVAR_NAMEin secretsVAR_NAMEin vars
- Lines starting with
//are ignored (treated as comments) - If a value is not found, the step fails explicitly (except
CLOUDFRONT_DIST_ID, which is optional) CLOUDFRONT_DIST_IDresolution is opt-in: it only runs when theCLOUDFRONTinput is set totrue. When disabled (the default), the step is skipped entirely and no output is set- If the output file ends with
.json, values are always written as JSON strings - Prefix
~inside a placeholder (e.g.,'~{VAR}') means the value will be inserted without quotes - Arrays like
[1,2,3]are detected and preserved as raw values - If the value is not a number, boolean, array, or prefixed with
~, it is wrapped in single quotes ('value') - Values are inserted literally: characters like
&,/,\, and quotes are preserved as-is and never treated as special replacement syntax
This project is licensed under the MIT License.
Contributions are welcome! Feel free to open issues or pull requests.
Developed by Matías Cariboni.