Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions util/GHA-delete-GNU-workflow-logs.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
#!/bin/sh

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

# ME="${0}"
Comment thread
xtqqczze marked this conversation as resolved.
# ME_dir="$(dirname -- "${ME}")"
# ME_parent_dir="$(dirname -- "${ME_dir}")"
# ME_parent_dir_abs="$(realpath -mP -- "${ME_parent_dir}")"

# ref: <https://stackoverflow.com/questions/57927115/anyone-know-a-way-to-delete-a-workflow-from-github-actions>

# note: requires `gh` and `jq`

## tools available?

# * `gh` available?
GH=$(command -v gh)
"${GH}" --version || (echo "ERR!: missing \`gh\` (see install instructions at <https://github.com/cli/cli>)"; exit 1)
# * `jq` or fallback available?
: ${JQ:=$(command -v jq || command -v jaq)}
"${JQ}" --version || (echo "ERR!: missing \`jq\` (install with \`sudo apt install jq\`)"; exit 1)
if ! command -v gh >/dev/null 2>&1; then
echo "ERR!: missing \`gh\` (see install instructions at <https://github.com/cli/cli>)" 1>&2
exit 1
fi

case "${dry_run}" in
'0' | 'f' | 'false' | 'no' | 'never' | 'none') unset dry_run ;;
Expand All @@ -30,7 +22,7 @@ REPO_NAME="${REPO_NAME:-coreutils}"
WORK_NAME="${WORK_NAME:-GNU}"

# * `--paginate` retrieves all pages
# 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 ;" _
"${GH}" api "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 ;" _
# gh api --paginate "repos/${USER_NAME}/${REPO_NAME}/actions/runs" --jq ".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 ;" _
gh api "repos/${USER_NAME}/${REPO_NAME}/actions/runs" \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we add --paginate here while at it? it works fine with --jq and the comment above already talks about it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not keen on refactoring this code, since I have no method to test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the commented out code is the same thing as below, but without --paginate, so apparently --paginate was consciously removed at some point.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented-out code using --paginate has been there since the file was originally added by @rivy: c74bc2e

--jq ".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 ;" _
Loading