workflows/phpunit.yml - adjust mysql setup step #507
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PHPUnit | |
| on: [push, pull_request, workflow_dispatch] | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| run: | |
| runs-on: ${{ matrix.operating-system }} | |
| timeout-minutes: 15 | |
| strategy: | |
| matrix: | |
| operating-system: [ubuntu-latest] | |
| php-version: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] | |
| name: PHP ${{ matrix.php-version }} on ${{ matrix.operating-system }} | |
| env: | |
| MYSQL_DATABASE: test | |
| MYSQL_USERNAME: root | |
| MYSQL_PASSWORD: root | |
| COVERAGE_VER: '8.3' | |
| steps: | |
| - name: Set up MySQL | |
| run: | | |
| # Start MySQL service | |
| sudo systemctl start mysql | |
| # Wait for MySQL to be ready | |
| sudo mysql --wait --connect-timeout=60 -e "SELECT 1" 2>/dev/null || sleep 5 | |
| # Create database using sudo mysql (no password needed initially) | |
| sudo mysql -e 'CREATE DATABASE IF NOT EXISTS ${{ env.MYSQL_DATABASE }};' | |
| # Set up root user password and authentication method | |
| sudo mysql -e "ALTER USER '${{ env.MYSQL_USERNAME }}'@'localhost' IDENTIFIED WITH mysql_native_password BY '${{ env.MYSQL_PASSWORD }}';" || \ | |
| sudo mysql -e "UPDATE mysql.user SET plugin='mysql_native_password', Password=PASSWORD('${{ env.MYSQL_PASSWORD }}') WHERE User='${{ env.MYSQL_USERNAME }}' AND Host='localhost';" || \ | |
| sudo mysql -e "SET PASSWORD FOR '${{ env.MYSQL_USERNAME }}'@'localhost' = PASSWORD('${{ env.MYSQL_PASSWORD }}');" | |
| sudo mysql -e "FLUSH PRIVILEGES;" | |
| # Give MySQL a moment to apply changes | |
| sleep 2 | |
| # Verify connection works with the new password | |
| mysql -u"${{ env.MYSQL_USERNAME }}" -p"${{ env.MYSQL_PASSWORD }}" -e "SHOW DATABASES;" | grep ${{ env.MYSQL_DATABASE }} | |
| echo "MySQL version: $(mysqld --version)" | |
| - name: Checkout | |
| uses: actions/checkout@v4.1.1 | |
| - name: Install PHP | |
| uses: shivammathur/setup-php@v2 # https://github.com/marketplace/actions/setup-php-action | |
| with: | |
| php-version: ${{ matrix.php-version }} | |
| extensions: iconv, intl, mysqli, oauth | |
| ini-values: error_reporting=-1, memory_limit=512M, post_max_size=256M, xdebug.mode="coverage,debug,develop" | |
| coverage: xdebug #optional | |
| - name: Check PHP Version | |
| run: | | |
| php -v | |
| php -r 'echo "curl version: " . curl_version()["version"] . "\n";' | |
| - name: Validate composer.json and composer.lock | |
| run: composer validate --strict | |
| - name: Cache composer packages | |
| uses: actions/cache@v4 | |
| id: composer-cache | |
| with: | |
| path: vendor | |
| key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-php- | |
| - name: Install dependencies | |
| run: | | |
| composer --version | |
| composer install --prefer-dist --no-progress | |
| - name: Unit test | |
| # This step runs tests for all PHP versions except where we're collecting coverage in the next step | |
| if: ${{ matrix.php-version != env.COVERAGE_VER || github.ref_name != 'master' }} | |
| run: composer run test | |
| - name: Run code coverage | |
| if: ${{ matrix.php-version == env.COVERAGE_VER && github.ref_name == 'master' }} | |
| run: | | |
| vendor/bin/phpunit --coverage-clover coverage/clover.xml | |
| php -f vendor/bdk/devutil/src/coverageChecker.php -- coverage/clover.xml | |
| - name: Publish code coverage | |
| if: ${{ matrix.php-version == env.COVERAGE_VER && github.ref_name == 'master' }} | |
| uses: qltysh/qlty-action/coverage@v1 | |
| with: | |
| files: coverage/clover.xml | |
| oidc: true |