mirror of
https://code.forgejo.org/actions/cascading-pr
synced 2025-03-14 22:36:58 +01:00
simplify the retry implementation and tests
This commit is contained in:
parent
9d138db73c
commit
15dc3ec7a7
4 changed files with 29 additions and 18 deletions
|
@ -51,7 +51,7 @@ not exist, it is created.
|
|||
| origin-pr | number of the PR in {orign-repo} | `true` | |
|
||||
| destination-url | URL of the Forgejo instance where the cascading PR is created or updated (e.g. https://code.forgejo.org) | `true` | |
|
||||
| destination-repo | the repository in which the cascading PR is created or updated | `true` | |
|
||||
| destination-fork-repo | the fork of {desitnation-repo} in which the {destination-branch} will be created or updated | `false` | |
|
||||
| destination-fork-repo | the fork of {destination-repo} in which the {destination-branch} will be created or updated | `false` | |
|
||||
| destination-branch | the base branch of the destination repository for the cascading PR | `true` | |
|
||||
| destination-token | a token with write permission on destination-repo | `true` | |
|
||||
| update | path to the script to update the content of the cascading PR | `true` | |
|
||||
|
|
|
@ -59,7 +59,7 @@ inputs:
|
|||
description: 'the repository in which the cascading PR is created or updated'
|
||||
required: true
|
||||
destination-fork-repo:
|
||||
description: 'the fork of {desitnation-repo} in which the {destination-branch} will be created or updated'
|
||||
description: 'the fork of {destination-repo} in which the {destination-branch} will be created or updated'
|
||||
destination-branch:
|
||||
description: 'the base branch of the destination repository for the cascading PR'
|
||||
required: true
|
||||
|
|
|
@ -28,23 +28,24 @@ function dependencies() {
|
|||
}
|
||||
|
||||
function retry() {
|
||||
rm -f $TMPDIR/retry.out
|
||||
rm -f $TMPDIR/retry.{out,attempt,err}
|
||||
local success=false
|
||||
for delay in $RETRY_DELAYS ; do
|
||||
if "$@" |& tee -a $TMPDIR/retry.out > $TMPDIR/retry-attempt.out ; then
|
||||
if "$@" > $TMPDIR/retry.attempt 2>> $TMPDIR/retry.err ; then
|
||||
success=true
|
||||
break
|
||||
fi
|
||||
cat $TMPDIR/retry-attempt.out >&2
|
||||
log waiting $delay "$@"
|
||||
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.out
|
||||
cat $TMPDIR/retry.attempt
|
||||
return 0
|
||||
else
|
||||
log_error retry failed for "$@"
|
||||
cat $TMPDIR/retry.out
|
||||
echo retry failed for "$@" >&2
|
||||
cat $TMPDIR/retry.out >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
|
28
tests/run.sh
28
tests/run.sh
|
@ -171,17 +171,27 @@ function unit_retry() {
|
|||
# Succeeds after two tries
|
||||
#
|
||||
echo 2 > $TMPDIR/unit_retry_two
|
||||
RETRY_DELAYS='1 1 1 1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log
|
||||
if ! RETRY_DELAYS='1 1 1 1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log ; then
|
||||
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
|
||||
return 1
|
||||
fi
|
||||
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
|
||||
cat $TMPDIR/retry.test-log
|
||||
test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" = 2
|
||||
|
||||
if test "$(grep -c '^waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 2 ; then
|
||||
cat $TMPDIR/retry.test-log
|
||||
return 1
|
||||
fi
|
||||
#
|
||||
# Succeeds immediately
|
||||
#
|
||||
RETRY_DELAYS='1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log
|
||||
if ! RETRY_DELAYS='1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log ; then
|
||||
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
|
||||
return 1
|
||||
fi
|
||||
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
|
||||
test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" = 0
|
||||
if test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 0 ; then
|
||||
cat $TMPDIR/retry.test-log
|
||||
return 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Verify the output is only the output of the last run and is not polluted by
|
||||
|
@ -194,7 +204,8 @@ function unit_retry() {
|
|||
# Fails after one try
|
||||
#
|
||||
echo 2 > $TMPDIR/unit_retry_two
|
||||
if RETRY_DELAYS='1' retry unit_retry_fail $two |& tee $TMPDIR/retry.test-log ; then
|
||||
if RETRY_DELAYS='1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log ; then
|
||||
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
|
||||
return 1
|
||||
fi
|
||||
grep --quiet 'retry failed' $TMPDIR/retry.test-log
|
||||
|
@ -368,8 +379,7 @@ function integration() {
|
|||
}
|
||||
|
||||
function unit() {
|
||||
# do not run in debug mode, it will polute the output and fail
|
||||
${BASH_SOURCE[0]} --verbose unit_retry
|
||||
unit_retry
|
||||
}
|
||||
|
||||
function run_tests() {
|
||||
|
|
Loading…
Add table
Reference in a new issue