@@ -2,50 +2,81 @@ name: Run tests
2
2
3
3
on :
4
4
pull_request_target :
5
+ types : [opened, synchronize, labeled]
5
6
schedule :
6
7
- cron : ' 0 0 * * *'
7
8
8
9
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
+ }
11
59
60
+ php-tests :
61
+ runs-on : ubuntu-latest
62
+ needs : access_check
12
63
strategy :
13
64
matrix :
14
- os : [ubuntu-latest ]
65
+ db : [ 'mysql', 'sqlite', 'pgsql' ]
15
66
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.*' }
30
72
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 }}
45
74
46
75
steps :
47
76
- name : Checkout code
48
- uses : actions/checkout@v3
77
+ uses : actions/checkout@v4
78
+ with :
79
+ ref : ${{ github.event.pull_request.head.sha }}
49
80
50
81
- name : Setup PHP
51
82
uses : shivammathur/setup-php@v2
@@ -54,16 +85,25 @@ jobs:
54
85
extensions : mbstring, dom, fileinfo, mysql
55
86
coverage : none
56
87
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
+
57
94
- name : Install dependencies
58
95
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
60
97
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
61
106
- name : Execute tests
62
107
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
0 commit comments