Menu

Auto-sync .env File to GitHub Actions

Good to know

NEXTY.DEV v3.2.16 introduces two new production environment variable sync scripts. If your local code doesn't have these scripts, please download them from the source repository:

This guide shows you how to use scripts to automatically batch create environment variables from your local .env file into GitHub Actions Secrets and Variables.

Prerequisites

  1. Install GitHub CLI

MacOS:

brew install gh

Windows:

winget install --id GitHub.cli
 
or
 
scoop install gh
  1. Login to GitHub
gh auth login

Follow the interactive prompts to complete the login.

  1. Ensure Repository Permissions

You need Admin permissions on the target repository to create Secrets and Variables.

Script Usage

In your package.json file, find the scripts configuration and add the following commands:

"scripts": {
  "env:clear": "node scripts/clear-env-from-github.mjs",
  "env:sync": "node scripts/sync-env-to-github.mjs",
}

Before each sync, first clear the environment variables in GitHub Actions Secrets and Variables (optional but recommended):

npm run env:clear

Then sync the environment variables from your local .env file to GitHub Actions Secrets and Variables:

npm run env:sync

Whether clearing or syncing, the execution results will be displayed, for example:

 Done in 10.9s!
  📦 Variables created: 19
  🔐 Secrets created: 25
  ⏭️ Skipped: 9

If you encounter a message indicating that some environment variables failed to clear or sync, simply run the command again.

Security Notes

  • ⚠️ Never commit your .env file to Git
  • Ensure .env is listed in .gitignore
  • Secrets are stored encrypted on GitHub. When editing Secrets, they will appear blank - this is normal behavior and nothing to worry about.