mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-07-21 23:08:23 +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
|
@ -1,3 +1,10 @@
|
||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*]
|
[*]
|
||||||
tab_width: 8
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
tab_width = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
|
@ -21,7 +21,7 @@ DEBUG=false
|
||||||
: ${RETRY_DELAYS:=1 1 5 5 15 30}
|
: ${RETRY_DELAYS:=1 1 5 5 15 30}
|
||||||
|
|
||||||
function dependencies() {
|
function dependencies() {
|
||||||
if ! which jq curl > /dev/null ; then
|
if ! which jq curl >/dev/null; then
|
||||||
apt-get update -qq
|
apt-get update -qq
|
||||||
apt-get -qq install -y jq curl
|
apt-get -qq install -y jq curl
|
||||||
fi
|
fi
|
||||||
|
@ -30,17 +30,17 @@ function dependencies() {
|
||||||
function retry() {
|
function retry() {
|
||||||
rm -f $TMPDIR/retry.{out,attempt,err}
|
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 "$@" > $TMPDIR/retry.attempt 2>> $TMPDIR/retry.err ; then
|
if "$@" >$TMPDIR/retry.attempt 2>>$TMPDIR/retry.err; then
|
||||||
success=true
|
success=true
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
cat $TMPDIR/retry.{err,attempt} >> $TMPDIR/retry.out
|
cat $TMPDIR/retry.{err,attempt} >>$TMPDIR/retry.out
|
||||||
cat $TMPDIR/retry.{err,attempt} >&2
|
cat $TMPDIR/retry.{err,attempt} >&2
|
||||||
echo waiting $delay "$@" >&2
|
echo waiting $delay "$@" >&2
|
||||||
sleep $delay
|
sleep $delay
|
||||||
done
|
done
|
||||||
if $success ; then
|
if $success; then
|
||||||
cat $TMPDIR/retry.attempt
|
cat $TMPDIR/retry.attempt
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
@ -70,7 +70,7 @@ function log_error() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function log_verbose() {
|
function log_verbose() {
|
||||||
if $VERBOSE ; then
|
if $VERBOSE; then
|
||||||
log_info "$@"
|
log_info "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ function log_info() {
|
||||||
|
|
||||||
function fatal_error() {
|
function fatal_error() {
|
||||||
log_error "$@"
|
log_error "$@"
|
||||||
if $EXIT_ON_ERROR ; then
|
if $EXIT_ON_ERROR; then
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
|
@ -91,10 +91,10 @@ function fatal_error() {
|
||||||
function stash_debug() {
|
function stash_debug() {
|
||||||
echo start $SELF
|
echo start $SELF
|
||||||
mkdir -p $TMPDIR
|
mkdir -p $TMPDIR
|
||||||
> $TMPDIR/run.out
|
>$TMPDIR/run.out
|
||||||
tail --follow $TMPDIR/run.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" &
|
tail --follow $TMPDIR/run.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" &
|
||||||
pid=$!
|
pid=$!
|
||||||
if ! $SELF --debug "$@" >& $TMPDIR/run.out ; then
|
if ! $SELF --debug "$@" >&$TMPDIR/run.out; then
|
||||||
kill $pid
|
kill $pid
|
||||||
cat $TMPDIR/run.out
|
cat $TMPDIR/run.out
|
||||||
echo fail $SELF
|
echo fail $SELF
|
||||||
|
@ -142,9 +142,9 @@ function check_status() {
|
||||||
local expected_status="$3"
|
local expected_status="$3"
|
||||||
local expected_description="$4"
|
local expected_description="$4"
|
||||||
|
|
||||||
get_status $api $sha > $TMPDIR/status.json
|
get_status $api $sha >$TMPDIR/status.json
|
||||||
local status="$(jq --raw-output .state < $TMPDIR/status.json)"
|
local status="$(jq --raw-output .state <$TMPDIR/status.json)"
|
||||||
local description="$(jq --raw-output .statuses[0].description < $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
|
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
|
elif test "$status" = "failure" -o "$status" = "success"; then
|
||||||
|
@ -168,8 +168,8 @@ function wait_running() {
|
||||||
|
|
||||||
function wait_log() {
|
function wait_log() {
|
||||||
local sha="$1" expected_status="$2" expected_description="$3"
|
local sha="$1" expected_status="$2" expected_description="$3"
|
||||||
local status="$(jq --raw-output .state < $TMPDIR/status.json)"
|
local status="$(jq --raw-output .state <$TMPDIR/status.json)"
|
||||||
local description="$(jq --raw-output .statuses[0].description < $TMPDIR/status.json)"
|
local description="$(jq --raw-output .statuses[0].description <$TMPDIR/status.json)"
|
||||||
if test "$expected_description"; then
|
if test "$expected_description"; then
|
||||||
expected_description=" '$expected_description'"
|
expected_description=" '$expected_description'"
|
||||||
fi
|
fi
|
||||||
|
@ -183,13 +183,13 @@ function wait_status() {
|
||||||
local description="$4"
|
local description="$4"
|
||||||
|
|
||||||
for i in $(seq $LOOPS); do
|
for i in $(seq $LOOPS); do
|
||||||
if test $(check_status "$api" "$sha" "$status" "$description") != RETRY ; then
|
if test $(check_status "$api" "$sha" "$status" "$description") != RETRY; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
wait_log "$sha" "$status" "$description"
|
wait_log "$sha" "$status" "$description"
|
||||||
sleep $LOOP_DELAY
|
sleep $LOOP_DELAY
|
||||||
done
|
done
|
||||||
if test $(check_status "$api" "$sha" "$status" "$description") = "OK" ; then
|
if test $(check_status "$api" "$sha" "$status" "$description") = "OK"; then
|
||||||
log_info "$sha status OK"
|
log_info "$sha status OK"
|
||||||
else
|
else
|
||||||
get_status $api $sha | jq .statuses
|
get_status $api $sha | jq .statuses
|
||||||
|
@ -201,11 +201,11 @@ function wait_status() {
|
||||||
function sanity_check_pr_or_ref() {
|
function sanity_check_pr_or_ref() {
|
||||||
local pr="$1" ref="$2"
|
local pr="$1" ref="$2"
|
||||||
|
|
||||||
if test "$pr" -a "$ref" ; then
|
if test "$pr" -a "$ref"; then
|
||||||
log_error "--origin-pr $pr and --origin-ref $ref are mutually exclusive"
|
log_error "--origin-pr $pr and --origin-ref $ref are mutually exclusive"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if test -z "$pr" -a -z "$ref" ; then
|
if test -z "$pr" -a -z "$ref"; then
|
||||||
log_error "one of --origin-pr or --origin-ref must be set"
|
log_error "one of --origin-pr or --origin-ref must be set"
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -5,7 +5,7 @@ set -e
|
||||||
set -o posix
|
set -o posix
|
||||||
|
|
||||||
SELF=${BASH_SOURCE[0]}
|
SELF=${BASH_SOURCE[0]}
|
||||||
SELF_DIR="$( cd "$( dirname "$SELF" )" && pwd )"
|
SELF_DIR="$(cd "$(dirname "$SELF")" && pwd)"
|
||||||
source $SELF_DIR/cascading-pr-lib.sh
|
source $SELF_DIR/cascading-pr-lib.sh
|
||||||
|
|
||||||
trap "rm -fr $TMPDIR" EXIT
|
trap "rm -fr $TMPDIR" EXIT
|
||||||
|
@ -29,19 +29,19 @@ function repo_curl() {
|
||||||
function default_branch() {
|
function default_branch() {
|
||||||
local direction=$1
|
local direction=$1
|
||||||
|
|
||||||
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]} > $TMPDIR/$direction.json
|
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]} >$TMPDIR/$direction.json
|
||||||
jq --raw-output .default_branch < $TMPDIR/$direction.json
|
jq --raw-output .default_branch <$TMPDIR/$direction.json
|
||||||
}
|
}
|
||||||
|
|
||||||
function destination_updated_at() {
|
function destination_updated_at() {
|
||||||
local api
|
local api
|
||||||
|
|
||||||
if ${options[destination_is_fork]} ; then
|
if ${options[destination_is_fork]}; then
|
||||||
repo_curl ${options[destination_repo]} api_json ${options[destination_fork_api]} > $TMPDIR/updated_at.json
|
repo_curl ${options[destination_repo]} api_json ${options[destination_fork_api]} >$TMPDIR/updated_at.json
|
||||||
else
|
else
|
||||||
repo_curl ${options[destination_repo]} api_json ${options[destination_api]} > $TMPDIR/updated_at.json
|
repo_curl ${options[destination_repo]} api_json ${options[destination_api]} >$TMPDIR/updated_at.json
|
||||||
fi
|
fi
|
||||||
jq --raw-output .updated_at < $TMPDIR/updated_at.json
|
jq --raw-output .updated_at <$TMPDIR/updated_at.json
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_branch_destination() {
|
function delete_branch_destination() {
|
||||||
|
@ -49,12 +49,12 @@ function delete_branch_destination() {
|
||||||
local repo=${options[destination_repo]}
|
local repo=${options[destination_repo]}
|
||||||
local api=${options[destination_api]}
|
local api=${options[destination_api]}
|
||||||
|
|
||||||
if ${options[destination_is_fork]} ; then
|
if ${options[destination_is_fork]}; then
|
||||||
repo=${options[destination_fork_repo]}
|
repo=${options[destination_fork_repo]}
|
||||||
api=${options[destination_fork_api]}
|
api=${options[destination_fork_api]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! repo_curl ${options[destination_repo]} api_json $api/branches/$branch >& /dev/null ; then
|
if ! repo_curl ${options[destination_repo]} api_json $api/branches/$branch >&/dev/null; then
|
||||||
log_info "branch $branch does not exists in $repo"
|
log_info "branch $branch does not exists in $repo"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -67,7 +67,7 @@ function pr_origin_comment_body() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function comment_origin_pr() {
|
function comment_origin_pr() {
|
||||||
cat > $TMPDIR/data <<EOF
|
cat >$TMPDIR/data <<EOF
|
||||||
{
|
{
|
||||||
"body":"$(pr_origin_comment_body)"
|
"body":"$(pr_origin_comment_body)"
|
||||||
}
|
}
|
||||||
|
@ -95,13 +95,13 @@ function upsert_destination_pr() {
|
||||||
log_info "an open PR already exists $url"
|
log_info "an open PR already exists $url"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if ${options[destination_is_fork]} ; then
|
if ${options[destination_is_fork]}; then
|
||||||
head="$(owner ${options[destination_fork_repo]}):${options[destination_head]}"
|
head="$(owner ${options[destination_fork_repo]}):${options[destination_head]}"
|
||||||
else
|
else
|
||||||
head=${options[destination_head]}
|
head=${options[destination_head]}
|
||||||
fi
|
fi
|
||||||
local title=$(pr_destination_title)
|
local title=$(pr_destination_title)
|
||||||
cat > $TMPDIR/data <<EOF
|
cat >$TMPDIR/data <<EOF
|
||||||
{
|
{
|
||||||
"title":"$(pr_destination_title)",
|
"title":"$(pr_destination_title)",
|
||||||
"body":"$(pr_destination_body)",
|
"body":"$(pr_destination_body)",
|
||||||
|
@ -109,7 +109,7 @@ function upsert_destination_pr() {
|
||||||
"head":"$head"
|
"head":"$head"
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
retry repo_curl ${options[destination_repo]} api_json --data @$TMPDIR/data ${options[destination_api]}/pulls > $TMPDIR/destination-pr.json
|
retry repo_curl ${options[destination_repo]} api_json --data @$TMPDIR/data ${options[destination_api]}/pulls >$TMPDIR/destination-pr.json
|
||||||
log_info "PR created $(pr_url destination)"
|
log_info "PR created $(pr_url destination)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,12 +127,12 @@ function close_pr() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function pr_get_origin() {
|
function pr_get_origin() {
|
||||||
repo_curl ${options[origin_repo]} api_json ${options[origin_api]}/pulls/${options[origin_pr]} > $TMPDIR/origin-pr.json
|
repo_curl ${options[origin_repo]} api_json ${options[origin_api]}/pulls/${options[origin_pr]} >$TMPDIR/origin-pr.json
|
||||||
}
|
}
|
||||||
|
|
||||||
function pr_get_destination() {
|
function pr_get_destination() {
|
||||||
local title=$(pr_destination_title)
|
local title=$(pr_destination_title)
|
||||||
repo_curl ${options[destination_repo]} api --get --data state=open --data type=pulls --data-urlencode q="$title" ${options[destination_api]}/issues | jq --raw-output .[0] > $TMPDIR/destination-pr.json
|
repo_curl ${options[destination_repo]} api --get --data state=open --data type=pulls --data-urlencode q="$title" ${options[destination_api]}/issues | jq --raw-output .[0] >$TMPDIR/destination-pr.json
|
||||||
}
|
}
|
||||||
|
|
||||||
function pr_get() {
|
function pr_get() {
|
||||||
|
@ -191,7 +191,7 @@ function git_checkout() {
|
||||||
|
|
||||||
(
|
(
|
||||||
cd $TMPDIR/$direction
|
cd $TMPDIR/$direction
|
||||||
if [[ "$ref" =~ ^refs/ ]] ; then
|
if [[ "$ref" =~ ^refs/ ]]; then
|
||||||
git fetch --update-head-ok ${remote} +$ref:$ref
|
git fetch --update-head-ok ${remote} +$ref:$ref
|
||||||
else
|
else
|
||||||
ref=${remote}/$ref
|
ref=${remote}/$ref
|
||||||
|
@ -213,7 +213,7 @@ function git_reset_branch() {
|
||||||
local direction=$1 remote=$2 branch=$3
|
local direction=$1 remote=$2 branch=$3
|
||||||
(
|
(
|
||||||
cd $TMPDIR/$direction
|
cd $TMPDIR/$direction
|
||||||
if git ls-remote --exit-code --heads ${remote} $branch ; then
|
if git ls-remote --exit-code --heads ${remote} $branch; then
|
||||||
git fetch --quiet ${remote} $branch
|
git fetch --quiet ${remote} $branch
|
||||||
git reset --hard ${remote}/$branch
|
git reset --hard ${remote}/$branch
|
||||||
fi
|
fi
|
||||||
|
@ -222,7 +222,7 @@ function git_reset_branch() {
|
||||||
|
|
||||||
function sha_pushed() {
|
function sha_pushed() {
|
||||||
local direction=$1
|
local direction=$1
|
||||||
if test -f $TMPDIR/$direction.sha ; then
|
if test -f $TMPDIR/$direction.sha; then
|
||||||
cat $TMPDIR/$direction.sha
|
cat $TMPDIR/$direction.sha
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ function push() {
|
||||||
local before=$(destination_updated_at)
|
local before=$(destination_updated_at)
|
||||||
sleep 1 # the resolution of the update time is one second
|
sleep 1 # the resolution of the update time is one second
|
||||||
git push --force ${remote} prbranch:$branch
|
git push --force ${remote} prbranch:$branch
|
||||||
git rev-parse HEAD > ../destination.sha
|
git rev-parse HEAD >../destination.sha
|
||||||
retry destination_updated_at_changed "$before"
|
retry destination_updated_at_changed "$before"
|
||||||
local after=$(destination_updated_at)
|
local after=$(destination_updated_at)
|
||||||
log_info "pushed"
|
log_info "pushed"
|
||||||
|
@ -260,20 +260,20 @@ function wait_destination_ci() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function upsert_fork() {
|
function upsert_fork() {
|
||||||
if repo_curl ${options[destination_repo]} api_json ${options[destination_fork_api]} > $TMPDIR/fork.json 2> /dev/null ; then
|
if repo_curl ${options[destination_repo]} api_json ${options[destination_fork_api]} >$TMPDIR/fork.json 2>/dev/null; then
|
||||||
if test "$(jq --raw-output .fork < $TMPDIR/fork.json)" != true ; then
|
if test "$(jq --raw-output .fork <$TMPDIR/fork.json)" != true; then
|
||||||
log_error "the destination fork already exists but is not a fork ${options[destination_fork]}"
|
log_error "the destination fork already exists but is not a fork ${options[destination_fork]}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local forked_from_repo=$(jq --raw-output .parent.full_name < $TMPDIR/fork.json)
|
local forked_from_repo=$(jq --raw-output .parent.full_name <$TMPDIR/fork.json)
|
||||||
if test "$forked_from_repo" != "${options[destination_repo]}" ; then
|
if test "$forked_from_repo" != "${options[destination_repo]}"; then
|
||||||
log_error "${options[destination_fork]} must be a fork of ${options[destination_repo]} but is a fork of $forked_from_repo instead"
|
log_error "${options[destination_fork]} must be a fork of ${options[destination_repo]} but is a fork of $forked_from_repo instead"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
local fork_owner=$(owner ${options[destination_fork_repo]})
|
local fork_owner=$(owner ${options[destination_fork_repo]})
|
||||||
local data="{}"
|
local data="{}"
|
||||||
if repo_curl ${options[destination_repo]} api_json ${options[destination_url]}/api/v1/orgs/${fork_owner} >& /dev/null ; then
|
if repo_curl ${options[destination_repo]} api_json ${options[destination_url]}/api/v1/orgs/${fork_owner} >&/dev/null; then
|
||||||
data='{"organization":"'$fork_owner'"}'
|
data='{"organization":"'$fork_owner'"}'
|
||||||
fi
|
fi
|
||||||
repo_curl ${options[destination_repo]} api_json --data "$data" ${options[destination_url]}/api/v1/repos/${options[destination_repo]}/forks
|
repo_curl ${options[destination_repo]} api_json --data "$data" ${options[destination_url]}/api/v1/repos/${options[destination_repo]}/forks
|
||||||
|
@ -297,7 +297,7 @@ function checkout() {
|
||||||
# fork
|
# fork
|
||||||
#
|
#
|
||||||
local head_remote=origin
|
local head_remote=origin
|
||||||
if ${options[destination_is_fork]} ; then
|
if ${options[destination_is_fork]}; then
|
||||||
upsert_fork
|
upsert_fork
|
||||||
git_remote destination fork ${options[destination_fetch_fork]}
|
git_remote destination fork ${options[destination_fetch_fork]}
|
||||||
head_remote=fork
|
head_remote=fork
|
||||||
|
@ -308,7 +308,7 @@ function checkout() {
|
||||||
function update() {
|
function update() {
|
||||||
(
|
(
|
||||||
local update=${options[update]}
|
local update=${options[update]}
|
||||||
if ! [[ "$update" =~ ^/ ]] ; then
|
if ! [[ "$update" =~ ^/ ]]; then
|
||||||
local d
|
local d
|
||||||
if $(origin_has_pr) && $(pr_from_fork origin); then
|
if $(origin_has_pr) && $(pr_from_fork origin); then
|
||||||
local default_branch=$(default_branch origin)
|
local default_branch=$(default_branch origin)
|
||||||
|
@ -330,7 +330,7 @@ function update() {
|
||||||
$update $TMPDIR/destination $TMPDIR/destination-pr.json $TMPDIR/origin $origin_info
|
$update $TMPDIR/destination $TMPDIR/destination-pr.json $TMPDIR/origin $origin_info
|
||||||
)
|
)
|
||||||
local remote_head=origin
|
local remote_head=origin
|
||||||
if ${options[destination_is_fork]} ; then
|
if ${options[destination_is_fork]}; then
|
||||||
remote_head=fork
|
remote_head=fork
|
||||||
fi
|
fi
|
||||||
push $remote_head ${options[destination_head]}
|
push $remote_head ${options[destination_head]}
|
||||||
|
@ -340,15 +340,15 @@ function set_git_url() {
|
||||||
local direction=$1 name=$2 repo=$3
|
local direction=$1 name=$2 repo=$3
|
||||||
local token=${options[${direction}_token]}
|
local token=${options[${direction}_token]}
|
||||||
|
|
||||||
if [[ "$token" =~ ^@ ]] ; then
|
if [[ "$token" =~ ^@ ]]; then
|
||||||
local file=${token##@}
|
local file=${token##@}
|
||||||
(
|
(
|
||||||
echo -n ${options[${direction}_scheme]}://any:
|
echo -n ${options[${direction}_scheme]}://any:
|
||||||
cat $file
|
cat $file
|
||||||
echo @${options[${direction}_host_port]}/$repo
|
echo @${options[${direction}_host_port]}/$repo
|
||||||
) > $TMPDIR/$direction.git-credentials
|
) >$TMPDIR/$direction.git-credentials
|
||||||
else
|
else
|
||||||
echo ${options[${direction}_scheme]}://any:${options[${direction}_token]}@${options[${direction}_host_port]}/$repo > $TMPDIR/$direction.git-credentials
|
echo ${options[${direction}_scheme]}://any:${options[${direction}_token]}@${options[${direction}_host_port]}/$repo >$TMPDIR/$direction.git-credentials
|
||||||
fi
|
fi
|
||||||
options[$name]=${options[${direction}_scheme]}://${options[${direction}_host_port]}/$repo
|
options[$name]=${options[${direction}_scheme]}://${options[${direction}_host_port]}/$repo
|
||||||
}
|
}
|
||||||
|
@ -409,17 +409,17 @@ function run_origin_ref() {
|
||||||
checkout
|
checkout
|
||||||
update
|
update
|
||||||
local sha=$(sha_pushed destination)
|
local sha=$(sha_pushed destination)
|
||||||
if test "$sha" ; then
|
if test "$sha"; then
|
||||||
upsert_destination_pr
|
upsert_destination_pr
|
||||||
local status
|
local status
|
||||||
if wait_destination_ci "$sha" ; then
|
if wait_destination_ci "$sha"; then
|
||||||
log_info "cascade PR status successful"
|
log_info "cascade PR status successful"
|
||||||
status=0
|
status=0
|
||||||
else
|
else
|
||||||
log_info "cascade PR status failed"
|
log_info "cascade PR status failed"
|
||||||
status=1
|
status=1
|
||||||
fi
|
fi
|
||||||
if "${options[close]}" ; then
|
if "${options[close]}"; then
|
||||||
log_info "close the cascade PR and remove the branch"
|
log_info "close the cascade PR and remove the branch"
|
||||||
close_pr
|
close_pr
|
||||||
fi
|
fi
|
||||||
|
@ -436,7 +436,7 @@ function run_origin_pr() {
|
||||||
checkout
|
checkout
|
||||||
update
|
update
|
||||||
local sha=$(sha_pushed destination)
|
local sha=$(sha_pushed destination)
|
||||||
if test "$sha" ; then
|
if test "$sha"; then
|
||||||
upsert_destination_pr
|
upsert_destination_pr
|
||||||
comment_origin_pr
|
comment_origin_pr
|
||||||
wait_destination_ci "$sha"
|
wait_destination_ci "$sha"
|
||||||
|
@ -444,7 +444,7 @@ function run_origin_pr() {
|
||||||
;;
|
;;
|
||||||
closed)
|
closed)
|
||||||
if "$(pr_merged origin)"; then
|
if "$(pr_merged origin)"; then
|
||||||
if "${options[close]}" ; then
|
if "${options[close]}"; then
|
||||||
log_info "PR is merged, close the cascade PR and remove the branch"
|
log_info "PR is merged, close the cascade PR and remove the branch"
|
||||||
close_pr
|
close_pr
|
||||||
else
|
else
|
||||||
|
@ -552,7 +552,7 @@ function main() {
|
||||||
|
|
||||||
dependencies
|
dependencies
|
||||||
|
|
||||||
if echo "${@}" | grep --quiet -e '--debug' ; then
|
if echo "${@}" | grep --quiet -e '--debug'; then
|
||||||
main "${@}"
|
main "${@}"
|
||||||
else
|
else
|
||||||
stash_debug "${@}"
|
stash_debug "${@}"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
VERSION=1.0.0
|
VERSION=1.0.0
|
||||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
VERBOSE=false
|
VERBOSE=false
|
||||||
DEBUG=false
|
DEBUG=false
|
||||||
: ${EXIT_ON_ERROR:=true}
|
: ${EXIT_ON_ERROR:=true}
|
||||||
|
@ -28,7 +28,7 @@ function log_error() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function log_verbose() {
|
function log_verbose() {
|
||||||
if $VERBOSE ; then
|
if $VERBOSE; then
|
||||||
log "$@"
|
log "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ function log_info() {
|
||||||
|
|
||||||
function fatal_error() {
|
function fatal_error() {
|
||||||
log_error "$@"
|
log_error "$@"
|
||||||
if $EXIT_ON_ERROR ; then
|
if $EXIT_ON_ERROR; then
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
|
@ -66,32 +66,35 @@ function login_api() {
|
||||||
local user="$1" password="$2" token="$3" scopes="${4:-[\"all\"]}" url="$5"
|
local user="$1" password="$2" token="$3" scopes="${4:-[\"all\"]}" url="$5"
|
||||||
|
|
||||||
dot_ensure
|
dot_ensure
|
||||||
if test -s $DOT/token ; then
|
if test -s $DOT/token; then
|
||||||
log_info "already logged in, ignored"
|
log_info "already logged in, ignored"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -z "$token" ; then
|
if test -z "$token"; then
|
||||||
log_verbose curl -sS -X DELETE --user "${user}:${password}" "${url}/api/v1/users/$user/tokens/${TOKEN_NAME}" -o /dev/null -w "%{http_code}"
|
log_verbose curl -sS -X DELETE --user "${user}:${password}" "${url}/api/v1/users/$user/tokens/${TOKEN_NAME}" -o /dev/null -w "%{http_code}"
|
||||||
local basic="${user:-unknown}:${password:-unknown}"
|
local basic="${user:-unknown}:${password:-unknown}"
|
||||||
local status=$(curl -sS -X DELETE --user "${basic}" "${url}/api/v1/users/$user/tokens/${TOKEN_NAME}" -o /dev/null -w "%{http_code}")
|
local status=$(curl -sS -X DELETE --user "${basic}" "${url}/api/v1/users/$user/tokens/${TOKEN_NAME}" -o /dev/null -w "%{http_code}")
|
||||||
if test "${status}" != 404 -a "${status}" != 204 ; then
|
if test "${status}" != 404 -a "${status}" != 204; then
|
||||||
fatal_error permission denied, the user or password are probably incorrect, try again with --verbose
|
fatal_error permission denied, the user or password are probably incorrect, try again with --verbose
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
token=$(client $HEADER_JSON --user "${basic}" --data-raw '{"name":"'${TOKEN_NAME}'","scopes":'${scopes}'}' "${url}/api/v1/users/${user}/tokens" | jq --raw-output .sha1)
|
token=$(client $HEADER_JSON --user "${basic}" --data-raw '{"name":"'${TOKEN_NAME}'","scopes":'${scopes}'}' "${url}/api/v1/users/${user}/tokens" | jq --raw-output .sha1)
|
||||||
fi
|
fi
|
||||||
if [[ "$token" =~ ^@ ]] ; then
|
if [[ "$token" =~ ^@ ]]; then
|
||||||
cp "${token##@}" $DOT/token
|
cp "${token##@}" $DOT/token
|
||||||
else
|
else
|
||||||
echo "$token" > $DOT/token
|
echo "$token" >$DOT/token
|
||||||
fi
|
fi
|
||||||
( echo -n "Authorization: token " ; cat $DOT/token ) > $DOT/header-token
|
(
|
||||||
|
echo -n "Authorization: token "
|
||||||
|
cat $DOT/token
|
||||||
|
) >$DOT/header-token
|
||||||
#
|
#
|
||||||
# Verify it works
|
# Verify it works
|
||||||
#
|
#
|
||||||
local status=$(api -w "%{http_code}" -o /dev/null "${url}/api/v1/user")
|
local status=$(api -w "%{http_code}" -o /dev/null "${url}/api/v1/user")
|
||||||
if test "${status}" != 200 ; then
|
if test "${status}" != 200; then
|
||||||
fatal_error "${url}/api/v1/user returns status code '${status}', the token is invalid, $0 logout and login again"
|
fatal_error "${url}/api/v1/user returns status code '${status}', the token is invalid, $0 logout and login again"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -99,7 +102,7 @@ function login_api() {
|
||||||
|
|
||||||
function client() {
|
function client() {
|
||||||
log_verbose curl --cookie $DOT/cookies -f -sS "$@"
|
log_verbose curl --cookie $DOT/cookies -f -sS "$@"
|
||||||
if ! curl --cookie $DOT/cookies -f -sS "$@" ; then
|
if ! curl --cookie $DOT/cookies -f -sS "$@"; then
|
||||||
fatal_error
|
fatal_error
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -111,7 +114,7 @@ function web() {
|
||||||
function client_update_cookies() {
|
function client_update_cookies() {
|
||||||
log_verbose curl --cookie-jar $DOT/cookies --cookie $DOT/cookies -w "%{http_code}" -f -sS "$@"
|
log_verbose curl --cookie-jar $DOT/cookies --cookie $DOT/cookies -w "%{http_code}" -f -sS "$@"
|
||||||
local status=$(curl --cookie-jar $DOT/cookies --cookie $DOT/cookies -w "%{http_code}" -f -sS "$@")
|
local status=$(curl --cookie-jar $DOT/cookies --cookie $DOT/cookies -w "%{http_code}" -f -sS "$@")
|
||||||
if ! test "${status}" = 200 -o "${status}" = 303 ; then
|
if ! test "${status}" = 200 -o "${status}" = 303; then
|
||||||
fatal_error
|
fatal_error
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -119,7 +122,7 @@ function client_update_cookies() {
|
||||||
function login_client() {
|
function login_client() {
|
||||||
local user="$1" password="$2" url="$3"
|
local user="$1" password="$2" url="$3"
|
||||||
|
|
||||||
if test -z "$password" ; then
|
if test -z "$password"; then
|
||||||
log_verbose "no password, web will not be authenticated"
|
log_verbose "no password, web will not be authenticated"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -138,14 +141,14 @@ function login_client() {
|
||||||
#
|
#
|
||||||
client_update_cookies -o /dev/null "${url}/user/login"
|
client_update_cookies -o /dev/null "${url}/user/login"
|
||||||
local csrf=$(sed -n -e '/csrf/s/.*csrf\t//p' $DOT/cookies)
|
local csrf=$(sed -n -e '/csrf/s/.*csrf\t//p' $DOT/cookies)
|
||||||
echo "X-Csrf-Token: $csrf" > $DOT/header-csrf
|
echo "X-Csrf-Token: $csrf" >$DOT/header-csrf
|
||||||
#
|
#
|
||||||
# Verify it works
|
# Verify it works
|
||||||
#
|
#
|
||||||
local status=$(web -o /dev/null -w "%{http_code}" "${url}/user/settings")
|
local status=$(web -o /dev/null -w "%{http_code}" "${url}/user/settings")
|
||||||
if test "${status}" != 200 ; then
|
if test "${status}" != 200; then
|
||||||
grep -C 1 flash-error $DOT/login.html
|
grep -C 1 flash-error $DOT/login.html
|
||||||
if ${DEBUG} ; then
|
if ${DEBUG}; then
|
||||||
cat $DOT/login.html
|
cat $DOT/login.html
|
||||||
fi
|
fi
|
||||||
fatal_error login failed, the user or password are probably incorrect, try again with --verbose
|
fatal_error login failed, the user or password are probably incorrect, try again with --verbose
|
||||||
|
@ -160,12 +163,11 @@ function login() {
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
rm -f $DOT/*
|
rm -f $DOT/*
|
||||||
if test -d $DOT ; then
|
if test -d $DOT; then
|
||||||
rmdir $DOT
|
rmdir $DOT
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
cat >&2 <<EOF
|
cat >&2 <<EOF
|
||||||
forgejo-curl.sh - thin curl wrapper that helps with Forgejo authentication
|
forgejo-curl.sh - thin curl wrapper that helps with Forgejo authentication
|
||||||
|
@ -327,7 +329,7 @@ function main() {
|
||||||
echo "forgejo-curl.sh version $VERSION"
|
echo "forgejo-curl.sh version $VERSION"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--help|*)
|
--help | *)
|
||||||
usage
|
usage
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
|
|
55
tests/run.sh
55
tests/run.sh
|
@ -4,7 +4,7 @@
|
||||||
set -e
|
set -e
|
||||||
set -o posix
|
set -o posix
|
||||||
|
|
||||||
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
TMPDIR=/tmp/cascading-pr-test
|
TMPDIR=/tmp/cascading-pr-test
|
||||||
export LOOP_DELAY=5
|
export LOOP_DELAY=5
|
||||||
mkdir -p $TMPDIR
|
mkdir -p $TMPDIR
|
||||||
|
@ -44,8 +44,8 @@ function user_secret() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function orgs_delete() {
|
function orgs_delete() {
|
||||||
forgejo-curl.sh api_json ${options[url]}/api/v1/orgs | jq --raw-output '.[] | .name' | while read owner ; do
|
forgejo-curl.sh api_json ${options[url]}/api/v1/orgs | jq --raw-output '.[] | .name' | while read owner; do
|
||||||
forgejo-curl.sh api_json ${options[url]}/api/v1/orgs/$owner/repos | jq --raw-output '.[] | .name' | while read repo ; do
|
forgejo-curl.sh api_json ${options[url]}/api/v1/orgs/$owner/repos | jq --raw-output '.[] | .name' | while read repo; do
|
||||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/$repo
|
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/$repo
|
||||||
done
|
done
|
||||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/orgs/$owner
|
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/orgs/$owner
|
||||||
|
@ -55,7 +55,7 @@ function orgs_delete() {
|
||||||
function user_create() {
|
function user_create() {
|
||||||
local username="$1" email="$2"
|
local username="$1" email="$2"
|
||||||
log_verbose "(re)create user $username"
|
log_verbose "(re)create user $username"
|
||||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/admin/users/$username?purge=true >& /dev/null || true
|
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/admin/users/$username?purge=true >&/dev/null || true
|
||||||
forgejo-curl.sh api_json --data '{"username":"'$username'","email":"'$email'","password":"'${options[password]}'","must_change_password":false}' ${options[url]}/api/v1/admin/users
|
forgejo-curl.sh api_json --data '{"username":"'$username'","email":"'$email'","password":"'${options[password]}'","must_change_password":false}' ${options[url]}/api/v1/admin/users
|
||||||
user_login $username
|
user_login $username
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ function close_pull_request() {
|
||||||
local repo=$1
|
local repo=$1
|
||||||
|
|
||||||
log_verbose "close all pull requests in user1/$repo"
|
log_verbose "close all pull requests in user1/$repo"
|
||||||
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr ; do
|
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr; do
|
||||||
forgejo-curl.sh api_json -X PATCH --data '{"state":"closed"}' ${options[url]}/api/v1/repos/user1/${repo}/issues/$pr
|
forgejo-curl.sh api_json -X PATCH --data '{"state":"closed"}' ${options[url]}/api/v1/repos/user1/${repo}/issues/$pr
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ function merge_pull_request() {
|
||||||
local repo=$1
|
local repo=$1
|
||||||
|
|
||||||
log_verbose "merge all pull requests in user1/$repo"
|
log_verbose "merge all pull requests in user1/$repo"
|
||||||
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr ; do
|
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr; do
|
||||||
forgejo-curl.sh api_json --data '{"Do":"merge"}' ${options[url]}/api/v1/repos/user1/${repo}/pulls/$pr/merge
|
forgejo-curl.sh api_json --data '{"Do":"merge"}' ${options[url]}/api/v1/repos/user1/${repo}/pulls/$pr/merge
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -120,15 +120,15 @@ function create_branch1() {
|
||||||
local owner=$1 repo=$2 modify=$3
|
local owner=$1 repo=$2 modify=$3
|
||||||
|
|
||||||
log_verbose "(re)create branch1 in $owner/$repo"
|
log_verbose "(re)create branch1 in $owner/$repo"
|
||||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/${repo}/branches/branch1 >& /dev/null || true
|
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/${repo}/branches/branch1 >&/dev/null || true
|
||||||
forgejo-curl.sh api_json --data '{"new_branch_name":"branch1"}' ${options[url]}/api/v1/repos/$owner/${repo}/branches
|
forgejo-curl.sh api_json --data '{"new_branch_name":"branch1"}' ${options[url]}/api/v1/repos/$owner/${repo}/branches
|
||||||
(
|
(
|
||||||
cd $TMPDIR
|
cd $TMPDIR
|
||||||
rm -fr ${repo}
|
rm -fr ${repo}
|
||||||
git clone -b branch1 http://user1:admin1234@${options[host_port]}/$owner/${repo}
|
git clone -b branch1 http://user1:admin1234@${options[host_port]}/$owner/${repo}
|
||||||
cd ${repo}
|
cd ${repo}
|
||||||
echo CONTENT > README
|
echo CONTENT >README
|
||||||
if test "$modify" ; then
|
if test "$modify"; then
|
||||||
log_verbose "modify branch1 in $owner/$repo with $modify"
|
log_verbose "modify branch1 in $owner/$repo with $modify"
|
||||||
$modify
|
$modify
|
||||||
fi
|
fi
|
||||||
|
@ -137,19 +137,18 @@ function create_branch1() {
|
||||||
git add .
|
git add .
|
||||||
git commit -m 'update'
|
git commit -m 'update'
|
||||||
git push origin branch1
|
git push origin branch1
|
||||||
git rev-parse HEAD > ../${owner}-${repo}.sha
|
git rev-parse HEAD >../${owner}-${repo}.sha
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_pull_requests() {
|
function delete_pull_requests() {
|
||||||
local owner=$1 repo=$2
|
local owner=$1 repo=$2
|
||||||
|
|
||||||
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/$owner/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr ; do
|
forgejo-curl.sh api_json ${options[url]}/api/v1/repos/$owner/${repo}/pulls | jq --raw-output '.[] | .number' | while read pr; do
|
||||||
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/${repo}/issues/$pr
|
forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/$owner/${repo}/issues/$pr
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function create_pull_request() {
|
function create_pull_request() {
|
||||||
local baseowner=$1 headowner=$2 repo=$3
|
local baseowner=$1 headowner=$2 repo=$3
|
||||||
|
|
||||||
|
@ -159,7 +158,7 @@ function create_pull_request() {
|
||||||
else
|
else
|
||||||
head=$headowner:branch1
|
head=$headowner:branch1
|
||||||
fi
|
fi
|
||||||
cat > $TMPDIR/data <<EOF
|
cat >$TMPDIR/data <<EOF
|
||||||
{"title":"PR","base":"main","head":"$head"}
|
{"title":"PR","base":"main","head":"$head"}
|
||||||
EOF
|
EOF
|
||||||
log_verbose "create pull request in $baseowner/$repo from $head"
|
log_verbose "create pull request in $baseowner/$repo from $head"
|
||||||
|
@ -184,9 +183,9 @@ function unit_finalize_options() {
|
||||||
function unit_retry_fail() {
|
function unit_retry_fail() {
|
||||||
local file=$1
|
local file=$1
|
||||||
local value=$(cat $file)
|
local value=$(cat $file)
|
||||||
expr $value - 1 > $file
|
expr $value - 1 >$file
|
||||||
echo RESULT
|
echo RESULT
|
||||||
if test $value -gt 0 ; then
|
if test $value -gt 0; then
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
|
@ -201,25 +200,25 @@ function unit_retry() {
|
||||||
#
|
#
|
||||||
# Succeeds after two tries
|
# Succeeds after two tries
|
||||||
#
|
#
|
||||||
echo 2 > $TMPDIR/unit_retry_two
|
echo 2 >$TMPDIR/unit_retry_two
|
||||||
if ! RETRY_DELAYS='1 1 1 1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $TMPDIR/retry.test-log ; then
|
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
|
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
|
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
|
||||||
if test "$(grep -c '^waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 2 ; then
|
if test "$(grep -c '^waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 2; then
|
||||||
cat $TMPDIR/retry.test-log
|
cat $TMPDIR/retry.test-log
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
#
|
#
|
||||||
# Succeeds immediately
|
# Succeeds immediately
|
||||||
#
|
#
|
||||||
if ! RETRY_DELAYS='1' retry unit_retry_fail $two > $TMPDIR/retry.test-result 2> $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
|
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
|
test "$(cat $TMPDIR/retry.test-result)" = "RESULT"
|
||||||
if test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 0 ; then
|
if test "$(grep -c 'waiting 1 unit_retry_fail' $TMPDIR/retry.test-log)" != 0; then
|
||||||
cat $TMPDIR/retry.test-log
|
cat $TMPDIR/retry.test-log
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -228,14 +227,14 @@ function unit_retry() {
|
||||||
# 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
|
||||||
# unrelated output
|
# unrelated output
|
||||||
#
|
#
|
||||||
echo 2 > $TMPDIR/unit_retry_two
|
echo 2 >$TMPDIR/unit_retry_two
|
||||||
test "$(RETRY_DELAYS='1 1 1' retry unit_retry_fail $two)" = "RESULT"
|
test "$(RETRY_DELAYS='1 1 1' retry unit_retry_fail $two)" = "RESULT"
|
||||||
|
|
||||||
#
|
#
|
||||||
# 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 > $TMPDIR/retry.test-result 2> $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
|
cat $TMPDIR/retry.test-result $TMPDIR/retry.test-log
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -323,11 +322,11 @@ function create_and_close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function taint_update() {
|
function taint_update() {
|
||||||
if ! test -f upgraded ; then
|
if ! test -f upgraded; then
|
||||||
echo upgraded file not found
|
echo upgraded file not found
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
echo 'TAINTED' > upgraded
|
echo 'TAINTED' >upgraded
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_from_origin_fork_and_close() {
|
function create_from_origin_fork_and_close() {
|
||||||
|
@ -423,14 +422,14 @@ function run() {
|
||||||
shift
|
shift
|
||||||
|
|
||||||
echo "Start running $fun ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
echo "Start running $fun ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
||||||
if $DEBUG ; then
|
if $DEBUG; then
|
||||||
$fun "$@"
|
$fun "$@"
|
||||||
else
|
else
|
||||||
mkdir -p $TMPDIR
|
mkdir -p $TMPDIR
|
||||||
> $TMPDIR/$fun.out
|
>$TMPDIR/$fun.out
|
||||||
tail --follow $TMPDIR/$fun.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" &
|
tail --follow $TMPDIR/$fun.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" &
|
||||||
pid=$!
|
pid=$!
|
||||||
if ! ${BASH_SOURCE[0]} --debug ${options[args]} $fun "$@" >& $TMPDIR/$fun.out ; then
|
if ! ${BASH_SOURCE[0]} --debug ${options[args]} $fun "$@" >&$TMPDIR/$fun.out; then
|
||||||
kill $pid
|
kill $pid
|
||||||
cat $TMPDIR/$fun.out
|
cat $TMPDIR/$fun.out
|
||||||
echo Failure running $fun
|
echo Failure running $fun
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue