generated from creasico/laravel-package
-
-
Notifications
You must be signed in to change notification settings - Fork 3
197 lines (171 loc) · 5.81 KB
/
test.yml
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: Tests
on:
pull_request:
branches: [main]
push:
branches: [main]
# paths: ['.github/**.yml', 'src/*', 'tests/*']
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
CC_TEST_REPORTER_URL: ${{ vars.CC_TEST_REPORTER_URL }}
DB_USERNAME: ${{ github.repository_owner }}
DB_PASSWORD: secret
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
configs:
name: Configure
uses: creasico/laravel-package/.github/workflows/configure.yml@main
secrets: inherit
permissions:
contents: read
pull-requests: write
prepare:
name: Prepare Database
runs-on: ubuntu-latest
needs: configs
env:
DB_NUSA: nusantara
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: ${{ env.DB_PASSWORD }}
MYSQL_DATABASE: ${{ env.DB_NUSA }}
MYSQL_USER: ${{ env.DB_USERNAME }}
MYSQL_PASSWORD: ${{ env.DB_PASSWORD }}
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: xdebug
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ needs.configs.outputs.composer-cache }}
key: php-8.1-10.x-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: php-8.1-10.x--composer-
- name: Install dependencies
run: composer update --prefer-dist --no-interaction --no-progress
- name: Import databases
run: composer db:import
tests:
name: Test on PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }} DB ${{ matrix.db }}
needs: [configs, prepare]
runs-on: ubuntu-latest
outputs:
has-reports: ${{ steps.reports.outputs.has-reports }}
env:
DB_CONNECTION: ${{ matrix.db }}
DB_DATABASE: ${{ github.repository_owner }}
services:
postgresql:
image: postgres:14
env:
POSTGRES_DB: ${{ env.DB_DATABASE }}
POSTGRES_USER: ${{ env.DB_USERNAME }}
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
ports:
- 5432:5432
options: >-
--health-cmd=pg_isready
--health-interval=10s
--health-timeout=5s
--health-retries=3
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: ${{ env.DB_PASSWORD }}
MYSQL_DATABASE: ${{ env.DB_DATABASE }}
MYSQL_USER: ${{ env.DB_USERNAME }}
MYSQL_PASSWORD: ${{ env.DB_PASSWORD }}
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
strategy:
fail-fast: false
matrix:
db: ['mysql', 'pgsql', 'sqlite']
laravel: ['10.x', '11.x']
php: ['8.1', '8.2', '8.3']
exclude:
- php: '8.1'
laravel: '11.x'
- php: '8.3'
laravel: '9.x'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: xdebug
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ needs.configs.outputs.composer-cache }}
key: php-${{ matrix.php }}-${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: php-${{ matrix.php }}-${{ matrix.laravel }}-composer-
- name: Install dependencies
run: |
composer require "laravel/framework=${{ matrix.laravel }}" --no-update
composer update --prefer-dist --no-interaction --no-progress
- name: Run tests
run: composer test -- --coverage
- name: Generate reports for CodeClimate
id: reports
if: ${{ matrix.db == 'pgsql' && ( github.actor != 'dependabot[bot]' || needs.configs.outputs.should-reports == '1' ) }}
env:
COVERAGE_FILE: tests/reports/clover.xml
CODECLIMATE_REPORT: tests/reports/codeclimate.${{ matrix.php }}-L${{ matrix.laravel }}.json
run: |
if [[ -n \"$CC_TEST_REPORTER_URL\" ]]; then
curl -LSs $CC_TEST_REPORTER_URL > ./cc-test-reporter && chmod +x ./cc-test-reporter
./cc-test-reporter format-coverage -t clover -o $CODECLIMATE_REPORT $COVERAGE_FILE
echo "has-reports=1" >> $GITHUB_OUTPUT
fi
- name: Upload tests reports
uses: actions/upload-artifact@v4
if: ${{ steps.reports.outputs.has-reports == '1' }}
with:
name: cc-reports-${{ matrix.php }}-L${{ matrix.laravel }}
path: tests/reports/codeclimate.${{ matrix.php }}-L${{ matrix.laravel }}.json
reports:
name: Report Test Coverages
if: ${{ github.actor != 'dependabot[bot]' && needs.tests.outputs.has-reports == '1' }}
runs-on: ubuntu-latest
needs: tests
steps:
- name: Download test reports
uses: actions/download-artifact@v4
with:
pattern: cc-reports-*
merge-multiple: true
- name: Report to CodeClimate
run: |
curl -LSs $CC_TEST_REPORTER_URL > ./cc-test-reporter && chmod +x ./cc-test-reporter
./cc-test-reporter sum-coverage -o - codeclimate.*.json | ./cc-test-reporter upload-coverage --input -