From 383a4aed65544b773f4c078e7f62ba60fe73f271 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:05:53 +0400 Subject: [PATCH] setup database before running tests --- .github/workflows/test.yml | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a01e8e..ed9c669 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,12 +11,33 @@ permissions: jobs: build: - runs-on: ubuntu-latest - + services: + mysql: + image: mysql:8.0 + env: + # The MySQL docker container requires these environment variables to be set + # so we can create and migrate the test database. + # See: https://hub.docker.com/_/mysql + MYSQL_DATABASE: cafe_test + MYSQL_ROOT_PASSWORD: password + ports: + # Opens port 3306 on service container and host + # https://docs.github.com/en/actions/using-containerized-services/about-service-containers + - 3306:3306 + # Before continuing, verify the mysql container is reachable from the ubuntu host + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 steps: - uses: actions/checkout@v3 + # - name: Install Ubuntu dependencies + # run: | + # sudo apt-get update + # sudo apt-get install libcurl4-openssl-dev libmysqlclient-dev libgirepository1.0-dev + + - name: Import SQL dump to cafe_test database + run: mysql -Dcafe_test -uroot -ppassword -h127.0.0.1 -P33306 < "resources/database/dump/cafe.sql" + - name: Validate composer.json and composer.lock run: composer validate --strict @@ -29,8 +50,16 @@ jobs: restore-keys: | ${{ runner.os }}-php- - - name: Install dependencies + - name: Install Composer dependencies run: composer install --prefer-dist --no-progress + # - name: Start database service + # run: sudo systemctl start mysql.service + - name: Run test suite + env: + DB_HOST: 127.0.0.1 + DB_USERNAME: root + DB_PASSWORD: password + TEST_DB_NAME: cafe_test run: composer test