From a3d7a05f710f2fd6f70281cc9b1fe2d89957498f Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 4 Jan 2024 00:15:08 +0000 Subject: [PATCH] move db setup to a script for easier re-use --- .github/workflows/tests.yml | 29 +---------------------------- tests/setup-db.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 28 deletions(-) create mode 100755 tests/setup-db.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 43a21328..889e7e84 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -85,25 +85,7 @@ jobs: extensions: mbstring - name: Set up database - run: | - 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 + run: ./tests/setup-db.sh "${{ matrix.database }}" - name: Check versions run: php -v && composer -V @@ -116,15 +98,6 @@ jobs: - name: Run test suite 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 vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover else diff --git a/tests/setup-db.sh b/tests/setup-db.sh new file mode 100755 index 00000000..f3370c3b --- /dev/null +++ b/tests/setup-db.sh @@ -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