Skip to content

Commit e913a4d

Browse files
committed
initial commit
0 parents  commit e913a4d

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
on:
2+
push:
3+
4+
jobs:
5+
case-basic:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: ./
9+
with:
10+
path: ./tests
11+
values: |
12+
values.yml
13+
values-override.yml
14+
output: |
15+
app_name = .appName
16+
host = .nginx.host

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.idea/

action.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Read Helm Values
2+
description:
3+
Given list of values.yaml files, it will read specified variables from the merged result.
4+
5+
Because of dynamic nature of output variables, they are written to $GITHUB_OUTPUT.
6+
So no output is defined in this action
7+
inputs:
8+
path:
9+
description: Base directory for values files
10+
required: false
11+
default: '.'
12+
values:
13+
description: List of values files, separated by newline
14+
required: true
15+
output:
16+
description: Key-values list of variables to read, format is `key=.yq.expression`, each pair is on new line
17+
required: true
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Install yq
22+
shell: bash
23+
run: |
24+
set -e
25+
if ! command -v yq &> /dev/null; then
26+
wget https://github.com/mikefarah/yq/releases/download/v4.46.1/yq_linux_amd64 -O /usr/local/bin/yq
27+
chmod +x /usr/local/bin/yq
28+
fi
29+
30+
- name: Extract Helm values
31+
id: extract
32+
shell: bash
33+
run: |
34+
EXPRS=()
35+
while IFS= read -r line; do
36+
[[ -z "$line" ]] && continue
37+
EXPRS+=("$line")
38+
done <<< "${{ inputs.output }}"
39+
40+
${{ github.action_path }}/read-values.bash <<< "${{ inputs.values_files }}" >> "$GITHUB_OUTPUT"

read-values.bash

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
shopt -s extglob
4+
5+
FILES=()
6+
while IFS= read -r line; do
7+
[[ -z "$line" ]] && continue
8+
FILES+=("$line")
9+
done
10+
if [ ${#FILES[@]} -eq 0 ]; then
11+
echo "Error: No values files provided" >&2
12+
exit 1
13+
fi
14+
15+
MERGED=$(yq eval '.' "${FILES[0]}")
16+
17+
# Merge each subsequent file
18+
for ((i=1; i<${#FILES[@]}; i++)); do
19+
MERGED=$(echo "$MERGED" | yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' - "${FILES[i]}")
20+
done
21+
22+
23+
# Each argument format:
24+
# key = .yq.expression (spaces around '=' are optional)
25+
26+
for out in "$@"; do
27+
[[ -z "$out" ]] && continue
28+
29+
IFS='=' read -r KEY EXPR <<< "$out"
30+
31+
# trim surronding whitespace
32+
KEY="${KEY##+([[:space:]])}"
33+
KEY="${KEY%%+([[:space:]])}"
34+
EXPR="${EXPR##+([[:space:]])}"
35+
EXPR="${EXPR%%+([[:space:]])}"
36+
37+
VALUE=$(echo "$MERGED" | yq eval "$EXPR" -)
38+
echo "${KEY}=${VALUE}"
39+
done

tests/basic/values-override.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
appName: default
2+
3+
nginx:
4+
host: ton.org

tests/basic/values.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
appName: default
2+
3+
nginx:
4+
host: example.org
5+

0 commit comments

Comments
 (0)