Skip to content

Commit 3528d10

Browse files
authored
GHA-delete-GNU-workflow-logs.sh: Support custom jq command and support jaq for the case it is not installed as jq (#9581)
1 parent a7c9d03 commit 3528d10

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed
Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
# spell-checker:ignore (utils) gitsome jq ; (gh) repos
3+
# spell-checker:ignore (utils) gitsome jq jaq ; (gh) repos
44

55
# ME="${0}"
66
# ME_dir="$(dirname -- "${ME}")"
@@ -14,24 +14,11 @@
1414
## tools available?
1515

1616
# * `gh` available?
17-
unset GH
18-
if gh --version 1>/dev/null 2>&1; then
19-
export GH="gh"
20-
else
21-
echo "ERR!: missing \`gh\` (see install instructions at <https://github.com/cli/cli>)" 1>&2
22-
fi
23-
24-
# * `jq` available?
25-
unset JQ
26-
if jq --version 1>/dev/null 2>&1; then
27-
export JQ="jq"
28-
else
29-
echo "ERR!: missing \`jq\` (install with \`sudo apt install jq\`)" 1>&2
30-
fi
31-
32-
if [ -z "${GH}" ] || [ -z "${JQ}" ]; then
33-
exit 1
34-
fi
17+
GH=$(command -v gh)
18+
"${GH}" --version || (echo "ERR!: missing \`gh\` (see install instructions at <https://github.com/cli/cli>)"; exit 1)
19+
# * `jq` or fallback available?
20+
: ${JQ:=$(command -v jq || command -v jaq)}
21+
"${JQ}" --version || (echo "ERR!: missing \`jq\` (install with \`sudo apt install jq\`)"; exit 1)
3522

3623
case "${dry_run}" in
3724
'0' | 'f' | 'false' | 'no' | 'never' | 'none') unset dry_run ;;
@@ -44,6 +31,6 @@ WORK_NAME="${WORK_NAME:-GNU}"
4431

4532
# * `--paginate` retrieves all pages
4633
# gh api --paginate "repos/${USER_NAME}/${REPO_NAME}/actions/runs" | jq -r ".workflow_runs[] | select(.name == \"${WORK_NAME}\") | (.id)" | xargs -n1 sh -c "for arg do { echo gh api repos/${USER_NAME}/${REPO_NAME}/actions/runs/\${arg} -X DELETE ; if [ -z "$dry_run" ]; then gh api repos/${USER_NAME}/${REPO_NAME}/actions/runs/\${arg} -X DELETE ; fi ; } ; done ;" _
47-
gh api "repos/${USER_NAME}/${REPO_NAME}/actions/runs" |
48-
jq -r ".workflow_runs[] | select(.name == \"${WORK_NAME}\") | (.id)" |
49-
xargs -n1 sh -c "for arg do { echo gh api repos/${USER_NAME}/${REPO_NAME}/actions/runs/\${arg} -X DELETE ; if [ -z \"${dry_run}\" ]; then gh api repos/${USER_NAME}/${REPO_NAME}/actions/runs/\${arg} -X DELETE ; fi ; } ; done ;" _
34+
"${GH}" api "repos/${USER_NAME}/${REPO_NAME}/actions/runs" |
35+
"${JQ}" -r ".workflow_runs[] | select(.name == \"${WORK_NAME}\") | (.id)" |
36+
xargs -n1 sh -c "for arg do { echo ${GH} api repos/${USER_NAME}/${REPO_NAME}/actions/runs/\${arg} -X DELETE ; if [ -z \"${dry_run}\" ]; then ${GH} api repos/${USER_NAME}/${REPO_NAME}/actions/runs/\${arg} -X DELETE ; fi ; } ; done ;" _

0 commit comments

Comments
 (0)