| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# spell-checker:ignore (utils) gitsome jq jaq ; (gh) repos |
| 4 |
|
| 5 |
# ME="${0}" |
| 6 |
# ME_dir="$(dirname -- "${ME}")" |
| 7 |
# ME_parent_dir="$(dirname -- "${ME_dir}")" |
| 8 |
# ME_parent_dir_abs="$(realpath -mP -- "${ME_parent_dir}")" |
| 9 |
|
| 10 |
# ref: <https://stackoverflow.com/questions/57927115/anyone-know-a-way-to-delete-a-workflow-from-github-actions> |
| 11 |
|
| 12 |
# note: requires `gh` and `jq` |
| 13 |
|
| 14 |
## tools available? |
| 15 |
|
| 16 |
# * `gh` available? |
| 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) |
| 22 |
|
| 23 |
case "${dry_run}" in |
| 24 |
'0' | 'f' | 'false' | 'no' | 'never' | 'none') unset dry_run ;; |
| 25 |
*) dry_run="true" ;; |
| 26 |
esac |
| 27 |
|
| 28 |
USER_NAME="${USER_NAME:-uutils}" |
| 29 |
REPO_NAME="${REPO_NAME:-coreutils}" |
| 30 |
WORK_NAME="${WORK_NAME:-GNU}" |
| 31 |
|
| 32 |
# * `--paginate` retrieves all pages |
| 33 |
# 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 ;" _ |
| 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 ;" _ |