Skip to content

Commit

Permalink
Merge pull request #39 from pentaho/HNC-743
Browse files Browse the repository at this point in the history
[HNC-743] - Export Github Actions workflow run metadata into ENV vari…
  • Loading branch information
cardosov authored Aug 13, 2024
2 parents 318a1e8 + 5079ffb commit cbba217
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,32 @@ jobs:

steps:

- name: Load Job metadata into Env vars
shell: bash
continue-on-error: true
env:
JOB_CONTEXT: ${{ toJSON(job) }}
run: |
process_json() {
local prefix=$1
local json_data=$2
echo "$json_data" | jq -r 'to_entries | .[] | "\(.key) \(.value|tostring)"' | while read -r key value; do
# Check if the value is a JSON object or array
is_json=$(echo $value | jq -e . >/dev/null 2>&1 ; echo ${PIPESTATUS[1]})
if [[ $is_json == 0 ]]; then
# If it's an object or array, call the function recursively
process_json "${prefix}${key}_" "$(echo "$json_data" | jq -c ."$key")"
else
echo "Creating \"${prefix}${key}\" env var with the value \"${value}\""
echo "${prefix}${key}=${value}" >> $GITHUB_ENV
fi
done
}
# Start processing JSON from the root
echo "Dealing with ${{ env.JOB_CONTEXT }}"
process_json '' '${{ env.JOB_CONTEXT }}'
- name: Checkout code
uses: actions/checkout@v4
with:
Expand Down

0 comments on commit cbba217

Please sign in to comment.