Provides environment variables via direnv
This action provides environment variables via direnv,
evaluates the target .envrc, and exports the resulting environment variables
to subsequent workflow steps.
Documentation site: https://hatsunemiku3939.github.io/direnv-action/
The action performs the following steps:
- Installs the requested
direnvversion from the GitHub release assets or a cache. Cold installs verify the downloaded binary's SHA-256 digest before execution or caching. - Runs
direnv allowfor the configuredpath. - Runs
direnv export jsonin the configuredpath. - Logs the exported environment variable names without printing their values.
- Optionally verifies that required environment variable names were exported.
- Exports the resulting variables to the GitHub Actions environment.
- Appends
PATHentries throughcore.addPath()whenPATHis present in the exported values. - Masks configured secret values with the GitHub Actions masking API.
direnvVersion: Thedirenvversion to use. Default:2.37.1.direnvChecksum: Optional SHA-256 checksum for the downloadeddirenvbinary. Default:''.masks: A comma-separated list of environment variable names to mask. Default:''.required: A newline-delimited list of environment variable names that must be exported. Default:''.path: The directory wheredirenv allowanddirenv export jsonare executed. Default:..
No outputs
Examples below pin the current release, v1.4.6. If you prefer compatible updates within the current major line, use the moving major tag @v1.
uses: HatsuneMiku3939/direnv-action@v1.4.6
with:
direnvVersion: 2.37.1
masks: SECRET1, SECRET2This loads the .envrc file from the repository root.
By default, cold installs verify the downloaded direnv binary against the GitHub Release API asset digest. To pin an
expected digest yourself, set direnvChecksum to either a plain SHA-256 hex digest or a sha256:<digest> value:
uses: HatsuneMiku3939/direnv-action@v1.4.6
with:
direnvVersion: 2.37.1
direnvChecksum: sha256:1f1b93dd6f38523fde26dfac96151ef9d31a374e3005cd3345fb93555ae0c9b5To evaluate the .envrc in a subdirectory, set path explicitly:
uses: HatsuneMiku3939/direnv-action@v1.4.6
with:
path: child
masks: SECRET1, SECRET2To fail early when expected variables are not exported, set required:
uses: HatsuneMiku3939/direnv-action@v1.4.6
with:
required: |
AWS_REGION
DATABASE_URL
NODE_AUTH_TOKENFor the most predictable builds, pin an exact version tag such as @v1.4.6. Use @v1 only when you want to receive the latest compatible v1.x.y release automatically.
masksaccepts environment variable names, not raw secret values.requiredaccepts environment variable names, not raw values, and fails when any listed name is absent from the exported environment.- When
.envrcexportsPATH, the action appends it to the jobPATHinstead of overwriting the entire value. - Variables exported by
direnv export jsonare available to later workflow steps in the same job. - The action logs exported variable names for debugging, but it does not print environment variable values.
- The action does not define custom outputs; consumers should read exported environment variables directly.
- Cold installs verify the downloaded
direnvbinary before marking it executable or saving it to any cache. - When
direnvChecksumis provided, the action cache key includes that checksum so different pins do not share cache entries.
This action evaluates .envrc, which means repository code can influence the shell commands executed by direnv. Treat
.envrc as executable code, especially in workflows that can access repository secrets, cloud credentials, deployment
tokens, or production infrastructure.
- Only use this action with trusted repositories and trusted
.envrccontents. - Avoid evaluating untrusted fork contents from
pull_request_targetworkflows. If you usepull_request_target, do not check out and run a fork-provided.envrcin a job that has access to secrets. - Prefer running secret-bearing jobs only on trusted refs, protected branches, or reviewed tags. For fork PR validation,
use
pull_requestwith minimal permissions and without repository secrets unless the.envrccontents are trusted. - Use the
requiredinput to fail early when expected exported variables are missing. This helps prevent downstream steps from running with incomplete configuration, but it is not a sandbox or a secret-protection boundary. - Keep workflow
permissions:as narrow as possible and avoid passing long-lived credentials into jobs that evaluate changing.envrcfiles. - Treat masking as a log redaction aid, not a complete secret protection boundary.
- Keep sensitive logic inside trusted workflow contexts whenever possible.
- Download verification uses the GitHub Release API asset digest by default. This protects against corrupted or swapped
download bytes relative to GitHub's release metadata. For a stronger independent pin, provide
direnvChecksum.
Run the local quality checks before packaging or releasing changes:
npm run lint
npm testFor release preparation, use the full gate so the generated dist/ artifacts stay in sync:
npm run allThe Vitest unit tests cover binary URL selection, downloaded binary checksum verification, tool installation cache branches, environment export behavior, required variable validation, secret masking, and the main action flow with mocked GitHub Actions APIs.
Since v1.0.7, the following platform and architecture combinations are supported.
| Platform | Architecture |
|---|---|
| Linux | x86_64 |
| Linux | arm64 |
| Darwin | x86_64 |
| Darwin | arm64 |
Versions earlier than v1.0.7 support only linux-x86_64.
|
Kim SeungSu |
hopisaurus |
Mike Dial |
gidoichi |
Alex Klinkert |