-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
74 lines (67 loc) · 2.77 KB
/
action.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
70
71
72
73
74
---
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions
name: Flatten Contexts
author: '@vbem'
description: Dump flattened GitHub contexts for friendly debugging
branding:
icon: align-justify
color: green
inputs:
sep:
description: 'Separator between key and value'
required: false
default: ''
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-composite-actions
outputs: {}
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-actions
runs:
using: composite
steps:
- name: Dump flattened GitHub actions contexts for debugging
id: main
env:
STEP_CTX_GITHUB: ${{ toJson(github) }}
STEP_CTX_JOB: ${{ toJson(job) }}
STEP_CTX_STEPS: ${{ toJson(steps) }}
STEP_CTX_RUNNER: ${{ toJson(runner) }}
STEP_CTX_STRATEGY: ${{ toJson(strategy) }}
STEP_CTX_MATRIX: ${{ toJson(matrix) }}
shell: bash
run: |
# implementation details
# Group stdin to stderr with title
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines
# $1: group title
# stdin: logs
# stderr: grouped logs
# $?: 0 if successful and non-zero otherwise
function kit::wf::group {
echo "::group::$1" >&2
echo "$(< /dev/stdin)" >&2
echo '::endgroup::' >&2
}
# Flatten JSON to key-value lines
# $1: separator (default as ' 👉 ')
# stdin: json
# stdout: flattened key-value lines
# $?: 0 if successful and non-zero otherwise
function kit::json::flatten {
jq -Mcr --arg sep "${1:- 👉 }" \
'paths(type!="object" and type!="array") as $p | {"key":$p|join("."),"value":getpath($p)} | "\(.key)\($sep)\(.value|@json)"'
}
# Render the context
# $1: context name
# stdin: json
# stderr: redered output
# $?: 0 if successful and non-zero otherwise
function render {
kit::json::flatten '${{ inputs.sep }}' | kit::wf::group "📚 GitHub context: '$1'"
}
jq -Mcre '{runner:.}' <<< "$STEP_CTX_RUNNER" | render "runner"
jq -Mcre 'del(.token)|del(.event)|{github:.}' <<< "$STEP_CTX_GITHUB" | render "github"
jq -Mcre '{github:{event:.event}}' <<< "$STEP_CTX_GITHUB" | render "github.event"
jq -Mcre '{job:.}' <<< "$STEP_CTX_JOB" | render "job"
jq -Mcre '{steps:.}' <<< "$STEP_CTX_STEPS" | render "steps"
jq -Mcre '{strategy:.}' <<< "$STEP_CTX_STRATEGY" | render "strategy"
jq -Mcre '{matrix:.}' <<< "$STEP_CTX_MATRIX" | render "matrix"
...