@@ -2,22 +2,72 @@ 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]
15
65
payload :
16
66
- { laravel: '11.*', php: '8.3', 'testbench': '9.*' }
17
67
- { laravel: '11.*', php: '8.2', 'testbench': '9.*' }
18
- - { laravel: '10.*', php: '8.3', 'testbench': '8.*'}
19
- - { laravel: '10.*', php: '8.2', 'testbench': '8.*'}
20
- - { laravel: '10.*', php: '8.1', 'testbench': '8.*'}
68
+ - { laravel: '10.*', php: '8.3', 'testbench': '8.*' }
69
+ - { laravel: '10.*', php: '8.2', 'testbench': '8.*' }
70
+ - { laravel: '10.*', php: '8.1', 'testbench': '8.*' }
21
71
22
72
name : PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }}
23
73
36
86
37
87
steps :
38
88
- name : Checkout code
39
- uses : actions/checkout@v3
89
+ uses : actions/checkout@v4
90
+ with :
91
+ ref : ${{ github.event.pull_request.head.sha }}
40
92
41
93
- name : Setup PHP
42
94
uses : shivammathur/setup-php@v2
@@ -50,11 +102,4 @@ jobs:
50
102
composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" --no-interaction --no-update
51
103
composer update --prefer-stable --prefer-dist --no-interaction
52
104
- name : Execute tests
53
- env :
54
- CI_DB_DRIVER : mysql
55
- CI_DB_HOST : 127.0.0.1
56
- CI_DB_PORT : 3307
57
- CI_DB_DATABASE : test
58
- CI_DB_USERNAME : root
59
- CI_DB_PASSWORD : root
60
105
run : composer test
0 commit comments