2021-06-13 05:36:05 +00:00
#!/bin/sh
# spell-checker:ignore (utils) gitsome jq ; (gh) repos
2022-02-06 23:03:57 +00:00
# ME="${0}"
# ME_dir="$(dirname -- "${ME}")"
# ME_parent_dir="$(dirname -- "${ME_dir}")"
# ME_parent_dir_abs="$(realpath -mP -- "${ME_parent_dir}")"
2021-06-13 05:36:05 +00:00
# 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?
unset GH
2022-02-01 06:55:11 +00:00
if gh --version 1>/dev/null 2>& 1; then
export GH = "gh"
else
echo "ERR!: missing \`gh\` (see install instructions at <https://github.com/cli/cli>)" 1>& 2
fi
2021-06-13 05:36:05 +00:00
# * `jq` available?
unset JQ
2022-02-01 06:55:11 +00:00
if jq --version 1>/dev/null 2>& 1; then
export JQ = "jq"
else
echo "ERR!: missing \`jq\` (install with \`sudo apt install jq\`)" 1>& 2
fi
2021-06-13 05:36:05 +00:00
if [ -z " ${ GH } " ] || [ -z " ${ JQ } " ] ; then
exit 1
fi
2022-02-06 23:03:57 +00:00
case " ${ dry_run } " in
'0' | 'f' | 'false' | 'no' | 'never' | 'none' ) unset dry_run ; ;
*) dry_run = "true" ; ;
esac
2021-06-13 05:36:05 +00:00
2022-02-06 23:03:57 +00:00
USER_NAME = " ${ USER_NAME :- uutils } "
REPO_NAME = " ${ REPO_NAME :- coreutils } "
WORK_NAME = " ${ WORK_NAME :- GNU } "
2021-06-13 05:36:05 +00:00
# * `--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 ;" _
2022-02-06 23:03:57 +00:00
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 ; " _