feat: maintain server until hour
This commit is contained in:
@@ -20,12 +20,30 @@ gcr_gitea_admin_token() {
|
||||
tr -d '\n' < "$GITEA_ADMIN_TOKEN_FILE"
|
||||
}
|
||||
|
||||
# gcr_gitea_list_runners — prints "id name" lines for org hectic-lab.
|
||||
# gcr_gitea_list_runners REPO — prints "id name" lines for repo runners.
|
||||
gcr_gitea_list_runners() {
|
||||
repo="$1"
|
||||
token="$(gcr_gitea_admin_token)" || return 1
|
||||
owner="${repo%%/*}"
|
||||
name="${repo#*/}"
|
||||
curl -fsS -H "Authorization: token $token" \
|
||||
"$GCR_GITEA_URL/api/v1/orgs/hectic-lab/actions/runners?per_page=50" \
|
||||
| jq -r '.entries[]? | "\(.id) \(.name)"'
|
||||
"$GCR_GITEA_URL/api/v1/repos/$owner/$name/actions/runners" \
|
||||
| jq -r '.runners[]? | "\(.id) \(.name)"'
|
||||
}
|
||||
|
||||
# gcr_gitea_list_org_repos OWNER — prints fully-qualified repository names.
|
||||
gcr_gitea_list_org_repos() {
|
||||
owner="$1"
|
||||
token="$(gcr_gitea_admin_token)" || return 1
|
||||
page=1
|
||||
while :; do
|
||||
repos="$(curl -fsS -H "Authorization: token $token" \
|
||||
"$GCR_GITEA_URL/api/v1/orgs/$owner/repos?page=$page&limit=50")" || return 1
|
||||
printf '%s' "$repos" | jq -r '.[]? | .full_name'
|
||||
count="$(printf '%s' "$repos" | jq 'length')" || return 1
|
||||
[ "$count" -lt 50 ] && return 0
|
||||
page=$((page + 1))
|
||||
done
|
||||
}
|
||||
|
||||
# gcr_gitea_job_state REPO JOB_ID — prints "<status>:<conclusion>".
|
||||
@@ -40,8 +58,35 @@ gcr_gitea_job_state() {
|
||||
}
|
||||
|
||||
gcr_gitea_delete_runner() {
|
||||
id="$1"
|
||||
repo="$1"; id="$2"
|
||||
token="$(gcr_gitea_admin_token)" || return 1
|
||||
owner="${repo%%/*}"
|
||||
name="${repo#*/}"
|
||||
curl -fsS -X DELETE -H "Authorization: token $token" \
|
||||
"$GCR_GITEA_URL/api/v1/orgs/hectic-lab/actions/runners/$id"
|
||||
"$GCR_GITEA_URL/api/v1/repos/$owner/$name/actions/runners/$id"
|
||||
}
|
||||
|
||||
gcr_gitea_set_runner_disabled() {
|
||||
repo="$1"; id="$2"; disabled="$3"
|
||||
case "$disabled" in true|false) ;; *) return 1 ;; esac
|
||||
token="$(gcr_gitea_admin_token)" || return 1
|
||||
owner="${repo%%/*}"
|
||||
name="${repo#*/}"
|
||||
curl -fsS -X PATCH -H "Authorization: token $token" \
|
||||
-H 'Content-Type: application/json' --data "{\"disabled\":$disabled}" \
|
||||
"$GCR_GITEA_URL/api/v1/repos/$owner/$name/actions/runners/$id" >/dev/null
|
||||
}
|
||||
|
||||
# gcr_gitea_runner_disabled REPO RUNNER_NAME true|false
|
||||
gcr_gitea_runner_disabled() {
|
||||
repo="$1"; runner_name="$2"; disabled="$3"
|
||||
runners="$(gcr_gitea_list_runners "$repo")" || return 1
|
||||
while read -r id name; do
|
||||
[ "$name" = "$runner_name" ] || continue
|
||||
gcr_gitea_set_runner_disabled "$repo" "$id" "$disabled"
|
||||
return "$?"
|
||||
done <<EOF
|
||||
$runners
|
||||
EOF
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user