Skip to content

Steph0/dotenv-configserver

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Environment variables from a remote (centralized) config server

Loads dotenv (.env) files content from a remote repository to GITHUB_ENV and outputs. This action can be used like a config server but for your Github actions.

This action can work as a workaround if you do not beneficiate of Github Environments feature in your Github plan Common example: your enterprise is using Github Teams plan and private repositories.

Environment variables will be then available using ${{ env.<KEY> }} within the same job.
Outputs will be then available using ${{ <job id>.outputs.<output name> }} for other jobs.

Configuration

Parameter Required Description Example
repository true The remote repository (configserver). Format: <owner>/<repo> repository: "Steph0/dotenv-configserver"
token false This should be a token with access to your repository scoped in as a secret (default to GITHUB_TOKEN) token: ${{ secrets.GITHUB_TOKEN }}
branch false The remote branch to checkout (default: main) branch: "staging"
destination false The working folder to write configuration to (default 'RUNNER_TEMP') destination: "/my/dest/folder"
directory false Look for file in configserver subdirectory (default '.').
Useful if your configserver hosts several config directories in it
directory: "my-app-dir"
filename false The config filename (default to '.env') filename: "my-application.env"
profile false Profile for file (ex: 'prod' will make tool
look for <filename_part>-.<filename_extension>)

If empty, won't apply.
profile: "prod"
Depending on filename will make action look for file:
my-application-prod.env
cleanup false If false, won't delete configuration files downloaded after loading to GITHUB_ENV (default: true) cleanup: false

Usage

This action allows many directories structures in your configserver.

This section illustrates common configserver configurations that could be used for your projects/enterprise:

Basic

Configserver:

(main branch)
|_ .env

Github Action:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      -   name: "Checkout"
          id: checkout
          uses: actions/checkout3

      - name: "Launch action"
        uses: Steph0/dotenv-configserver
        with:
          repository: "Steph0/test-configserver"
          token: "${{ secrets.ACTION_TOKEN }}"
      
      # You should see your .env config in 'env'
      - name: "See exported values"
        run: env

Flat

Configserver:

(main branch)
|_ dev.env
|_ staging.env
|_ prod.env

Github Action:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      -   name: "Checkout"
          id: checkout
          uses: actions/checkout3

      - name: "Launch action"
        uses: Steph0/dotenv-configserver
        with:
          repository: "Steph0/test-configserver"
          token: "${{ secrets.ACTION_TOKEN }}"
          # Will look for 'prod.env'
          profile: "prod"
      
      # You should see your .env config in 'env'
      - name: "See exported values"
        run: env

Env per branch

Configserver:

(main branch)
|_ .env

(dev branch)
|_ .env

Github Action:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      -   name: "Checkout"
          id: checkout
          uses: actions/checkout@v3

      - name: "Launch action"
        uses: Steph0/dotenv-configserver
        with:
          repository: "Steph0/test-configserver"
          token: "${{ secrets.ACTION_TOKEN }}"
          # Will checkout 'dev' branch
          branch: "dev"
      
      # You should see your .env config in 'env'
      - name: "See exported values"
        run: env

Nested directories

Configserver:

(main branch)
|_ front
   |_ application-prod.env
|_ backend
   |_ application-prod.env

(dev branch)
|_ front
   |_ application-dev.env
|_ backend
   |_ application-dev.env

Github Action:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      -   name: "Checkout"
          id: checkout
          uses: actions/checkout@v3

      - name: "Launch action"
        uses: Steph0/dotenv-configserver
        with:
          repository: "Steph0/test-configserver"
          token: "${{ secrets.ACTION_TOKEN }}"
          # Will checkout 'dev' branch
          branch: "dev"
          # Look for backend conf
          directory: backend
          # Override default filename
          filename: "application" # or `application.env`
          # Insert profile in filename (eg: application-dev.env)
          profile: "dev"
      
      # You should see your .env config in 'env'
      - name: "See exported values"
        run: env

Development

# Install dependencies
npm ci
# Build action
npm run all

You can test actions locally using ACT. Example:

# 'test.secrets' is a local file (automatically ignored) containing secrets like your Github PAT
npm run prepare && \
act workflow_dispatch -e ./.github/workflows/act-test.event -b --secret-file ./.github/workflows/test.secrets

Inspiration

This project took great inspiration from:

Heavily based also on the toolkit documentation.

Contribute

Feel free to ask for support or features requests in the Issues tab of the project repository.

Contributions (bug fixes, new features) are welcomed!

License: MIT