Skip to content

Add individual quiz runner #27

Add individual quiz runner

Add individual quiz runner #27

Workflow file for this run

name: Behat
on:
pull_request:
branches: [ "main", "staging" ]
push:
branches: [ "vincetheis-behat" ]
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: install mariadb
run: |
sudo cat /etc/hosts
sudo apt install mariadb-server
sudo systemctl disable mariadb
sudo systemctl stop mariadb
- name: Exorcises Snap from the system
run: |
# The snap version of firefox doesn't work with behat,
# so we have to make sure that apt doesn't install it
# via snap.
echo ✝️✝️ GO AWAY SNAP GO AWAY GO AWAY ✝️✝️ # This line is necessary
sudo apt autoremove --purge snapd
sudo apt-mark hold snapd
# Apparently, if we don't do this, Ubuntu will
# automatically reinstall snap without asking us
# when we try to install Firefox
sudo add-apt-repository ppa:mozillateam/ppa
echo '
Package: *
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 1001
Package: firefox
Pin: version 1:1snap*
Pin-Priority: -1
' | sudo tee /etc/apt/preferences.d/mozilla-firefox
echo ✝️✝️ GO AWAY SNAP GO AWAY GO AWAY ✝️✝️ # This line is also necessary
- name: install Firefox
run: sudo apt install firefox
- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
extensions: phar, iconv, mbstring, gd, intl, sodium, zip
tools: composer
- name: Set up the database and start pretty much everything
run: |
set -x
mariadb_data_dir="./mariadb_data"
mariadb_socket="/run/mysqld/mysqld.sock"
moodle_db_name="moodle"
moodle_sql_file="./MoodleSQL.sql"
root_username="root"
root_password="root"
# Function to check and kill existing processes
kill_existing() {
local process=$1
if pgrep -x "$process" > /dev/null; then
echo "Killing existing $process process..."
sudo pkill -x "$process"
sleep 2
fi
}
# Function to kill process using a specific port
kill_port_user() {
local port=$1
local pid=$(lsof -ti:$port)
if [ ! -z "$pid" ]; then
echo "Killing process using port $port..."
sudo kill -9 $pid
sleep 2
fi
}
# Ensure MariaDB data directory exists
mkdir -p ${mariadb_data_dir}
ls -l
# Ensure MariaDB data directory exists
mkdir -p ${mariadb_data_dir}
ls -l
# Initialize MariaDB if not already done
if [ ! -d "${mariadb_data_dir}/mysql" ]; then
mysql_install_db --datadir=${mariadb_data_dir}
# Start MariaDB temporarily to set up the database
# sudo touch ${mariadb_socket}
sudo chmod -R 2777 `dirname ${mariadb_socket}`
mysqld --datadir=${mariadb_data_dir} --socket=${mariadb_socket} --skip-grant-tables &
TEMP_MYSQL_PID=$!
while [ ! -S ${mariadb_socket} ];
do
echo "no socket file. Waiting 2 secs and trying again";
sleep 2
done
echo "MariaDB is up continuing.";
mysqld --verbose --help | grep "socket"
ps aux | grep mysqld
# Set root password and authentication method
echo "Setting root password..."
mysql -uroot -S${mariadb_socket} <<EOF
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '${root_password}';
FLUSH PRIVILEGES;
EOF
# Verify root password
echo "Verifying root password..."
mysql -uroot -p${root_password} -S${mariadb_socket} -e "SELECT 1;" || {
echo "Error: Root password verification failed."
kill $TEMP_MYSQL_PID
wait $TEMP_MYSQL_PID
exit 1
}
mysql -uroot -p${root_password} -S${mariadb_socket} -e "CREATE DATABASE IF NOT EXISTS ${moodle_db_name}" || {
echo "Error: Failed to create database ${moodle_db_name}."
kill $TEMP_MYSQL_PID
wait $TEMP_MYSQL_PID
exit 1
}
if [ -f "${moodle_sql_file}" ]; then
mysql -uroot -p${root_password} -S${mariadb_socket} ${moodle_db_name} < ${moodle_sql_file} && {
echo "SQL file imported successfully."
} || {
echo "Error: Failed to import SQL file."
}
else
echo "Warning: ${moodle_sql_file} not found. Database created but not populated."
fi
kill $TEMP_MYSQL_PID
wait $TEMP_MYSQL_PID
fi
# Kill existing MariaDB and PHP processes
kill_existing "mysqld"
kill_existing "php"
# Start MariaDB
start_mariadb() {
echo "Starting MariaDB..."
mysqld --datadir=${mariadb_data_dir} --socket=${mariadb_socket} &
MARIADB_PID=$!
while [ ! -S ${mariadb_socket} ];
do
echo "no socket file. Waiting 2 secs and trying again";
sleep 2
done
echo "socket is here continuing.";
}
# Adminer is not required for testing, so we skip the setup
# Start PHP built-in server for Moodle
start_php_server() {
echo "Starting PHP built-in server for Moodle..."
php -S 0.0.0.0:8000 -t `realpath server/moodle` &
PHP_SERVER_PID=$!
}
# Function to stop services
stop_services() {
echo "Stopping services..."
kill $MARIADB_PID $PHP_SERVER_PID 2>/dev/null
rm -f ${mariadb_socket}
}
# Start services`
start_mariadb
start_php_server
echo "MariaDB and PHP server are now running."
echo "Moodle is available at http://localhost:8000"
echo "To connect to MariaDB, use:"
echo " Host: 127.0.0.1 or localhost"
echo " Username: root"
echo " Password: ${root_password}"
echo " Database: ${moodle_db_name}"
echo "Press Ctrl+C to stop the services and exit."
- name: Set up geckodriver
uses: browser-actions/setup-geckodriver@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Initialise moodle, to create config.php
run: |
echo en_AU.UTF-8 UTF-8 | sudo tee -a /etc/locale.gen
sudo locale-gen
if [ "$(php -r "echo ini_get('max_input_vars');")" -lt 5000 ]; then
echo "max_input_vars = 5000" >> /etc/php/8.3/cli/php.ini
fi
export LANG="en_AU.UTF-8"
export LC_ALL="en_AU.UTF-8"
export PHPRC=`realpath /etc/php/8.3/cli/php.ini`
REPO_ROOT="`pwd`"
cd "$REPO_ROOT"/server/moodle
php admin/cli/install.php \
--lang=en \
--wwwroot="http://127.0.0.1:8000/" \
--dataroot="$REPO_ROOT/server/moodledata" \
--dbpass=root \
--dbport=3306 \
--dbsocket=/run/mysqld/mysqld.sock \
--skip-database \
--non-interactive \
--agree-license \
--allow-unstable \
--fullname="Moodle testing thing" \
--shortname="mtt" \
--adminpass="hunter2"
echo 'hi:('
ss -nltp
- name: Set up selenium.
run: |
wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.25.0/selenium-server-4.25.0.jar
#ampersand means in background
java -jar selenium-server-4.25.0.jar standalone &
echo `realpath .` >> $GITHUB_PATH
- name: Download moodle-browser-config
run: |
export MBCPATH=`realpath .`/moodle-browser-config
git clone https://github.com/andrewnicols/moodle-browser-config $MBCPATH
#Inserts require_once('$MBCPATH/init.php') before the other require_once, as specified in the document
sed -i "/^require_once(__DIR__ . '\/lib\/setup.php');/i require_once('$MBCPATH/init.php');" server/moodle/config.php
- name: Install & Init Behat
run: |
set -x
cd server/moodle
# Inserts all those lines before the require_once line mentioned before.
# This is necessary because moodle is stupid.
sed -i "/^require_once(__DIR__ . '\/lib\/setup.php');/i \$CFG->behat_dataroot = \$CFG->dataroot . '/behat';" config.php
sed -i "/^require_once(__DIR__ . '\/lib\/setup.php');/i \$CFG->behat_wwwroot = 'http:\/\/localhost:8000';" config.php
sed -i "/^require_once(__DIR__ . '\/lib\/setup.php');/i \$CFG->behat_dataroot_parent = \$CFG->dataroot . '\/behat';" config.php
sed -i "/^require_once(__DIR__ . '\/lib\/setup.php');/i \$CFG->behat_prefix = 'beh_';" config.php
composer install
php admin/tool/behat/cli/init.php
- name: Run tests
run: |
cd server/moodle
vendor/bin/behat --config `realpath ../moodledata/behat/behatrun/behat/behat.yml` --profile=headlessfirefox --tags=@mod_livequiz