This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
233 lines (200 loc) · 7.08 KB
/
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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
name: tests
on:
push:
branches: [master, main]
tags-ignore: ['**']
paths-ignore: ['**.md']
pull_request:
paths-ignore: ['**.md']
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs: # Docs: <https://help.github.com/en/articles/workflow-syntax-for-github-actions>
gitleaks:
name: GitLeaks
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: actions/checkout@v3
with: {fetch-depth: 0}
- name: Check for GitLeaks
uses: gacts/gitleaks@v1 # Action page: <https://github.com/gacts/gitleaks>
phpunit:
name: Run PHPUnit tests
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 # Action page: <https://github.com/shivammathur/setup-php>
with:
php-version: '8.2'
- name: Get Composer Cache Directory # Docs: <https://git.io/JfAKn#php---composer>
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies # Docs: <https://git.io/JfAKn#php---composer>
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.setup }}-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer update -n --prefer-dist --no-progress --ansi && composer info
- name: Run PHPUnit
run: composer phpunit
phpstan:
name: Run PHPStan (Static Analysis Tool)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.setup }}-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer update -n --prefer-dist --no-progress --ansi && composer info
- name: Run PHPStan
run: composer phpstan
docker-image:
name: Build docker image
runs-on: ubuntu-latest
needs: [phpunit, phpstan]
timeout-minutes: 10
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Build image
run: docker build -t app:local -f ./Dockerfile .
- name: Show PHP and Laravel versions, installed in docker image
run: docker run --rm app:local sh -c "php -v && php artisan -V"
- name: Save docker image
run: docker save app:local > ./docker-image.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: docker-image
path: ./docker-image.tar
retention-days: 1
#docker-image-scan:
# name: Scan docker image for vulnerabilities
# runs-on: ubuntu-latest
# needs: [docker-image]
# continue-on-error: true
# steps:
# - name: Download built docker image
# uses: actions/download-artifact@v3
# with:
# name: docker-image
# path: .artifact
#
# - name: Prepare image to run
# working-directory: .artifact
# run: docker load < docker-image.tar
#
# - name: Scan image
# uses: anchore/scan-action@v3 # action page: <https://github.com/anchore/scan-action>
# with:
# image: app:local
# #severity-cutoff: medium # negligible, low, medium, high or critical
docker-image-e2e:
name: Docker image End-to-End tests (SSL ${{ matrix.ssl }})
runs-on: ubuntu-latest
needs: [docker-image]
strategy:
fail-fast: false
matrix:
ssl: [on, off]
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Create docker network
run: docker network create "app-network"
- name: Start postgres server
run: |
docker run --rm -d \
--network "app-network" \
--name=postgres \
-p "5432/tcp" \
-e "POSTGRES_DB=forge" \
-e "POSTGRES_USER=forge" \
-e "POSTGRES_PASSWORD=forge" \
postgres:15-alpine
- name: Start redis server
run: |
docker run --rm -d \
--network "app-network" \
--name=redis \
-p "6379/tcp" \
redis:7-alpine \
redis-server --requirepass redis_password
- name: Download built docker image
uses: actions/download-artifact@v3
with:
name: docker-image
path: .artifact
- name: Prepare image to run
working-directory: .artifact
run: docker load < docker-image.tar
- name: Migrate the database
run: |
docker run --rm \
--network "app-network" \
-e "DB_HOST=postgres" \
-e "DB_DATABASE=forge" \
-e "DB_USERNAME=forge" \
-e "DB_PASSWORD=forge" \
app:local \
php artisan migrate --force
- name: Start application queue worker
run: |
docker run --rm -d \
--network "app-network" \
-e "REDIS_HOST=redis" \
-e "REDIS_PASSWORD=redis_password" \
-e "DB_HOST=postgres" \
-e "DB_DATABASE=forge" \
-e "DB_USERNAME=forge" \
-e "DB_PASSWORD=forge" \
app:local \
php artisan queue:work --memory=256 --sleep=1
- name: Start application HTTP server
run: |
docker run --rm -d \
--network "app-network" \
-p "8080:8080/tcp" \
-p "8443:8443/tcp" \
-e "REDIS_HOST=redis" \
-e "REDIS_PASSWORD=redis_password" \
-e "DB_HOST=postgres" \
-e "DB_DATABASE=forge" \
-e "DB_USERNAME=forge" \
-e "DB_PASSWORD=forge" \
app:local \
rr serve -c .rr.yaml
- name: Generate values for tests running
id: values
run: echo "::set-output name=base_url::`[ "${{ matrix.ssl }}" = "on" ] && echo "https://localhost:8443" || echo "http://localhost:8080"`"
# Image page: <https://hub.docker.com/r/postman/newman>,
# CLI options: <https://www.npmjs.com/package/newman#command-line-options>
- name: Run Newman
run: |
docker run --rm --tty \
--net host \
--volume "$(pwd):/rootfs:ro" \
--workdir "/rootfs/tests/postman" \
postman/newman:5.2-alpine run ./default.postman_collection.json \
--env-var "base_url=${{ steps.values.outputs.base_url }}" \
--insecure \
--color on