Skip to content

7.x #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 23, 2024
Merged

7.x #59

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 80 additions & 40 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
28 changes: 8 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down