-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (145 loc) · 4.26 KB
/
run-tests.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
name: Run Tests
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: zip pcntl mysqli pdo_mysql bcmath soap intl gd exif imagick redis
coverage: xdebug
- name: Run composer install
run: composer install -n --prefer-dist
- name: Prepare Laravel Application
run: |
php artisan key:generate
php artisan typescript:transform
- name: Upload application
uses: actions/upload-artifact@v4
with:
name: app_files
path: .
run-tests:
runs-on: ubuntu-latest
needs: setup
services:
mysql:
image: mysql:8.4
env:
MYSQL_DATABASE: hms
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
steps:
- name: Download application
uses: actions/download-artifact@v4
with:
name: app_files
- name: Execute tests
uses: php-actions/composer@v6
env:
DB_PORT: 3306
DB_CONNECTION: mysql
DB_HOST: 127.0.0.1
DB_DATABASE: hms
DB_USERNAME: root
DB_PASSWORD: root
XDEBUG_MODE: coverage
APP_KEY: ${{ secrets.TESTING_APP_KEY }}
with:
php_version: "8.3"
command: test
php_extensions: zip pcntl mysqli pdo_mysql bcmath soap intl gd exif imagick redis xdebug
- name: Upload application
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage/all/cobertura.xml
check-coverage:
runs-on: ubuntu-latest
needs: run-tests
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
fetch-depth: 0
- run: git fetch
- name: Download coverage
uses: actions/download-artifact@v4
with:
name: coverage
- uses: actions/setup-python@v5
with:
python-version: '3.9'
cache: 'pip' # caching pip dependencies
- run: pip install diff_cover
- run: diff-cover cobertura.xml --markdown-report coverage.md --fail-under 80 --compare-branch origin/main
- name: Upload report
uses: actions/upload-artifact@v4
with:
name: coverage_report
path: coverage.md
comment-coverage:
runs-on: ubuntu-latest
needs: check-coverage
if: ${{ github.event.pull_request.number }}
steps:
- name: Download report
uses: actions/download-artifact@v4
with:
name: coverage_report
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Diff Coverage
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: coverage.md
edit-mode: replace
cleanup-artifacts-pr:
runs-on: ubuntu-latest
if: github.event.pull_request.number != null
needs: [setup, run-tests, check-coverage, comment-coverage]
steps:
- uses: geekyeggo/delete-artifact@v5
with:
name: |
app_files
coverage
coverage_report
cleanup-artifacts-branch:
runs-on: ubuntu-latest
if: github.event.pull_request.number == null
needs: [setup, run-tests, check-coverage]
steps:
- uses: geekyeggo/delete-artifact@v5
with:
name: |
app_files
coverage
coverage_report