mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-04-21 08:28:44 +00: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` | |
|
| 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-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-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-branch | the base branch of the destination repository for the cascading PR | `true` | |
|
||||||
| destination-token | a token with write permission on destination-repo | `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` | |
|
| 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'
|
description: 'the repository in which the cascading PR is created or updated'
|
||||||
required: true
|
required: true
|
||||||
destination-fork-repo:
|
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:
|
destination-branch:
|
||||||
description: 'the base branch of the destination repository for the cascading PR'
|
description: 'the base branch of the destination repository for the cascading PR'
|
||||||
required: true
|
required: true
|
||||||
|
|
|
@ -28,23 +28,24 @@ function dependencies() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function retry() {
|
function retry() {
|
||||||
rm -f $TMPDIR/retry.out
|
rm -f $TMPDIR/retry.{out,attempt,err}
|
||||||
local success=false
|
local success=false
|
||||||
for delay in $RETRY_DELAYS ; do
|
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
|
success=true
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
cat $TMPDIR/retry-attempt.out >&2
|
cat $TMPDIR/retry.{err,attempt} >> $TMPDIR/retry.out
|
||||||
log waiting $delay "$@"
|
cat $TMPDIR/retry.{err,attempt} >&2
|
||||||
|
echo waiting $delay "$@" >&2
|
||||||
sleep $delay
|
sleep $delay
|
||||||
done
|
done
|
||||||
if $success ; then
|
if $success ; then
|
||||||
cat $TMPDIR/retry-attempt.out
|
cat $TMPDIR/retry.attempt
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
log_error retry failed for "$@"
|
echo retry failed for "$@" >&2
|
||||||
cat $TMPDIR/retry.out
|
cat $TMPDIR/retry.out >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
28
tests/run.sh
28
tests/run.sh
|
@ -171,17 +171,27 @@ function unit_retry() {
|
||||||
# Succeeds after two tries
|
# Succeeds after two tries
|
||||||
#
|
#
|
||||||
echo 2 > $TMPDIR/unit_retry_two
|
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"
|
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
|
||||||
cat $TMPDIR/retry.test-log
|
if test "$(grep -c '^waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 2 ; then
|
||||||
test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" = 2
|
cat $TMPDIR/retry.test-log
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
#
|
#
|
||||||
# Succeeds immediately
|
# 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 "$(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
|
# 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
|
# Fails after one try
|
||||||
#
|
#
|
||||||
echo 2 > $TMPDIR/unit_retry_two
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
grep --quiet 'retry failed' $TMPDIR/retry.test-log
|
grep --quiet 'retry failed' $TMPDIR/retry.test-log
|
||||||
|
@ -368,8 +379,7 @@ function integration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function unit() {
|
function unit() {
|
||||||
# do not run in debug mode, it will polute the output and fail
|
unit_retry
|
||||||
${BASH_SOURCE[0]} --verbose unit_retry
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_tests() {
|
function run_tests() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue