-
-
Notifications
You must be signed in to change notification settings - Fork 45
137 lines (121 loc) · 4.94 KB
/
Copy pathrun-tests.yml
File metadata and controls
137 lines (121 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Run tests
on:
pull_request_target:
types: [ opened, synchronize, labeled ]
schedule:
- cron: '0 0 * * *'
jobs:
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."
}
load-matrix:
runs-on: ubuntu-latest
needs: access_check
outputs:
db: ${{ steps.load.outputs.db }}
payload: ${{ steps.load.outputs.payload }}
steps:
- name: Checkout PR code to read matrix.json
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Load matrix
id: load
run: |
echo "db=$(jq -c '.db' matrix.json)" >> $GITHUB_OUTPUT
echo "payload=$(jq -c '.payload' matrix.json)" >> $GITHUB_OUTPUT
php-tests:
runs-on: ubuntu-latest
needs: load-matrix
strategy:
matrix:
db: ${{ fromJson(needs.load-matrix.outputs.db) }}
payload: ${{ fromJson(needs.load-matrix.outputs.payload) }}
name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} - DB ${{ matrix.db.driver }} ${{ matrix.db.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.payload.php }}
extensions: mbstring, dom, fileinfo
coverage: none
- name: Set up MySQL and PostgreSQL
env:
CI_SERVICE_ACCOUNT_JSON_KEY: ${{ secrets.CI_SERVICE_ACCOUNT_JSON_KEY }}
run: |
touch .env
if [ "${{ matrix.db.driver }}" = "mysql" ]; then
MYSQL_PORT=3307 MYSQL_VERSION=${{ matrix.db.version }} docker compose up ${{ matrix.db.driver }} -d
elif [ "${{ matrix.db.driver }}" = "pgsql" ]; then
POSTGRES_PORT=5432 PGSQL_VERSION=${{ matrix.db.version }} docker compose up ${{ matrix.db.driver }} -d
fi
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" --no-interaction --no-update
composer update --prefer-stable --prefer-dist --no-interaction
if [ "${{ matrix.db.driver }}" = "mysql" ]; then
while ! mysqladmin ping --host=127.0.0.1 --user=cloudtasks --port=3307 --password=cloudtasks --silent; do
echo "Waiting for MySQL..."
sleep 1
done
else
echo "Not waiting for MySQL."
fi
- name: Execute tests
env:
DB_DRIVER: ${{ matrix.db.driver }}
DB_HOST: 127.0.0.1
CI_CLOUD_TASKS_PROJECT_ID: ${{ secrets.CI_CLOUD_TASKS_PROJECT_ID }}
CI_CLOUD_TASKS_QUEUE: ${{ matrix.payload.queue }}-${{ matrix.db.driver }}
CI_CLOUD_TASKS_LOCATION: ${{ secrets.CI_CLOUD_TASKS_LOCATION }}
CI_CLOUD_TASKS_SERVICE_ACCOUNT_EMAIL: ${{ secrets.CI_CLOUD_TASKS_SERVICE_ACCOUNT_EMAIL }}
CI_SERVICE_ACCOUNT_JSON_KEY: ${{ secrets.CI_SERVICE_ACCOUNT_JSON_KEY }}
CI_CLOUD_TASKS_CUSTOM_QUEUE: ${{ matrix.payload.queue }}-${{ matrix.db.driver }}
run: |
echo $CI_SERVICE_ACCOUNT_JSON_KEY > tests/Support/gcloud-key-valid.json
touch .env
vendor/bin/phpunit