end-to-end/actions/actions.sh
Twenty Panda 96f91063c9 merge actions test into end-to-end.sh
* replace the high level test running actions tests with end-to-end.sh
* set DOMAIN to the IP instead of 127.0.0.1 for runner <-> forgejo communications
* move forgejo_cli from a function to a file so that it can be used by forgejo-runner.sh
* keep the documentation updates workflows separate because they need to open one PR per version
2024-03-20 13:42:44 +01:00

99 lines
2.5 KiB
Bash
Executable file

# Copyright 2024 The Forgejo Authors
# SPDX-License-Identifier: MIT
ACTIONS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function actions_verify_example() {
local example=$1
export url=http://${FORGEJO_USER}:${FORGEJO_PASSWORD}@${HOST_PORT}
export token=$(cat $DOT_FORGEJO_CURL/token)
actions_cleanup_example_volume
export example
export EXAMPLE_DIR=$ACTIONS_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
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
actions_save_contexts $example
}
function actions_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 actions_cleanup_example_volume() {
if test $(id -u) != 0 ; then
$SUDO chown $(id -u) /srv
fi
if ! test -d /srv/example ; then
mkdir -p /srv/example
return
fi
$SUDO rm -fr /srv/example/*
}
function actions_setup() {
local version=$1
actions_teardown
reset_forgejo $ACTIONS_DIR/default-app.ini
start_forgejo $version
export FORGEJO_RUNNER_LOGS=$DIR/forgejo-runner.log
actions_cleanup_example_volume
export FORGEJO_RUNNER_CONFIG=$ACTIONS_DIR/runner-config.yaml
forgejo-runner.sh setup '' '' http://${HOST_PORT}
}
function actions_teardown() {
forgejo-curl.sh logout
forgejo-runner.sh teardown
stop_daemon forgejo
}
function test_actions() {
local versions="${1:-1.20 1.21 $RELEASE_NUMBERS_AND_DEV}"
for version in $versions ; do
log_info "Testing actions for $version"
actions_setup $version
for example in echo checkout service container expression local-action docker-action if if-fail ; do
run actions_verify_example $example
done
if dpkg --compare-versions $version gt 1.20 ; then
for example in push tag push-cancel artifacts pull-request context cron ; do
run actions_verify_example $example
done
fi
done
}