From b56cedd350492024397ebe06c2fabc5bdc91c913 Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Sat, 16 Mar 2024 13:41:14 +0100 Subject: [PATCH 1/6] Prepare run-test workflow --- .github/workflows/run-tests.yml | 17 ++++------------- composer.json | 28 ++++++++-------------------- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e389c1d..e6bb5db 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,26 +13,17 @@ jobs: matrix: os: [ubuntu-latest] payload: + - { laravel: '11.*', php: '8.3', 'testbench': '9.*' } + - { laravel: '11.*', php: '8.2', 'testbench': '9.*' } - { 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.*' } name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} services: mysql: - image: mysql:5.7.27 + image: mysql:8 env: MYSQL_USER: root MYSQL_ROOT_PASSWORD: root @@ -66,4 +57,4 @@ jobs: CI_DB_DATABASE: test CI_DB_USERNAME: root CI_DB_PASSWORD: root - run: vendor/bin/phpunit + 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" From 5e5bf3be09e7d20a90ae7f66a434f23c81f3033d Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Sat, 16 Mar 2024 13:56:38 +0100 Subject: [PATCH 2/6] Modernize run-test workflow --- .github/workflows/run-tests.yml | 73 ++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e6bb5db..22a5b6b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,22 +2,72 @@ 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] payload: - { laravel: '11.*', php: '8.3', 'testbench': '9.*' } - { laravel: '11.*', php: '8.2', 'testbench': '9.*' } - - { laravel: '10.*', php: '8.3', 'testbench': '8.*'} - - { laravel: '10.*', php: '8.2', 'testbench': '8.*'} - - { laravel: '10.*', php: '8.1', 'testbench': '8.*'} + - { laravel: '10.*', php: '8.3', 'testbench': '8.*' } + - { laravel: '10.*', php: '8.2', 'testbench': '8.*' } + - { laravel: '10.*', php: '8.1', 'testbench': '8.*' } name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} @@ -36,7 +86,9 @@ jobs: 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 @@ -50,11 +102,4 @@ jobs: composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" --no-interaction --no-update composer update --prefer-stable --prefer-dist --no-interaction - 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: composer test From 95141c84473e72108f560c07ee8ed233fec82a20 Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Sat, 16 Mar 2024 14:51:11 +0100 Subject: [PATCH 3/6] wip --- .github/workflows/run-tests.yml | 35 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 22a5b6b..39e170d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -62,23 +62,22 @@ jobs: needs: access_check strategy: matrix: + db: [ 'mysql', 'sqlite' ] payload: - - { laravel: '11.*', php: '8.3', 'testbench': '9.*' } - - { laravel: '11.*', php: '8.2', 'testbench': '9.*' } - - { laravel: '10.*', php: '8.3', 'testbench': '8.*' } - - { laravel: '10.*', php: '8.2', 'testbench': '8.*' } - - { laravel: '10.*', php: '8.1', 'testbench': '8.*' } + - { 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 }} + name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} - DB ${{ matrix.db }} services: mysql: image: mysql:8 env: - MYSQL_USER: root - MYSQL_ROOT_PASSWORD: root - MYSQL_PASSWORD: - MYSQL_ALLOW_EMPTY_PASSWORD: true + MYSQL_USER: test + MYSQL_PASSWORD: test MYSQL_DATABASE: test ports: - 3307:3306 @@ -97,9 +96,23 @@ jobs: extensions: mbstring, dom, fileinfo, mysql coverage: none + - name: Set up MySQL and PostgreSQL + run: | + MYSQL_PORT=3307 POSTGRES_PORT=5432 docker compose up ${{ matrix.db }} -d + - 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: + DB_DRIVER: ${{ matrix.db }} run: composer test From 4a57bcdd0aa13f4eb1717afd716d896dfb219722 Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Sat, 16 Mar 2024 14:53:56 +0100 Subject: [PATCH 4/6] rm service --- .github/workflows/run-tests.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 39e170d..063d5a9 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -72,17 +72,6 @@ jobs: name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} - DB ${{ matrix.db }} - services: - mysql: - image: mysql:8 - env: - MYSQL_USER: test - MYSQL_PASSWORD: test - MYSQL_DATABASE: test - ports: - - 3307:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - steps: - name: Checkout code uses: actions/checkout@v4 From 9a59cb153254bfad149ba166cc2bbbb78ca7819d Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Sat, 16 Mar 2024 14:56:52 +0100 Subject: [PATCH 5/6] dont start containers for sqlite --- .github/workflows/run-tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 063d5a9..184589d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -87,7 +87,9 @@ jobs: - name: Set up MySQL and PostgreSQL run: | - MYSQL_PORT=3307 POSTGRES_PORT=5432 docker compose up ${{ matrix.db }} -d + if [ "${{ matrix.db }}" != "sqlite" ]; then + MYSQL_PORT=3307 POSTGRES_PORT=5432 docker compose up ${{ matrix.db }} -d + fi - name: Install dependencies run: | From af45f98b5f999756d429b7ab2b99566e740c36ca Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Sat, 23 Mar 2024 01:05:21 +0100 Subject: [PATCH 6/6] Test package with PostgreSQL --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 184589d..6790273 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -62,7 +62,7 @@ jobs: needs: access_check strategy: matrix: - db: [ 'mysql', 'sqlite' ] + db: [ 'mysql', 'sqlite', 'pgsql' ] payload: - { laravel: '11.*', php: '8.3', 'testbench': '9.*', collision: '8.*' } - { laravel: '11.*', php: '8.2', 'testbench': '9.*', collision: '8.*' }