interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / scripts / ci-status.sh

101 lines · 4079 bytes Raw Blame History
1#!/usr/bin/env bash
2# List GitHub Actions workflow runs that are not finished yet, grouped by status.
3
4set -euo pipefail
5
6usage() {
7 echo "usage: $(basename "$0") [-r owner/repo] [-s status]... [-b branch] [-w regex] [-t regex] [-f regex] [--kill [-y]]"
8 echo " -r, --repo repository (default: current)"
9 echo " -s, --status run status to include, repeatable (default: the not-finished ones)"
10 echo " -b, --branch branch to fetch runs for; exact match, handled by the API"
11 echo " -w, --workflow case-insensitive regex matched against the workflow name (client-side)"
12 echo " -t, --title case-insensitive regex matched against the run title (client-side)"
13 echo " -f, --filter case-insensitive regex matched against the branch name (client-side)"
14 echo " --kill cancel the selected runs (requires -b, -w, -t or -f)"
15 echo " -y, --yes skip the confirmation prompt of --kill"
16}
17
18repo=""
19branch=""
20workflow=""
21title=""
22filter=""
23kill=false
24assume_yes=false
25statuses=()
26need_value() { echo "missing value for $1" >&2; exit 1; }
27while [[ $# -gt 0 ]]; do
28 case "$1" in
29 -r|--repo) [[ $# -ge 2 ]] || need_value "$1"; repo="$2"; shift 2 ;;
30 -s|--status) [[ $# -ge 2 ]] || need_value "$1"; statuses+=("$2"); shift 2 ;;
31 -b|--branch) [[ $# -ge 2 ]] || need_value "$1"; branch="$2"; shift 2 ;;
32 -w|--workflow) [[ $# -ge 2 ]] || need_value "$1"; workflow="$2"; shift 2 ;;
33 -t|--title) [[ $# -ge 2 ]] || need_value "$1"; title="$2"; shift 2 ;;
34 -f|--filter) [[ $# -ge 2 ]] || need_value "$1"; filter="$2"; shift 2 ;;
35 --kill) kill=true; shift ;;
36 -y|--yes) assume_yes=true; shift ;;
37 -h|--help) usage; exit 0 ;;
38 *) echo "unknown argument: $1" >&2; exit 1 ;;
39 esac
40done
41
42# one request per status: the API does not accept multiple statuses at once
43[[ ${#statuses[@]} -gt 0 ]] || statuses=(in_progress queued pending waiting requested)
44
45[[ -n "$repo" ]] || repo=$(gh repo view --json nameWithOwner -q .nameWithOwner)
46
47query=("repos/$repo/actions/runs" -f per_page=100)
48[[ -z "$branch" ]] || query+=(-f branch="$branch")
49
50selected=$(
51 for status in "${statuses[@]}"; do
52 gh api --paginate --method GET "${query[@]}" -f status="$status" -q '.workflow_runs[]'
53 done | jq -sr --arg branch "$branch" --arg workflow "$workflow" --arg title "$title" --arg filter "$filter" '
54 unique_by(.id)
55 | map(
56 .age = ((now - (.run_started_at // .created_at | fromdate)) / 60 | floor)
57 | select(
58 ($branch == "" or .head_branch == $branch) and
59 ($workflow == "" or (.name | test($workflow; "i"))) and
60 ($title == "" or (.display_title | test($title; "i"))) and
61 ($filter == "" or (.head_branch | test($filter; "i")))
62 )
63 )
64 | sort_by(.status, -.age)'
65)
66
67tsv=$(jq -r '.[] | [ .status, (.age | tostring) + "m", .name, .head_branch, .display_title, .html_url ] | @tsv' <<< "$selected")
68
69if [[ -z "$tsv" ]]; then
70 echo "no active runs in $repo"
71 exit 0
72fi
73
74printf 'STATUS\tAGE\tWORKFLOW\tBRANCH\tTITLE\tURL\n%s\n' "$tsv" | column -t -s $'\t'
75echo
76printf '%s:' "$repo"
77for status in "${statuses[@]}"; do
78 printf ' %s=%s' "$status" "$(awk -F'\t' -v s="$status" '$1 == s' <<< "$tsv" | wc -l | tr -d ' ')"
79done
80echo
81
82if [[ "$kill" == false ]]; then
83 exit 0
84fi
85
86if [[ -z "$branch$workflow$title$filter" ]]; then
87 echo "refusing to cancel everything: pass -b, -w, -t or -f to select the runs to cancel" >&2
88 exit 1
89fi
90
91count=$(wc -l <<< "$tsv" | tr -d ' ')
92if [[ "$assume_yes" == false ]]; then
93 printf 'cancel %s run(s)? [y/N] ' "$count"
94 read -r reply </dev/tty || { echo; echo "aborted: no terminal to confirm on" >&2; exit 1; }
95 [[ "$reply" == [yY]* ]] || { echo "aborted"; exit 1; }
96fi
97
98jq -r '.[] | [ .id, .status ] | @tsv' <<< "$selected" |
99while IFS=$'\t' read -r id status; do
100 gh run cancel "$id" --repo "$repo" || echo "failed to cancel run $id (status: $status)"
101done