-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (53 loc) · 2.32 KB
/
env_vars.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Get Env Vars
on:
workflow_call:
inputs:
environment:
description: "The Github environment to retreive the env and secret var for."
required: true
type: string
outputs:
all_vars:
description: "All parsed variables and secrets."
value: ${{ jobs.get_env_vars.outputs.all_vars }}
jobs:
get_env_vars:
runs-on: ubuntu-latest
outputs:
all_vars: ${{ steps.vars_and_secrets.outputs.all_vars }}
environment:
name: ${{ inputs.environment }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- id: vars_and_secrets
name: Vars and Secrets to Env
env:
VARS_CONTEXT: ${{ toJson(vars) }}
SECRETS_CONTEXT: ${{ toJson(secrets) }}
run: |
parsed_vars=$(jq -n --argjson VARS_CONTEXT "$VARS_CONTEXT" --argjson SECRETS_CONTEXT "$SECRETS_CONTEXT" '$VARS_CONTEXT + $SECRETS_CONTEXT')
echo "Concat vars+secrets: ${parsed_vars}"
# Random delimeter string for security
delim=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
# Func to parse JSON with multiline strings, using delimeter (Github specific)
to_envs() { jq -r "to_entries[] | \"\(.key)=\(.value)\n\""; }
all_kv_pairs=$(echo "$parsed_vars" | to_envs)
echo "key=value pairs: ${all_kv_pairs}"
# Export wrapped multiline to GITHUB_OUTPUT
echo "all_vars<<EOF" >> $GITHUB_OUTPUT
echo $all_kv_pairs >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "Final GITHUB_ENV:"
cat $GITHUB_OUTPUT
## Comma separated output
# parsed_vars=$(jq -n --argjson VARS_CONTEXT "$VARS_CONTEXT" --argjson SECRETS_CONTEXT "$SECRETS_CONTEXT" '$VARS_CONTEXT + $SECRETS_CONTEXT')
# echo "Concat vars+secrets: ${parsed_vars}"
# # Parse all json as key=value pairs, single line, space separated
# to_comma_separated_kvs() { jq -r 'to_entries | map("\(.key)=\(.value)") | join(",")'; }
# all_kv_pairs=$(echo "$parsed_vars" | to_comma_separated_kvs)
# echo "key=value pairs: ${all_kv_pairs}"
# # Export as single line var
# echo "all_vars=${all_kv_pairs}" >> $GITHUB_OUTPUT
# echo "Final GITHUB_OUTPUT:"
# cat $GITHUB_OUTPUT