diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e389c1d..6790273 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,50 +2,81 @@ name: Run tests on: pull_request_target: + types: [opened, synchronize, labeled] schedule: - cron: '0 0 * * *' jobs: - php-tests: - runs-on: ${{ matrix.os }} + access_check: + runs-on: ubuntu-latest + name: Access check + steps: + - name: Ensure pull-request is safe to run + uses: actions/github-script@v7 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + if (context.eventName === 'schedule') { + return + } + + // If the user that pushed the commit is a maintainer, skip the check + const collaborators = await github.rest.repos.listCollaborators({ + owner: context.repo.owner, + repo: context.repo.repo + }); + + if (collaborators.data.some(c => c.login === context.actor)) { + console.log(`User ${context.actor} is allowed to run tests because they are a collaborator.`); + return + } + + const issue_number = context.issue.number; + const repository = context.repo.repo; + const owner = context.repo.owner; + + const response = await github.rest.issues.listLabelsOnIssue({ + owner, + repo: repository, + issue_number + }); + const labels = response.data.map(label => label.name); + let hasLabel = labels.includes('safe-to-test') + + if (context.payload.action === 'synchronize' && hasLabel) { + hasLabel = false + await github.rest.issues.removeLabel({ + owner, + repo: repository, + issue_number, + name: 'safe-to-test' + }); + } + + if (!hasLabel) { + throw "Action was not authorized. Exiting now." + } + php-tests: + runs-on: ubuntu-latest + needs: access_check strategy: matrix: - os: [ubuntu-latest] + db: [ 'mysql', 'sqlite', 'pgsql' ] payload: - - { laravel: '10.*', php: '8.3', 'testbench': '8.*'} - - { laravel: '10.*', php: '8.2', 'testbench': '8.*'} - - { laravel: '10.*', php: '8.1', 'testbench': '8.*'} - - { laravel: '9.*', php: '8.3', 'testbench': '7.*'} - - { laravel: '9.*', php: '8.2', 'testbench': '7.*'} - - { laravel: '9.*', php: '8.1', 'testbench': '7.*'} - - { laravel: '9.*', php: '8.0', 'testbench': '7.*'} - - { laravel: '8.*', php: '8.1', 'testbench': '6.*'} - - { laravel: '8.*', php: '8.0', 'testbench': '6.*'} - - { laravel: '8.*', php: '7.4', 'testbench': '6.*'} - - { laravel: '7.*', php: '8.0', 'testbench': '5.*' } - - { laravel: '7.*', php: '7.4', 'testbench': '5.*' } - - { laravel: '6.*', php: '8.0', 'testbench': '4.*' } - - { laravel: '6.*', php: '7.4', 'testbench': '4.*' } + - { laravel: '11.*', php: '8.3', 'testbench': '9.*', collision: '8.*' } + - { laravel: '11.*', php: '8.2', 'testbench': '9.*', collision: '8.*' } + - { laravel: '10.*', php: '8.3', 'testbench': '8.*', collision: '7.*' } + - { laravel: '10.*', php: '8.2', 'testbench': '8.*', collision: '7.*' } + - { laravel: '10.*', php: '8.1', 'testbench': '8.*', collision: '7.*' } - name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} - - services: - mysql: - image: mysql:5.7.27 - env: - MYSQL_USER: root - MYSQL_ROOT_PASSWORD: root - MYSQL_PASSWORD: - MYSQL_ALLOW_EMPTY_PASSWORD: true - MYSQL_DATABASE: test - ports: - - 3307:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} - DB ${{ matrix.db }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -54,16 +85,25 @@ jobs: extensions: mbstring, dom, fileinfo, mysql coverage: none + - name: Set up MySQL and PostgreSQL + run: | + if [ "${{ matrix.db }}" != "sqlite" ]; then + MYSQL_PORT=3307 POSTGRES_PORT=5432 docker compose up ${{ matrix.db }} -d + fi + - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" "nunomaduro/collision:${{ matrix.payload.collision }}" --no-interaction --no-update composer update --prefer-stable --prefer-dist --no-interaction + if [ "${{ matrix.db }}" = "mysql" ]; then + while ! mysqladmin ping --host=127.0.0.1 --user=test --port=3307 --password=test --silent; do + echo "Waiting for MySQL..." + sleep 1 + done + else + echo "Not waiting for MySQL." + fi - name: Execute tests env: - CI_DB_DRIVER: mysql - CI_DB_HOST: 127.0.0.1 - CI_DB_PORT: 3307 - CI_DB_DATABASE: test - CI_DB_USERNAME: root - CI_DB_PASSWORD: root - run: vendor/bin/phpunit + DB_DRIVER: ${{ matrix.db }} + run: composer test diff --git a/composer.json b/composer.json index 1219696..ed7846f 100644 --- a/composer.json +++ b/composer.json @@ -26,34 +26,22 @@ } }, "require": { - "ext-json": "*" + "ext-json": "*", + "laravel/framework": "^10.0|^11.0" }, "require-dev": { "mockery/mockery": "^1.2", - "orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0" + "orchestra/testbench": "^8.0|^9.0", + "laravel/pint": "^1.14" }, "minimum-stability": "dev", "prefer-stable": true, "scripts": { - "l10": [ - "composer require laravel/framework:10.* orchestra/testbench:8.* --no-interaction --no-update", - "composer update --prefer-stable --prefer-dist --no-interaction" - ], - "l9": [ - "composer require laravel/framework:9.* orchestra/testbench:7.* --no-interaction --no-update", - "composer update --prefer-stable --prefer-dist --no-interaction" - ], - "l8": [ - "composer require laravel/framework:8.* orchestra/testbench:6.* --no-interaction --no-update", - "composer update --prefer-stable --prefer-dist --no-interaction" + "l11": [ + "composer update laravel/framework:11.* orchestra/testbench:9.* --with-all-dependencies" ], - "l7": [ - "composer require laravel/framework:8.* orchestra/testbench:6.* --no-interaction --no-update", - "composer update --prefer-stable --prefer-dist --no-interaction" - ], - "l6": [ - "composer require laravel/framework:8.* orchestra/testbench:6.* --no-interaction --no-update", - "composer update --prefer-stable --prefer-dist --no-interaction" + "l10": [ + "composer update laravel/framework:10.* orchestra/testbench:8.* --with-all-dependencies" ], "test": [ "CI_DB_DRIVER=sqlite CI_DB_DATABASE=:memory: phpunit"