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

GitHub Action

YAML to ENV

v2.0.0

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.

Index

  1. Example Workflow
  2. Conversion Rules
  3. Inputs
  4. Outputs

Example Workflow

name: YAML to Env Example Workflow

on:
  workflow_dispatch:
    inputs:
      yaml-file:
        type: string
        required: false
        description: "Path to YAML file to parse"
        default: "test-values.yaml"
      yq-version:
        type: string
        required: false
        description: "Version of yq to install, if not already"
        default: "4.27.5"
      debug:
        type: boolean
        required: false
        description: "Enable debug logging"
        default: false

jobs:
  yaml-to-env:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set ENV values from YAML
        uses: dcarbone/[email protected]
        with:
          debug: '${{ inputs.debug }}'
          yaml-file: '${{ inputs.yaml-file }}'
          yq-version: '${{ inputs.yq-version }}'

      - name: Print environment variables
        run: |
          printenv

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."

debug

  debug:
    required: false
    default: "false"
    description: "Enable debug logging.  This WILL print un-masked secrets to stdout, so use with caution."

Action Outputs

yq-installed

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