ghenv

Docs

Setup

Create a Preview bundle

Set GHENV_PREVIEW_BUNDLE in the Preview environment. Its version-1 JSON identifies the repository and holds the approved names and values. This example uses placeholders. Enter your approved development values in GitHub’s secret form.

GHENV_PREVIEW_BUNDLE
{"version": 1,
 "environment": "Preview",
 "repository": "OWNER/REPO",
 "secrets": {"API_KEY": "development-placeholder"},
 "variables": {"API_BASE_URL": "http://127.0.0.1:3000"}
}

Keep the bundle within GitHub’s 48 KiB secret limit. Reserve its name for development values at environment, repository, and organization scope, where GitHub can fall back to a same-named secret.

Set access and approvals

A permitted dispatcher who passes Preview’s approval can request any entry the owner placed in the bundle. Protect the handoff workflow, its default branch, and changes to the bundle. Keep production credentials outside this export boundary.

Usage

Select values for one command

Terminal
ghenv run --repo OWNER/REPO --workflow pr-preview.yml \
  --secrets API_KEY --vars API_BASE_URL -- npm run dev

Add --timeout 10m before -- if a handoff needs more than the default five minutes. The child receives terminal streams and its exit status is returned by ghenv. The clean environment keeps tool and terminal settings and the selected values.

Save launch policy in TOML

Commit the names and policy in ghenv.toml. Store values in Preview. The explicit workflow selector works with released and current-source clients.

ghenv.toml
version = 1
repository = "OWNER/REPO"
workflow = "pr-preview.yml"
default_mode = "preview"
secrets = "API_KEY"
variables = "API_BASE_URL"
ghenv dev -- npm run dev

Run without old dotenv overrides

Configure the app to read its process environment and remove any dotenv loader that could override those values. Expo dotenv loading is disabled for clean launches. Treat browser-facing prefixes such as EXPO_PUBLIC_ as public.

Testing

Check the handoff route

ghenv doctor --repo OWNER/REPO --workflow pr-preview.yml

Doctor checks GitHub authentication and workflow metadata. The actual run also checks dispatch access, environment approval, and the selected bundle entries.

Verify a source checkout

Terminal
mise run setup
mise run build
mise run test

Repository tests cover bundle scope, the encrypted handoff, a fixture for the GitHub CLI adapter, and child-process behavior.

Architecture

Follow the encrypted handoff

One handoff per command
  1. RequestName the Preview entries
  2. ApproveGitHub environment rules
  3. EncryptOne-time key for the artifact
  4. LaunchInject values into the child

The CLI creates an ephemeral key pair and sends the public key with the requested names. The exporter validates the bundle’s repository and scope, encrypts the selected values, and uploads ciphertext. The client decrypts in memory and attempts artifact cleanup.

Understand the process boundary

The app receives the requested values in its environment and can read or persist them. Use a remote API for credentials local developers must never read. ghenv supervises the child’s process group during interruptions.

Examples

Start a local fixture stack

ghenv local -- npm run dev

This launches the existing command with a clean environment and skips the GitHub handoff.

Switch a profile to local mode

ghenv dev --mode local -- npm run dev

Use a project profile to select the launch mode per invocation. Your app can use local fixture settings for this mode.