mirror of
https://code.forgejo.org/actions/cascading-pr
synced 2025-06-26 21:38:02 +02:00
draft implementation
This commit is contained in:
parent
ec542726c8
commit
fc026df37e
2 changed files with 135 additions and 6 deletions
|
@ -12,6 +12,10 @@ DEBUG=false
|
|||
|
||||
: ${TMPDIR:=$(mktemp -d)}
|
||||
|
||||
: ${LOOPS:=80}
|
||||
|
||||
: ${LOOP_DELAY:=5}
|
||||
|
||||
function debug() {
|
||||
DEBUG=true
|
||||
set -x
|
||||
|
@ -72,3 +76,77 @@ function host_port() {
|
|||
echo ${host_port%%/}
|
||||
}
|
||||
|
||||
function scheme() {
|
||||
local url="$1"
|
||||
|
||||
echo "${url%%://*}"
|
||||
}
|
||||
|
||||
function get_status() {
|
||||
local api="$1"
|
||||
local sha="$2"
|
||||
|
||||
forgejo-curl.sh api_json $api/commits/$sha/status
|
||||
}
|
||||
|
||||
function check_status() {
|
||||
local api="$1"
|
||||
local sha="$2"
|
||||
local expected_status="$3"
|
||||
local expected_description="$3"
|
||||
|
||||
get_status $api $sha > $TMPDIR/status.json
|
||||
local status="$(jq --raw-output .state < $TMPDIR/status.json)"
|
||||
local description="$(jq --raw-output .statuses[0].description < $TMPDIR/status.json)"
|
||||
if test "$status" = "$expected_status" && test -z "$expected_description" -o "$description" = "$expected_description"; then
|
||||
echo OK
|
||||
elif test "$status" = "failure" -o "$status" = "success"; then
|
||||
echo NOK
|
||||
else
|
||||
echo RETRY
|
||||
fi
|
||||
}
|
||||
|
||||
function wait_success() {
|
||||
wait_status success "$@"
|
||||
}
|
||||
|
||||
function wait_failure() {
|
||||
wait_status failure "$@"
|
||||
}
|
||||
|
||||
function wait_running() {
|
||||
wait_status pending "$@" "Has started running"
|
||||
}
|
||||
|
||||
function wait_log() {
|
||||
local sha="$1" expected_status="$2" expected_description="$3"
|
||||
local status="$(jq --raw-output .state < $TMPDIR/status.json)"
|
||||
local description="$(jq --raw-output .statuses[0].description < $TMPDIR/status.json)"
|
||||
if test "$expected_description"; then
|
||||
expected_description=" '$expected_description'"
|
||||
fi
|
||||
log_info "$sha status waiting '$expected_status'$expected_description, currently '$status' '$description'"
|
||||
}
|
||||
|
||||
function wait_status() {
|
||||
local api="$2"
|
||||
local sha="$3"
|
||||
local status="$1"
|
||||
local description="$4"
|
||||
|
||||
for i in $(seq $LOOPS); do
|
||||
if test $(check_status "$api" "$sha" "$status" "$description") != RETRY ; then
|
||||
break
|
||||
fi
|
||||
wait_log "$sha" "$status" "$description"
|
||||
sleep $LOOP_DELAY
|
||||
done
|
||||
if test $(check_status "$api" "$sha" "$status" "$description") = "OK" ; then
|
||||
log_info "$sha status OK"
|
||||
else
|
||||
get_status $url $repo $sha | jq .statuses
|
||||
log_info "$sha status NOK"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue