mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-07-22 07:18:26 +02:00
Reviewed-on: https://code.forgejo.org/actions/cascading-pr/pulls/36 Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
98b48e57d7
commit
06248c771c
5 changed files with 526 additions and 518 deletions
|
@ -21,30 +21,30 @@ DEBUG=false
|
|||
: ${RETRY_DELAYS:=1 1 5 5 15 30}
|
||||
|
||||
function dependencies() {
|
||||
if ! which jq curl > /dev/null ; then
|
||||
apt-get update -qq
|
||||
apt-get -qq install -y jq curl
|
||||
if ! which jq curl >/dev/null; then
|
||||
apt-get update -qq
|
||||
apt-get -qq install -y jq curl
|
||||
fi
|
||||
}
|
||||
|
||||
function retry() {
|
||||
rm -f $TMPDIR/retry.{out,attempt,err}
|
||||
local success=false
|
||||
for delay in $RETRY_DELAYS ; do
|
||||
if "$@" > $TMPDIR/retry.attempt 2>> $TMPDIR/retry.err ; then
|
||||
for delay in $RETRY_DELAYS; do
|
||||
if "$@" >$TMPDIR/retry.attempt 2>>$TMPDIR/retry.err; then
|
||||
success=true
|
||||
break
|
||||
fi
|
||||
cat $TMPDIR/retry.{err,attempt} >> $TMPDIR/retry.out
|
||||
cat $TMPDIR/retry.{err,attempt} >>$TMPDIR/retry.out
|
||||
cat $TMPDIR/retry.{err,attempt} >&2
|
||||
echo waiting $delay "$@" >&2
|
||||
sleep $delay
|
||||
done
|
||||
if $success ; then
|
||||
cat $TMPDIR/retry.attempt
|
||||
return 0
|
||||
if $success; then
|
||||
cat $TMPDIR/retry.attempt
|
||||
return 0
|
||||
else
|
||||
echo retry failed for "$@" >&2
|
||||
echo retry failed for "$@" >&2
|
||||
cat $TMPDIR/retry.out >&2
|
||||
return 1
|
||||
fi
|
||||
|
@ -70,8 +70,8 @@ function log_error() {
|
|||
}
|
||||
|
||||
function log_verbose() {
|
||||
if $VERBOSE ; then
|
||||
log_info "$@"
|
||||
if $VERBOSE; then
|
||||
log_info "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -81,20 +81,20 @@ function log_info() {
|
|||
|
||||
function fatal_error() {
|
||||
log_error "$@"
|
||||
if $EXIT_ON_ERROR ; then
|
||||
exit 1
|
||||
if $EXIT_ON_ERROR; then
|
||||
exit 1
|
||||
else
|
||||
return 1
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function stash_debug() {
|
||||
echo start $SELF
|
||||
mkdir -p $TMPDIR
|
||||
> $TMPDIR/run.out
|
||||
>$TMPDIR/run.out
|
||||
tail --follow $TMPDIR/run.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" &
|
||||
pid=$!
|
||||
if ! $SELF --debug "$@" >& $TMPDIR/run.out ; then
|
||||
if ! $SELF --debug "$@" >&$TMPDIR/run.out; then
|
||||
kill $pid
|
||||
cat $TMPDIR/run.out
|
||||
echo fail $SELF
|
||||
|
@ -142,15 +142,15 @@ function check_status() {
|
|||
local expected_status="$3"
|
||||
local expected_description="$4"
|
||||
|
||||
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)"
|
||||
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
|
||||
echo OK
|
||||
elif test "$status" = "failure" -o "$status" = "success"; then
|
||||
echo NOK
|
||||
echo NOK
|
||||
else
|
||||
echo RETRY
|
||||
echo RETRY
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -168,10 +168,10 @@ function wait_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)"
|
||||
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'"
|
||||
expected_description=" '$expected_description'"
|
||||
fi
|
||||
log_info "$sha status waiting '$expected_status'$expected_description, currently '$status' '$description'"
|
||||
}
|
||||
|
@ -183,31 +183,31 @@ function wait_status() {
|
|||
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
|
||||
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"
|
||||
if test $(check_status "$api" "$sha" "$status" "$description") = "OK"; then
|
||||
log_info "$sha status OK"
|
||||
else
|
||||
get_status $api $sha | jq .statuses
|
||||
log_info "$sha status NOK"
|
||||
return 1
|
||||
get_status $api $sha | jq .statuses
|
||||
log_info "$sha status NOK"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function sanity_check_pr_or_ref() {
|
||||
local pr="$1" ref="$2"
|
||||
|
||||
if test "$pr" -a "$ref" ; then
|
||||
log_error "--origin-pr $pr and --origin-ref $ref are mutually exclusive"
|
||||
return 1
|
||||
if test "$pr" -a "$ref"; then
|
||||
log_error "--origin-pr $pr and --origin-ref $ref are mutually exclusive"
|
||||
return 1
|
||||
fi
|
||||
if test -z "$pr" -a -z "$ref" ; then
|
||||
log_error "one of --origin-pr or --origin-ref must be set"
|
||||
return 2
|
||||
if test -z "$pr" -a -z "$ref"; then
|
||||
log_error "one of --origin-pr or --origin-ref must be set"
|
||||
return 2
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -218,10 +218,10 @@ function set_origin_head() {
|
|||
sanity_check_pr_or_ref "$pr" "$ref"
|
||||
|
||||
if test "$pr"; then
|
||||
options[origin_head]=refs/pull/$pr/head
|
||||
origin_sanity_check
|
||||
options[origin_head]=refs/pull/$pr/head
|
||||
origin_sanity_check
|
||||
else
|
||||
options[origin_head]=$ref
|
||||
options[origin_head]=$ref
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -236,8 +236,8 @@ function set_destination_head() {
|
|||
sanity_check_pr_or_ref "$pr" "$ref"
|
||||
|
||||
if $(origin_has_pr); then
|
||||
options[destination_head]=${options[prefix]}-$pr
|
||||
options[destination_head]=${options[prefix]}-$pr
|
||||
else
|
||||
options[destination_head]=${options[prefix]}-$ref
|
||||
options[destination_head]=${options[prefix]}-$ref
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue