Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Sep 28, 2022
1 parent debcd02 commit 33791f1
Show file tree
Hide file tree
Showing 8 changed files with 554 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @dcarbone
37 changes: 37 additions & 0 deletions .github/workflows/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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
123 changes: 123 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: 'Tests - YAML to Env action'

on:
workflow_dispatch:

push:
branches:
- main
paths:
- 'action.yaml'
- '.github/workflows/tests.yaml'
- 'test-values.yaml'

pull_request:
branches:
- main

jobs:
test:
name: Test Action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Execute action
uses: dcarbone/yaml-to-env-action@main
with:
yaml-file: test-values.yaml
debug: 'true'

- name: Test env
run: |
_EXPECTED_ENVS=(
"STRING"
"hello there"
'${{ env.STRING }}'
"STRING_QUOTED"
"hello there"
'${{ env.STRING_QUOTED }}'
"STRING_INNER_QUOTED"
'hello "there"'
'${{ env.STRING_INNER_QUOTED }}'
"STRING_MULTILINE"
'This is some multiline text
this is pretty cool
the quork brewn facs jammed über teh cndl
'
'${{ env.STRING_MULTILINE }}'
"STRING_MULTILINE_BAR"
'This is some multiline text
this is pretty cool
the quork brewn facs jammed über teh cndl'
'${{ env.STRING_MULTILINE_BAR }}'
"NUMBER"
"5"
'${{ env.NUMBER }}'
"FLOAT"
"5.5"
'${{ env.FLOAT }}'
"OBJECT_KEY1"
"value1"
'${{ env.OBJECT_KEY1 }}'
"OBJECT_KEY2"
"2"
'${{ env.OBJECT_KEY2 }}'
"OBJECT_KEY3_0"
"nested value 1"
'${{ env.OBJECT_KEY3_0 }}'
"OBJECT_KEY3_1"
"nested value 2"
'${{ env.OBJECT_KEY3_1 }}'
"OBJECT_KEY3_2"
'nested value "3"'
'${{ env.OBJECT_KEY3_2 }}'
"ARRAY_0"
"one"
'${{ env.ARRAY_0 }}'
"ARRAY_1"
"two"
'${{ env.ARRAY_1 }}'
"ARRAY_2_0"
"nested one"
'${{ env.ARRAY_2_0 }}'
"STRING_WITH_EQUALS"
'value = yep'
'${{ env.STRING_WITH_EQUALS }}'
"STRING_MULTILINE_WITH_EQUALS"
'value
=
yep
'
'${{ env.STRING_MULTILINE_WITH_EQUALS }}'
)
for (( i=0; i < "${#_EXPECTED_ENVS[@]}"; i+=3 )); do
_env="${_EXPECTED_ENVS[$i]}"
_exp="${_EXPECTED_ENVS[$i+1]}"
_act="${_EXPECTED_ENVS[$i+2]}"
if [[ "${_act}" != "${_exp}" ]]; then
echo "Environment variable \"${_env}\" value mismatch:"
echo " Expected: \"${_exp}\""
echo " Actual: \"${_act}\""
exit 1
fi
done
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
/.idea
/test.env
138 changes: 137 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,137 @@
# yaml-to-env-action
# YAML to ENV GitHub Action

[GitHub Action](https://docs.github.com/en/actions) that reads values from a YAML file, setting them into the `$GITHUB_ENV` of a job.

# Index

1. [Example Workflow](#example-workflow)
2. [Conversion Rules](#conversion-rules)
3. [Inputs](#action-inputs)
4. [Outputs](#action-outputs)

## Example Workflow

```yaml
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
#### Simple
Source YAML:
```yaml
key: value
```
Output env:
```text
KEY=value
```

#### Nested Object

Source YAML:
```yaml
object:
key1: value1
key2: value 2
key3:
- nested value 1
- nested value 2
```
Output env:
```text
OBJECT_KEY1=value1
OBJECT_KEY2=value 2
OBJECT_KEY3_0=nested value 1
OBJECT_KEY3_1=nested value 2
```

#### Multiline value

Source YAML:
```yaml
multiline: |
value with
more than 1 line
```
Output env:
```text
MULTILINE<<EOF
value with
more than 1 line
EOF
```

## Action Inputs

#### yaml-file
```yaml
yaml-file:
required: true
description: "Filepath to YAML to parse"
```
#### yq-version
```yaml
yq-version:
required: false
default: "4.27.5"
description: "Version of yq to install, if not already in path. Tested with >= 4.25."
```
#### debug
```yaml
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
```yaml
yq-installed:
description: "'true' if yq was installed by this action"
```
Loading

0 comments on commit 33791f1

Please sign in to comment.