Skip to content

Commit 0caa189

Browse files
Merge pull request #59 from stackkit/7.x
7.x
2 parents 20755ce + af45f98 commit 0caa189

File tree

2 files changed

+88
-60
lines changed

2 files changed

+88
-60
lines changed

.github/workflows/run-tests.yml

+80-40
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,81 @@ name: Run tests
22

33
on:
44
pull_request_target:
5+
types: [opened, synchronize, labeled]
56
schedule:
67
- cron: '0 0 * * *'
78

89
jobs:
9-
php-tests:
10-
runs-on: ${{ matrix.os }}
10+
access_check:
11+
runs-on: ubuntu-latest
12+
name: Access check
13+
steps:
14+
- name: Ensure pull-request is safe to run
15+
uses: actions/github-script@v7
16+
with:
17+
github-token: ${{secrets.GITHUB_TOKEN}}
18+
script: |
19+
if (context.eventName === 'schedule') {
20+
return
21+
}
22+
23+
// If the user that pushed the commit is a maintainer, skip the check
24+
const collaborators = await github.rest.repos.listCollaborators({
25+
owner: context.repo.owner,
26+
repo: context.repo.repo
27+
});
28+
29+
if (collaborators.data.some(c => c.login === context.actor)) {
30+
console.log(`User ${context.actor} is allowed to run tests because they are a collaborator.`);
31+
return
32+
}
33+
34+
const issue_number = context.issue.number;
35+
const repository = context.repo.repo;
36+
const owner = context.repo.owner;
37+
38+
const response = await github.rest.issues.listLabelsOnIssue({
39+
owner,
40+
repo: repository,
41+
issue_number
42+
});
43+
const labels = response.data.map(label => label.name);
44+
let hasLabel = labels.includes('safe-to-test')
45+
46+
if (context.payload.action === 'synchronize' && hasLabel) {
47+
hasLabel = false
48+
await github.rest.issues.removeLabel({
49+
owner,
50+
repo: repository,
51+
issue_number,
52+
name: 'safe-to-test'
53+
});
54+
}
55+
56+
if (!hasLabel) {
57+
throw "Action was not authorized. Exiting now."
58+
}
1159
60+
php-tests:
61+
runs-on: ubuntu-latest
62+
needs: access_check
1263
strategy:
1364
matrix:
14-
os: [ubuntu-latest]
65+
db: [ 'mysql', 'sqlite', 'pgsql' ]
1566
payload:
16-
- { laravel: '10.*', php: '8.3', 'testbench': '8.*'}
17-
- { laravel: '10.*', php: '8.2', 'testbench': '8.*'}
18-
- { laravel: '10.*', php: '8.1', 'testbench': '8.*'}
19-
- { laravel: '9.*', php: '8.3', 'testbench': '7.*'}
20-
- { laravel: '9.*', php: '8.2', 'testbench': '7.*'}
21-
- { laravel: '9.*', php: '8.1', 'testbench': '7.*'}
22-
- { laravel: '9.*', php: '8.0', 'testbench': '7.*'}
23-
- { laravel: '8.*', php: '8.1', 'testbench': '6.*'}
24-
- { laravel: '8.*', php: '8.0', 'testbench': '6.*'}
25-
- { laravel: '8.*', php: '7.4', 'testbench': '6.*'}
26-
- { laravel: '7.*', php: '8.0', 'testbench': '5.*' }
27-
- { laravel: '7.*', php: '7.4', 'testbench': '5.*' }
28-
- { laravel: '6.*', php: '8.0', 'testbench': '4.*' }
29-
- { laravel: '6.*', php: '7.4', 'testbench': '4.*' }
67+
- { laravel: '11.*', php: '8.3', 'testbench': '9.*', collision: '8.*' }
68+
- { laravel: '11.*', php: '8.2', 'testbench': '9.*', collision: '8.*' }
69+
- { laravel: '10.*', php: '8.3', 'testbench': '8.*', collision: '7.*' }
70+
- { laravel: '10.*', php: '8.2', 'testbench': '8.*', collision: '7.*' }
71+
- { laravel: '10.*', php: '8.1', 'testbench': '8.*', collision: '7.*' }
3072

31-
name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }}
32-
33-
services:
34-
mysql:
35-
image: mysql:5.7.27
36-
env:
37-
MYSQL_USER: root
38-
MYSQL_ROOT_PASSWORD: root
39-
MYSQL_PASSWORD:
40-
MYSQL_ALLOW_EMPTY_PASSWORD: true
41-
MYSQL_DATABASE: test
42-
ports:
43-
- 3307:3306
44-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
73+
name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} - DB ${{ matrix.db }}
4574

4675
steps:
4776
- name: Checkout code
48-
uses: actions/checkout@v3
77+
uses: actions/checkout@v4
78+
with:
79+
ref: ${{ github.event.pull_request.head.sha }}
4980

5081
- name: Setup PHP
5182
uses: shivammathur/setup-php@v2
@@ -54,16 +85,25 @@ jobs:
5485
extensions: mbstring, dom, fileinfo, mysql
5586
coverage: none
5687

88+
- name: Set up MySQL and PostgreSQL
89+
run: |
90+
if [ "${{ matrix.db }}" != "sqlite" ]; then
91+
MYSQL_PORT=3307 POSTGRES_PORT=5432 docker compose up ${{ matrix.db }} -d
92+
fi
93+
5794
- name: Install dependencies
5895
run: |
59-
composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" --no-interaction --no-update
96+
composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" "nunomaduro/collision:${{ matrix.payload.collision }}" --no-interaction --no-update
6097
composer update --prefer-stable --prefer-dist --no-interaction
98+
if [ "${{ matrix.db }}" = "mysql" ]; then
99+
while ! mysqladmin ping --host=127.0.0.1 --user=test --port=3307 --password=test --silent; do
100+
echo "Waiting for MySQL..."
101+
sleep 1
102+
done
103+
else
104+
echo "Not waiting for MySQL."
105+
fi
61106
- name: Execute tests
62107
env:
63-
CI_DB_DRIVER: mysql
64-
CI_DB_HOST: 127.0.0.1
65-
CI_DB_PORT: 3307
66-
CI_DB_DATABASE: test
67-
CI_DB_USERNAME: root
68-
CI_DB_PASSWORD: root
69-
run: vendor/bin/phpunit
108+
DB_DRIVER: ${{ matrix.db }}
109+
run: composer test

composer.json

+8-20
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,22 @@
2626
}
2727
},
2828
"require": {
29-
"ext-json": "*"
29+
"ext-json": "*",
30+
"laravel/framework": "^10.0|^11.0"
3031
},
3132
"require-dev": {
3233
"mockery/mockery": "^1.2",
33-
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0"
34+
"orchestra/testbench": "^8.0|^9.0",
35+
"laravel/pint": "^1.14"
3436
},
3537
"minimum-stability": "dev",
3638
"prefer-stable": true,
3739
"scripts": {
38-
"l10": [
39-
"composer require laravel/framework:10.* orchestra/testbench:8.* --no-interaction --no-update",
40-
"composer update --prefer-stable --prefer-dist --no-interaction"
41-
],
42-
"l9": [
43-
"composer require laravel/framework:9.* orchestra/testbench:7.* --no-interaction --no-update",
44-
"composer update --prefer-stable --prefer-dist --no-interaction"
45-
],
46-
"l8": [
47-
"composer require laravel/framework:8.* orchestra/testbench:6.* --no-interaction --no-update",
48-
"composer update --prefer-stable --prefer-dist --no-interaction"
40+
"l11": [
41+
"composer update laravel/framework:11.* orchestra/testbench:9.* --with-all-dependencies"
4942
],
50-
"l7": [
51-
"composer require laravel/framework:8.* orchestra/testbench:6.* --no-interaction --no-update",
52-
"composer update --prefer-stable --prefer-dist --no-interaction"
53-
],
54-
"l6": [
55-
"composer require laravel/framework:8.* orchestra/testbench:6.* --no-interaction --no-update",
56-
"composer update --prefer-stable --prefer-dist --no-interaction"
43+
"l10": [
44+
"composer update laravel/framework:10.* orchestra/testbench:8.* --with-all-dependencies"
5745
],
5846
"test": [
5947
"CI_DB_DRIVER=sqlite CI_DB_DATABASE=:memory: phpunit"

0 commit comments

Comments
 (0)