end-to-end/actions/run.sh

128 lines
3.1 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
set -o pipefail
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function run() {
local example=$1
export example
export EXAMPLE_DIR=$SELF_DIR/example-$example
if test -f $EXAMPLE_DIR/setup.sh ; then
echo "============================ SETUP example-$example ==================="
bash -ex $EXAMPLE_DIR/setup.sh || return 1
fi
if test -f $EXAMPLE_DIR/run.sh ; then
echo "============================ RUN example-$example ==================="
bash -ex $EXAMPLE_DIR/run.sh || return 1
else
2024-01-05 18:37:15 +00:00
forgejo-test-helper.sh run_workflow actions/example-$example $url root example-$example $example $token || return 1
fi
if test -f $EXAMPLE_DIR/teardown.sh ; then
echo "============================ TEARDOWN example-$example ==================="
bash -ex $EXAMPLE_DIR/teardown.sh || return 1
fi
}
function examples_v1_20() {
echo 'echo checkout service container expression local-action docker-action if if-fail'
}
function examples_v1_21() {
# keep "cron" last otherwise it will linger and pollute the following runs
2024-01-13 17:03:40 +00:00
echo 'echo push tag push-cancel artifacts service checkout pull-request container expression local-action context docker-action if if-fail cron'
}
function examples_v7_0() {
examples_v1_21
}
function save_contexts() {
local example="$1"
if test -d /srv/example/$example/contexts; then
mkdir -p /srv/contexts
rsync -av /srv/example/$example/contexts/ /srv/contexts/$example/
fi
}
function cleanup_example_volume() {
if ! test -d /srv/example ; then
mkdir -p /srv/example
return
fi
if test $(id -u) != 0 ; then
SUDO=sudo
fi
$SUDO rm -fr /srv/example/*
}
function setup() {
local binary=$1
forgejo-binary.sh setup root admin1234 $binary
cleanup_example_volume
export FORGEJO_RUNNER_CONFIG=$SELF_DIR/runner-config.yaml
forgejo-runner.sh setup
}
function teardown() {
forgejo-curl.sh logout
forgejo-runner.sh teardown
forgejo-binary.sh teardown
}
function main() {
local binary="$1"
shift
2024-01-07 17:08:41 +00:00
export full_version="$1"
shift
export version="$1"
shift
export DOT=$DIR/forgejo-curl
teardown
if test "$#" = 0 ; then
2024-01-07 17:08:41 +00:00
examples=$(examples_${version/./_})
else
examples="$@"
fi
if test "$examples" = "none" ; then
exit 0
fi
setup $binary
if ! test -f "$DIR/forgejo-auth-url" ; then
echo "DIR=$DIR must be a directory with a forgejo-auth-url file"
fi
export FORGEJO_RUNNER_LOGS=$DIR/forgejo-runner.log
export url=$(cat $DIR/forgejo-auth-url)
export token=$(cat $DIR/forgejo-token)
for example in $examples ; do
echo "======================== BEGIN example-$example ==================="
if ! time run $example >& /tmp/run.out ; then
2024-01-05 18:37:15 +00:00
sed -e 's/^/[RUN] /' < /tmp/run.out
echo "======================== FAIL example-$example ==================="
sleep 5 # hack for Forgejo v1.21 to workaround a bug by which the last lines of the output are moved to the next step
false
fi
echo "======================== END example-$example ==================="
save_contexts $example
cleanup_example_volume
done
}
main "$@"