Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
terminal

GitHub Action

Inplace Environment Substitution

v1.2.0

Inplace Environment Substitution

terminal

Inplace Environment Substitution

Replaces files containing environment variables placeholders '${PLACEHOLDER}' in place

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Inplace Environment Substitution

uses: Slidem/[email protected]

Learn more about this action in Slidem/inplace-envsubst-action

Choose a version

Inplace Environment Substitution for Files

Simple github action that allows inplace environment substitution for files

How it works

The action scans all your files in your "working directory-directory", based on the "search_input" provided (see bellow for more details) If the file files matches your search input, the files are replaced in place based on the environment variables set for the current workflow / job / step

The environment variables placeholder must follow the following pattern ${PLACEHOLDER_KEY}

Some notes:

  • Nested environment placeholders do not work. For ${KEY${KEY}}, the environment variable key translated will be KEY${KEY}
  • Currently, does not support default values (For example ${KEY:-defaultvalue})

Inputs

Name Default Description
working-directory The root directory where the file search and environment substitution takes place
fail_on_missing_variables false If set to "true" the job fails if a placeholder could not be resolved to an env variable. If set to false, action will ignore the non resolvable placeholder
replace_in_parallel false If set to true, for each file matching the regex, the env substitution will be executed in parallel, spawning a go routine for each
search_input Json string defining the search input for the files wished to be substituted. Example {"patterns": [".+.yaml"],"files": ["replace.me"],"depth": 2}

How to use:

Example on how to use this action provided in this workflow: https://github.com/Slidem/inplace-envsubst-action/blob/master/.github/workflows/test.yaml

      - name: Test action
        uses: Slidem/[email protected]
        env:
          COOL: "cool value"
        with:
          working-directory: testdir/replaced
          fail-on-missing-variables: "true"
          search_input: |
            {
              "patterns": [".+.yaml"],
              "files": ["replace.me"],
              "depth": 2
            }

The Search Input

The search_input JSON has 3 fields:

  • patterns: Array of regex patterns to match the files to be substituted. If any of the regex matches the files, the files will be substituted.
  • files: Array of strings, for exact match of files to be replaced
  • depth: (!mandatory) Defines how many levels deep the recursive search will go, starting from your working-directory