hercules/tools/ci/travis.sh
Ibrahim Zidan f00c0f910e
Update copyrights for year 2026
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
2026-06-28 21:05:37 +03:00

319 lines
11 KiB
Bash
Executable file

#!/usr/bin/env bash
# This file is part of Hercules.
# http://herc.ws - http://github.com/HerculesWS/Hercules
#
# Copyright (C) 2014-2026 Hercules Dev Team
#
# Hercules is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Base Author: Haru @ http://herc.ws
if [ "$1" == "--sanitizer-build" ]; then
SANITIZER_BUILD=1
shift
fi
MODE="$1"
shift
function foo {
for i in "$@"; do
echo "> $i"
done
}
function usage {
echo "usage:"
echo " $0 createdb <dbname> [dbuser] [dbpassword] [dbhost]"
echo " $0 importdb <dbname> [dbuser] [dbpassword] [dbhost]"
echo " $0 adduser <dbname> <new_user> <new_user_password> [dbuser] [dbpassword] [dbhost]"
echo " $0 build [configure args]"
echo " $0 test <dbname> [dbuser] [dbpassword] [dbhost]"
echo " $0 getplugins"
echo " $0 startmysql"
echo " $0 extratest"
echo " $0 prepareenv"
exit 1
}
function aborterror {
echo $@
exit 1
}
function run_server {
echo "Running: $1 --run-once $2"
rm -rf core* || true
BACKUP_LD_PRELOAD="$LD_PRELOAD"
if [ $SANITIZER_BUILD -eq 1 ]; then
export LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/15/libasan.so
fi
CRASH_PLEASE=1 $1 --run-once $2 2>runlog.txt
LD_PRELOAD="$BACKUP_LD_PRELOAD"
export errcode=$?
export teststr=$(head -c 10000 runlog.txt|grep -v "WARNING: MYSQL_OPT_RECONNECT is deprecated and will be removed in a future version.")
if [[ -n "${teststr}" ]]; then
echo "Errors found in running server $1."
head -c 10000 runlog.txt
aborterror "Errors found in running server $1."
else
echo "No errors found for server $1."
fi
if [ ${errcode} -ne 0 ]; then
echo "server $1 terminated with exit code ${errcode}"
COREFILE=$(find . -maxdepth 1 -name "core*" | head -n 1)
if [[ -f "$COREFILE" ]]; then
gdb -c "$COREFILE" $1 -ex "thread apply all bt" -ex "set pagination 0" -batch
fi
aborterror "Test failed"
fi
}
function run_test {
echo "Running tests $1"
sysctl -w kernel.core_pattern=core || true
rm -rf core* || true
(cd build && ctest -R "$1" > ../runlog.txt)
export errcode=$?
if [ ${errcode} -ne 0 ]; then
echo "Tests terminated with exit code ${errcode}"
echo cat runlog.txt
cat runlog.txt
aborterror "Tests failed"
fi
}
# Defaults
DBNAME=ragnarok
DBUSER=ragnarok
DBPASS=ragnarok
DBHOST=localhost
SANITIZER_BUILD=0
case "$MODE" in
createdb|importdb|test)
if [ -z "$1" ]; then
usage
fi
DBNAME="$1"
if [ -n "$2" ]; then
DBUSER_ARG="--user=$2"
DBUSER="$2"
fi
if [ -n "$3" ]; then
DBPASS_ARG="--password=$3"
DBPASS="$3"
fi
if [ -n "$4" ]; then
DBHOST_ARG="--host=$4"
DBHOST="$4"
fi
;;
adduser)
if [ -z "$3" ]; then
usage
fi
DBNAME="$1"
NEWUSER="$2"
NEWPASS="$3"
if [ -n "$4" ]; then
DBUSER_ARG="--user=$4"
DBUSER="$4"
fi
if [ -n "$5" ]; then
DBPASS_ARG="--password=$5"
DBPASS="$5"
fi
if [ -n "$6" ]; then
DBHOST_ARG="--host=$6"
DBHOST="$6"
fi
;;
esac
SSL_ARG=""
if [[ $(mysql --version) =~ "MariaDB" ]]; then
SSL_ARG="--ssl=0"
fi
case "$MODE" in
createdb)
echo "Creating database $DBNAME as $DBUSER..."
mysql $DBUSER_ARG $DBPASS_ARG $DBHOST_ARG $SSL_ARG --execute="CREATE DATABASE $DBNAME;" || aborterror "Unable to create database."
;;
importdb)
echo "Importing tables into $DBNAME as $DBUSER..."
mysql $DBUSER_ARG $DBPASS_ARG $DBHOST_ARG $SSL_ARG --database=$DBNAME < sql-files/main.sql || aborterror "Unable to import main database."
mysql $DBUSER_ARG $DBPASS_ARG $DBHOST_ARG $SSL_ARG --database=$DBNAME < sql-files/logs.sql || aborterror "Unable to import logs database."
;;
adduser)
echo "Adding user $NEWUSER as $DBUSER, with access to database $DBNAME..."
mysql $DBUSER_ARG $DBPASS_ARG $DBHOST_ARG $SSL_ARG --execute="GRANT SELECT,INSERT,UPDATE,DELETE ON $DBNAME.* TO '$NEWUSER'@'$DBHOST' IDENTIFIED BY '$NEWPASS';" || true
mysql $DBUSER_ARG $DBPASS_ARG $DBHOST_ARG $SSL_ARG --execute="CREATE USER '$NEWUSER'@'$DBHOST' IDENTIFIED BY '$NEWPASS';" || true
mysql $DBUSER_ARG $DBPASS_ARG $DBHOST_ARG $SSL_ARG --execute="GRANT SELECT,INSERT,UPDATE,DELETE ON $DBNAME.* TO '$NEWUSER'@'$DBHOST';" || true
mysql $DBUSER_ARG $DBPASS_ARG $DBHOST_ARG $SSL_ARG --execute="ALTER USER '$NEWUSER'@'$DBHOST' IDENTIFIED BY '$NEWPASS';" || true
if [[ -n "$(uname -a | grep -i linux)" ]]; then
mysql --defaults-file=/etc/mysql/debian.cnf $DBPASS_ARG $DBHOST_ARG $SSL_ARG --execute="CREATE USER '$NEWUSER'@'$DBHOST' IDENTIFIED BY '$NEWPASS';" || true
mysql --defaults-file=/etc/mysql/debian.cnf $DBPASS_ARG $DBHOST_ARG $SSL_ARG --execute="GRANT SELECT,INSERT,UPDATE,DELETE ON $DBNAME.* TO '$NEWUSER'@'$DBHOST';" || true
mysql --defaults-file=/etc/mysql/debian.cnf $DBPASS_ARG $DBHOST_ARG $SSL_ARG --execute="ALTER USER '$NEWUSER'@'$DBHOST' IDENTIFIED BY '$NEWPASS';" || true
fi
;;
build)
if [[ -z "${SKIP_VALIDATE_INTERFACES}" ]]; then
(cd tools && ./validateinterfaces.py silent) || aborterror "Interface validation error."
else
echo "Skip validateinterfaces"
fi
cmake -B build -S . -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=cmake_modules/conan_provider.cmake -DENABLE_TESTING=ON $@ || aborterror "cmake error, aborting build."
(cd build && make -j3) || aborterror "Build failed."
(cd build && make plugins -j3) || aborterror "Build failed."
(cd build && make plugin.script_mapquit -j3) || aborterror "Build failed."
(cd build && make tests) || aborterror "Build failed."
(cd build && make install) || aborterror "Failed to install targets."
;;
buildhpm)
./configure $@ || (cat config.log && aborterror "Configure error, aborting build.")
cd tools/HPMHookGen
make
;;
test)
cat > conf/travis_sql_connection.conf << EOF
sql_connection: {
//default_codepage: ""
//case_sensitive: false
db_hostname: "$DBHOST"
db_username: "$DBUSER"
db_password: "$DBPASS"
db_database: "$DBNAME"
//codepage:""
}
EOF
[ $? -eq 0 ] || aborterror "Unable to write database configuration, aborting tests."
cat > conf/import/login-server.conf << EOF
login_configuration: {
account: {
@include "conf/travis_sql_connection.conf"
ipban: {
@include "conf/travis_sql_connection.conf"
}
}
}
EOF
[ $? -eq 0 ] || aborterror "Unable to override login-server configuration, aborting tests."
cat > conf/import/char-server.conf << EOF
char_configuration: {
@include "conf/travis_sql_connection.conf"
}
EOF
[ $? -eq 0 ] || aborterror "Unable to override char-server configuration, aborting tests."
cat > conf/import/map-server.conf << EOF
map_configuration: {
@include "conf/travis_sql_connection.conf"
}
EOF
[ $? -eq 0 ] || aborterror "Unable to override map-server configuration, aborting tests."
cat > conf/import/inter-server.conf << EOF
inter_configuration: {
log: {
@include "conf/travis_sql_connection.conf"
}
}
EOF
[ $? -eq 0 ] || aborterror "Unable to override inter-server configuration, aborting tests."
ARGS="--load-script npc/dev/test.txt "
ARGS="--load-plugin script_mapquit $ARGS --load-script npc/dev/ci_test.txt"
PLUGINS="--load-plugin HPMHooking"
echo "run tests"
if [[ $DBUSER == "travis" ]]; then
echo "Disable leak dection on travis"
export ASAN_OPTIONS=detect_leaks=0:detect_stack_use_after_return=true:strict_init_order=true:detect_odr_violation=0
else
export ASAN_OPTIONS=leak_check_at_exit=1:detect_stack_use_after_return=true:strict_init_order=true:detect_odr_violation=0
fi
run_test "base62|chunked|libconfig"
echo "run all servers without HPM"
run_server ./bin/login-server
run_server ./bin/char-server
run_server ./bin/map-server "$ARGS"
run_server ./bin/api-server
echo "run all servers with HPM"
run_server ./bin/login-server "$PLUGINS"
run_server ./bin/char-server "$PLUGINS"
run_server ./bin/map-server "$ARGS $PLUGINS"
run_server ./bin/api-server "$PLUGINS"
echo "run all servers with sample plugin"
run_server ./bin/login-server "$PLUGINS --load-plugin sample"
run_server ./bin/char-server "$PLUGINS --load-plugin sample"
run_server ./bin/map-server "$PLUGINS --load-plugin sample"
run_server ./bin/api-server "$PLUGINS --load-plugin sample"
echo "run all servers with httpsample plugin"
run_server ./bin/login-server "$PLUGINS --load-plugin httpsample"
run_server ./bin/char-server "$PLUGINS --load-plugin httpsample"
run_server ./bin/map-server "$PLUGINS --load-plugin httpsample"
run_server ./bin/api-server "$PLUGINS --load-plugin httpsample"
echo "run all servers with constdb2doc"
run_server ./bin/map-server "$PLUGINS --load-plugin constdb2doc --constdb2doc"
echo "run all servers with db2sql"
run_server ./bin/map-server "$PLUGINS --load-plugin db2sql --db2sql"
run_server ./bin/map-server "$PLUGINS --load-plugin db2sql --itemdb2sql"
run_server ./bin/map-server "$PLUGINS --load-plugin db2sql --mobdb2sql"
echo "run all servers with generate-translations"
run_server ./bin/map-server "$PLUGINS --load-plugin generate-translations --generate-translations"
echo "run all servers with mapcache"
# for other flags need grf or other files
run_server ./bin/map-server "$PLUGINS --load-plugin mapcache --fix-md5"
echo "run all servers with script_mapquit"
run_server ./bin/map-server "$PLUGINS --load-plugin script_mapquit"
;;
extratest)
export ASAN_OPTIONS=leak_check_at_exit=1:detect_stack_use_after_return=true:strict_init_order=true:detect_odr_violation=0
PLUGINS="--load-plugin HPMHooking"
echo "run map server with uncommented old and custom scripts"
find ./npc -type f -name "*.conf" -exec ./tools/ci/uncomment.sh {} \;
run_server ./bin/login-server "$PLUGINS"
run_server ./bin/char-server "$PLUGINS"
run_server ./bin/map-server "$ARGS $PLUGINS"
run_server ./bin/api-server "$PLUGINS"
;;
getplugins)
echo "Cloning plugins repository..."
# Nothing to clone right now, all relevant plugins are part of the repository.
#git clone http://github.com/HerculesWS/StaffPlugins.git || aborterror "Unable to fetch plugin repository"
#if [ -f StaffPlugins/Haru/script_mapquit/script_mapquit.c -a -f StaffPlugins/Haru/script_mapquit/examples/ci_test.txt ]; then
# pushd src/plugins || aborterror "Unable to enter plugins directory."
# ln -s ../../StaffPlugins/Haru/script_mapquit/script_mapquit.c ./
# popd
#else
# echo "Plugin not found, skipping advanced tests."
#fi
;;
startmysql)
echo "Starting mysql..."
service mysql status || true
service mysql stop || true
service mysql start || true
service mysql status || true
;;
prepareenv)
echo "Preparing enviroment"
python3 -m venv .venv || aborterror "Unable to create python virtual env"
source .venv/bin/activate || aborterror "Unable to activate virtual env"
pip install conan || aborterror "Unable to install conan"
;;
*)
usage
;;
esac