Skip to content
copy

GitHub Action

YAML to ENV

v3.0.1 Latest version

YAML to ENV

copy

YAML to ENV

Parse all keys & values out of a YAML file, adding them to the $GITHUB_ENV file

Installation

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

              

- name: YAML to ENV

uses: dcarbone/[email protected]

Learn more about this action in dcarbone/yaml-to-env-action

Choose a version

YAML to ENV GitHub Action

GitHub Action that reads values from a YAML file, setting them into the $GITHUB_ENV of a job.

Example Workflow

You can see an example workflow here: example.yaml

Conversion Rules

Names

Key to env name happens using the following script:

tr '[:lower:]' '[:upper:]' | sed -E 's/[^a-zA-Z0-9_]/_/g';

You can see the exact logic here

Simple

Source YAML:

key: value

Output env:

KEY=value

Nested Object

Source YAML:

object:
  key1: value1
  key2: value 2
  key3:
    - nested value 1
    - nested value 2

Output env:

OBJECT_KEY1=value1
OBJECT_KEY2=value 2
OBJECT_KEY3_0=nested value 1
OBJECT_KEY3_1=nested value 2

Multiline value

Source YAML:

multiline: |
  value with
  more than 1 line

Output env:

MULTILINE<<EOF
value with
more than 1 line
EOF

Action Inputs

yaml-file

  yaml-file:
    required: true
    description: "Filepath to YAML to parse"

yq-version

  yq-version:
    required: false
    default: "4.27.5"
    description: "Version of yq to install, if not already in path.  Tested with >= 4.25."

mask-values

  mask-values:
    required: false
    default: "false"
    description: "Add value masking to all exported environment variable values (https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#example-masking-an-environment-variable)"

Action Outputs

yq-installed

  yq-installed:
    description: "'true' if yq was installed by this action"

var-count

  var-count:
    description: "Number of environment variables defined from source YAML file."

yaml-keys

  yaml-keys:
    description: "Comma-separated string of keys extracted from source YAML file."

env-names

  env-names:
    description: "Comma-separated string of exported environment variable names"