move db setup to a script for easier re-use

This commit is contained in:
Shish 2024-01-04 00:15:08 +00:00
parent f4da2e92f0
commit a3d7a05f71
2 changed files with 31 additions and 28 deletions

View file

@ -85,25 +85,7 @@ jobs:
extensions: mbstring extensions: mbstring
- name: Set up database - name: Set up database
run: | run: ./tests/setup-db.sh "${{ matrix.database }}"
mkdir -p data/config
if [[ "${{ matrix.database }}" == "pgsql" ]]; then
sudo systemctl start postgresql ;
psql --version ;
sudo -u postgres psql -c "SELECT set_config('log_statement', 'all', false);" -U postgres ;
sudo -u postgres psql -c "CREATE USER shimmie WITH PASSWORD 'shimmie';" -U postgres ;
sudo -u postgres psql -c "CREATE DATABASE shimmie WITH OWNER shimmie;" -U postgres ;
fi
if [[ "${{ matrix.database }}" == "mysql" ]]; then
sudo systemctl start mysql ;
mysql --version ;
mysql -e "SET GLOBAL general_log = 'ON';" -uroot -proot ;
mysql -e "CREATE DATABASE shimmie;" -uroot -proot ;
fi
if [[ "${{ matrix.database }}" == "sqlite" ]]; then
sudo apt update && sudo apt-get install -y sqlite3 ;
sqlite3 --version ;
fi
- name: Check versions - name: Check versions
run: php -v && composer -V run: php -v && composer -V
@ -116,15 +98,6 @@ jobs:
- name: Run test suite - name: Run test suite
run: | run: |
if [[ "${{ matrix.database }}" == "pgsql" ]]; then
export TEST_DSN="pgsql:user=shimmie;password=shimmie;host=127.0.0.1;dbname=shimmie"
fi
if [[ "${{ matrix.database }}" == "mysql" ]]; then
export TEST_DSN="mysql:user=root;password=root;host=127.0.0.1;dbname=shimmie"
fi
if [[ "${{ matrix.database }}" == "sqlite" ]]; then
export TEST_DSN="sqlite:data/shimmie.sqlite"
fi
if [[ "${{ matrix.php }}" == "8.3" ]]; then if [[ "${{ matrix.php }}" == "8.3" ]]; then
vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover
else else

30
tests/setup-db.sh Executable file
View file

@ -0,0 +1,30 @@
#!/bin/sh
DATABASE=$1
mkdir -p data/config
if [[ "$DATABASE" == "pgsql" ]]; then
sudo systemctl start postgresql
psql --version
sudo -u postgres psql -c "SELECT set_config('log_statement', 'all', false);" -U postgres
sudo -u postgres psql -c "CREATE USER shimmie WITH PASSWORD 'shimmie';" -U postgres
sudo -u postgres psql -c "CREATE DATABASE shimmie WITH OWNER shimmie;" -U postgres
export TEST_DSN="pgsql:user=shimmie;password=shimmie;host=127.0.0.1;dbname=shimmie"
fi
if [[ "$DATABASE" == "mysql" ]]; then
sudo systemctl start mysql
mysql --version
mysql -e "SET GLOBAL general_log = 'ON';" -uroot -proot
mysql -e "CREATE DATABASE shimmie;" -uroot -proot
export TEST_DSN="mysql:user=root;password=root;host=127.0.0.1;dbname=shimmie"
fi
if [[ "$DATABASE" == "sqlite" ]]; then
sudo apt update && sudo apt-get install -y sqlite3
sqlite3 --version
export TEST_DSN="sqlite:data/shimmie.sqlite"
fi
if [[ -n "$GITHUB_ENV" ]]; then
echo "TEST_DSN=$TEST_DSN" >> $GITHUB_ENV
fi