-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
refactor: use gh api --jq instead of jq
#14963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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}" | ||
| # 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 ;; | ||
|
|
@@ -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" \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we add
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| --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 ;" _ | ||
Uh oh!
There was an error while loading. Please reload this page.