Skip to content

This action use "yq" to convert a YAML to GitHub Actions outputs

License

Notifications You must be signed in to change notification settings

actions-betaon/yq-yaml-parser

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

YAML parser action

GitHub Super-Linter CI Docker CI Test

This action reads values from a YAML file setting as action outputs.

Usage

Here's an example of how to use this action in a workflow file:

name: Example Workflow

on:
  workflow_dispatch:
    inputs:
      yaml-file-path:
        description: 'Path to the yaml file to parser'
        required: true
        type: string
      yaml-filtering-keys:
        description: 'Read using specific filter'
        required: false
        type: string
      yaml-renaming-outputs:
        description: 'Used to rename the default output name'
        required: false
        type: string

jobs:
  yq-yaml-parser:
    name: Yq yaml parser
    runs-on: ubuntu-latest

    steps:
      - name: Yaml to outputs
        id: yaml-to-outputs
        uses: actions-betaon/[email protected]
        with:
          file-path: '${{ inputs.yaml-file-path }}'
          filtering-keys: '${{ inputs.yaml-filtering-keys }}'
          renaming-outputs: '${{ inputs.yaml-renaming-outputs }}'

Inputs

Input Description Required
file-path Path to the YAML file to parse as output true
filtering-keys The YAML key names filter to apply false
renaming-outputs The YAML rename "keyname=output" output list false

Outputs

Given

sample:
  key-1: value 1
  key-2: |
    value 2 with
    2 lines
  key-3:
    - nested value 1
    - nested value 2

Output as

sample_key-1=value 1
sample_key-2<<EOF
value 2 with
2 lines
EOF
sample_key-3_0=nested value 1
sample_key-3_1=nested value 2

Filtering keys

The input filtering-keys can be used to filter the outputs using four methods:

  • Filter by keys
  • Exclude by keys
  • Filter by regular expression
  • Exclude by regular expression

Filter by keys

This method filter outputs using the exact match by key name.

To filter, simply apply the keys names to be filtered.

filtering-keys: |
  my-key_custom
  my-key_specific

Exclude by keys

This method exlude outputs using the exact match by key name.

To apply the exlude filter, you must add the symbol "!" before the keys names.

filtering-keys: |
  !my-key_custom
  !my-key_specific

Filter by regular expression

This method filter outputs using a regular expression pattern.

To filter using regular expression, you must add the symbol "+" before the regular expression pattern.

filtering-keys: |
  +.*custom.*
  +.*specific.*

Exclude by regular expression

This method exclude outputs using a regular expression pattern.

To apply the exlude regular expression, you must add the symbol "-" before the regular expression pattern.

filtering-keys: |
  -.*custom.*
  -.*specific.*

:warning

This action uses alpine linux base image. The regular expression pattern is applied internally using busybox grep.

Due this, some complex regular expression patterns may not work properly.