-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yaml
375 lines (348 loc) · 12.7 KB
/
action.yaml
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
name: jq Direct
branding:
icon: code
color: blue
description: Simple and robust jq action offering updated jq versions, YAML input/output conversions, input from command or text & more!
inputs:
#
# Action arguments
#
arguments:
default: ""
description: Pass arguments directly to jq
required: false
debug:
default: false
description: Add debug output
required: false
filter:
default: .
description: jq filter (will be ignored if from-file is specified)
required: false
input:
default: ""
description: Input for jq
required: false
input-command:
default: ''
description: Command run in bash, output will be used by jq as input
required: false
input-files:
default: ''
description: One or more filenames for jq to use as input
required: false
input-yaml:
default: ""
description: Input for jq in YAML format - will transform into JSON for jq
required: false
output-yaml:
default: false
description: Output in YAML format - will transform jq JSON output
required: false
quiet:
default: false
description: Suppress JSON output when available
required: false
version:
default: 1.7.1
description: Version of jq - will retrieve if necessary, "" will use existing version
required: false
#
# Following are implementations of jq's native arguments
#
arg:
default: ""
description: (jq arg) set $name to the string value - specify as YAML map
required: false
args:
default: ""
description: (jq arg) positional string values
required: false
argjson:
default: ""
description: (jq arg) set $name to the JSON value - specify is YAML map
required: false
ascii-output:
default: false
description: (jq arg -a) output strings by only ASCII characters using escape sequences
required: false
compact-output:
default: false
description: (jq arg -c) compact instead of pretty-printed output
required: false
exit-status:
default: false
description: (jq arg -e) set exit status code based on the output
required: false
from-file:
default: ''
description: (jq arg -f) load filter from the file
required: false
indent:
default: ''
description: (jq arg) use n spaces for indentation (max 7 spaces)
required: false
join-output:
default: false
description: (jq arg -j) implies -r and output without newline after each output
required: false
jsonargs:
default: ''
description: (jq arg) positional JSON values
required: false
module-directory:
default: ''
description: (jq arg -L) search modules from the directory
required: false
null-input:
default: false
description: (jq arg -n) use null as the single input value
required: false
raw-input:
default: false
description: (jq arg -R) read each line as string instead of JSON
required: false
raw-output:
default: false
description: (jq arg -r) output strings without escapes and quotes
required: false
raw-output0:
default: false
description: (jq arg) implies -r and output NUL after each output
required: false
rawfile:
default: ""
description: (jq arg) set $name to string contents of file - specify as YAML map
required: false
seq:
default: false
description: (jq arg) parse input/output as application/json-seq
required: false
slurp:
default: false
description: (jq arg -s) read all inputs into an array and use it as the single input value
required: false
slurpfile:
default: ""
description: (jq arg) name file set $name to an array of JSON values read from the file - specify as YAML map
required: false
sort-keys:
default: false
description: (jq arg -S) sort keys of each object on output
required: false
stream:
default: false
description: (jq arg) parse the input value in streaming fashion
required: false
stream-errors:
default: false
description: (jq arg) implies --stream and report parse error as an array
required: false
tab:
default: false
description: (jq arg) use tabs for indentation
required: false
unbuffered:
default: false
description: (jq arg) flush output stream after each output
required: false
# -C, --color-output colorize JSON output
# -M, --monochrome-output disable colored output
# --build-configuration show jq's build configuration
# -- terminates argument processing
outputs:
is-json:
description: Is output JSON - "true" or "false"
value: ${{ steps.jq.outputs.is-json }}
output:
description: Output from jq command
value: ${{ steps.jq.outputs.output }}
runs:
using: composite
steps:
- env:
JQ_BIN_DIR: "${{ runner.temp }}/.direct-actions/jq/${{ inputs.version }}"
INPUTS_arg: ${{ inputs.arg }}
INPUTS_args: ${{ inputs.args }}
INPUTS_argjson: ${{ inputs.argjson }}
INPUTS_arguments: ${{ inputs.arguments }}
INPUTS_jsonargs: ${{ inputs.jsonargs }}
INPUTS_slurpfile: ${{ inputs.slurpfile }}
INPUTS_rawfile: ${{ inputs.rawfile }}
id: setup-jq
run: |
# setup-jq
#
${{ inputs.debug == 'true' && 'set -x' || '' }}
JQ_OS=$(uname -s)
if [ "$JQ_OS" = "Darwin" ] ; then
JQ_OS=macos
elif [ "$JQ_OS" = "Linux" ] ; then
JQ_OS=linux
else
echo "::error title=Unknown Runner OS::Unknown runner OS reported by uname -s (${JQ_OS})"
exit 1
fi
JQ_ARCH=$(uname -m)
if [ "$JQ_ARCH" = "aarch64" ] ; then
JQ_ARCH=arm64
elif [ "$JQ_ARCH" = "x86_64" ] ; then
JQ_ARCH=amd64
fi
JQ_BIN_FILE="jq-${JQ_OS}-${JQ_ARCH}"
if [ -z '${{ inputs.version }}' ] ; then
JQ_BIN=$(command -v jq)
else
JQ_BIN="${JQ_BIN_DIR}/${JQ_BIN_FILE}"
fi
if [ -x "${JQ_BIN}" ] ; then
JQ_BIN_EXISTS=true
else
JQ_BIN_EXISTS=false
fi
JQ_BIN_FILE="jq-${JQ_OS}-${JQ_ARCH}"
# Process inputs
#
INPUT=$(mktemp)
INPUT_YAML=$(mktemp)
if ${{ inputs.input != '' }} ; then
cat <<'__EOF_DA_JQ__' >"$INPUT"
${{ inputs.input }}
__EOF_DA_JQ__
else
INPUT=
fi
if ${{ inputs.input-yaml != '' }} ; then
cat <<'__EOF_DA_JQ__' | yq @json >"$INPUT_YAML"
${{ inputs.input-yaml }}
__EOF_DA_JQ__
else
INPUT_YAML=
fi
# Process arguments
#
JQ_ARGS_STRING=
# binary flags
JQ_ARGS=()
if [ '${{ inputs.ascii-output }}' == true ] ; then JQ_ARGS+=(-a) ; fi
if [ '${{ inputs.compact-output }}' == true ] ; then JQ_ARGS+=(-c) ; fi
if [ '${{ inputs.exit-status }}' == true ] ; then JQ_ARGS+=(--exit-status) ; fi
if [ '${{ inputs.join-output }}' == true ] ; then JQ_ARGS+=(-j) ; fi
if [ '${{ inputs.null-input }}' == true ] ; then JQ_ARGS+=(-n) ; fi
if [ '${{ inputs.raw-input }}' == true ] ; then JQ_ARGS+=(-R) ; fi
if [ '${{ inputs.raw-output }}' == true ] ; then JQ_ARGS+=(-r) ; fi
if [ '${{ inputs.raw-output0 }}' == true ] ; then JQ_ARGS+=(--raw-output0) ; fi
if [ '${{ inputs.seq }}' == true ] ; then JQ_ARGS+=(--seq) ; fi
if [ '${{ inputs.slurp }}' == true ] ; then JQ_ARGS+=(-s) ; fi
if [ '${{ inputs.sort-keys }}' == true ] ; then JQ_ARGS+=(-S) ; fi
if [ '${{ inputs.stream }}' == true ] ; then JQ_ARGS+=(--stream) ; fi
if [ '${{ inputs.stream-errors }}' == true ] ; then JQ_ARGS+=(--stream-errors) ; fi
if [ '${{ inputs.tab }}' == true ] ; then JQ_ARGS+=(--tab) ; fi
if [ '${{ inputs.unbuffered }}' == true ] ; then JQ_ARGS+=(--unbuffered) ; fi
# simple parameters
if [ -n '${{ inputs.from-file }}' ] ; then
JQ_ARGS+=(--from-file)
JQ_ARGS+=('${{ inputs.from-file }}')
fi
if [ -n '${{ inputs.indent }}' ] ; then
JQ_ARGS+=(--indent)
JQ_ARGS+=('${{ inputs.indent }}')
fi
if [ -n '${{ inputs.module-directory }}' ] ; then
JQ_ARGS+=(--module-directory)
JQ_ARGS+=('${{ inputs.module-directory }}')
fi
for arg in "${JQ_ARGS[@]}" ; do
JQ_ARGS_STRING+=" $arg"
done
# yaml transforms - let yq take care of quoting
if ${{ inputs.arg != '' }} ; then
JQ_ARGS_STRING+=' '$(yq @json <<<"$INPUTS_arg" | jq "to_entries[] | \"--arg\", .key, .value" | tr '\n' ' ')
fi
if ${{ inputs.argjson != '' }} ; then
JQ_ARGS_STRING+=' '$(yq @json <<<"$INPUTS_argjson" | jq "to_entries[] | \"--argjson\", .key, .value" | tr '\n' ' ')
fi
if ${{ inputs.rawfile != '' }} ; then
JQ_ARGS_STRING+=' '$(yq @json <<<"$INPUTS_rawfile" | jq "to_entries[] | \"--rawfile\", .key, .value" | tr '\n' ' ')
fi
if ${{ inputs.slurpfile != '' }} ; then
JQ_ARGS_STRING+=' '$(yq @json <<<"$INPUTS_slurpfile" | jq "to_entries[] | \"--slurpfile\", .key, .value" | tr '\n' ' ')
fi
# inject input.arguments, and finish arguments
if ${{ inputs.arguments != '' }} ; then
JQ_ARGS_STRING+=" ${INPUTS_arguments}"
fi
# finally, "remaining arguments are..."
JQ_ARGS=()
if ${{ inputs.args != '' }} && ${{ inputs.jsonargs != '' }} ; then
echo '::error title=Invalid parameters::Cannot specify both args and jsonargs parameters'
exit 1
fi
if ${{ inputs.args != '' }} ; then
JQ_ARGS+=(--args)
fi
if ${{ inputs.jsonargs != '' }} ; then
JQ_ARGS+=(--jsonargs)
fi
append_args() {
while [ -n "$1" ] ; do
JQ_ARGS+=("$1")
shift
done
}
append_args $INPUTS_args $INPUTS_jsonargs
for arg in "${JQ_ARGS[@]}" ; do
JQ_ARGS_STRING+=" $arg"
done
${{ inputs.quiet == 'true' && '' || 'echo ::group::setup-jq outputs' }}
cat <<_EOF_ ${{ inputs.quiet == 'true' && '>' || '| tee -a' }} "$GITHUB_OUTPUT"
file-input=${INPUT}
file-input-yaml=${INPUT_YAML}
jq-args=${JQ_ARGS_STRING# }
jq-bin=${JQ_BIN}
jq-bin-dir=${JQ_BIN_DIR}
jq-bin-exists=${JQ_BIN_EXISTS}
jq-bin-file=${JQ_BIN_FILE}
_EOF_
${{ inputs.quiet == 'true' && '' || 'echo ::endgroup::' }}
shell: bash
- env:
JQ_BIN: ${{ steps.setup-jq.outputs.jq-bin }}
JQ_BIN_DIR: ${{ steps.setup-jq.outputs.jq-bin-dir }}
JQ_BIN_FILE: ${{ steps.setup-jq.outputs.jq-bin-file }}
JQ_URL: https://github.com/jqlang/jq/releases/download/jq-${{ inputs.version }}/${{ steps.setup-jq.outputs.jq-bin-file }}
if: ${{ steps.setup-jq.outputs.jq-bin-exists != 'true' }}
run: |
# Retrieving jq (${{ inputs.version }})
${{ inputs.debug == 'true' && 'set -x' || '' }}
if [ ! -d "$JQ_BIN_DIR" ] ; then
mkdir -p "$JQ_BIN_DIR"
fi
curl --output-dir "$JQ_BIN_DIR" -Ofs -L "$JQ_URL"
chmod 755 "$JQ_BIN"
shell: bash
- env:
JQ_ARGS: ${{ steps.setup-jq.outputs.jq-args }}
JQ_BIN: ${{ steps.setup-jq.outputs.jq-bin }}
JQ_FILTER: ${{ inputs.from-file == '' && inputs.filter || '' }}
JQ_INPUT_FILES: ${{ steps.setup-jq.outputs.file-input }} ${{ steps.setup-jq.outputs.file-input-yaml }} ${{ inputs.input-files }}
id: jq
run: |
# jq
${{ inputs.debug == 'true' && 'set -x' || '' }}
output=$(mktemp)
${{ inputs.quiet == 'true' && '' || 'echo ::group::jq' }}
${{ inputs.input-command }}${{ inputs.input-command != '' && ' | ' || '' }}"$JQ_BIN" ${{ env.JQ_FILTER == '' && '' || '"' }}$JQ_FILTER${{ env.JQ_FILTER == '' && '' || '"' }} $JQ_INPUT_FILES ${{ steps.setup-jq.outputs.jq-args }} ${{ inputs.quiet == 'true' && '>' || '| tee' }} "$output"
${{ inputs.quiet == 'true' && '' || 'echo ::endgroup::' }}
echo 'output<<_EOF_' >>"${GITHUB_OUTPUT}"
cat "$output" >>"${GITHUB_OUTPUT}"
echo '_EOF_' >>"${GITHUB_OUTPUT}"
if "$JQ_BIN" '""' "$output" >/dev/null 2>&1 ; then
echo 'is-json=true' >> "$GITHUB_OUTPUT"
${{ inputs.quiet == 'true' && '' || 'echo ::group::JSON' }}
${{ inputs.quiet == 'true' && '' || '"$JQ_BIN" -C . "$output"' }}
${{ inputs.quiet == 'true' && '' || 'echo ::endgroup::' }}
else
echo 'is-json=false' >> "$GITHUB_OUTPUT"
fi
shell: bash