-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
252 lines (216 loc) · 6.73 KB
/
Taskfile.yml
File metadata and controls
252 lines (216 loc) · 6.73 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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# yaml-language-server: $schema=https://taskfile.dev/schema.json
---
version: "3"
vars:
DOCKER_COMPOSE: "docker compose"
PHP: "{{.DOCKER_COMPOSE}} exec phpfpm"
COMPOSER: "{{.PHP}} composer"
tasks:
default:
silent: true
cmds:
- task --list
install:
desc: Install dependencies
cmds:
- task: composer:install
setup:
desc: Set up the project
cmds:
- task: up
- task: install
# Container management
up:
desc: Start docker containers
cmds:
- task: network:frontend
- "{{.DOCKER_COMPOSE}} up -d"
down:
desc: Stop docker containers
cmds:
- "{{.DOCKER_COMPOSE}} down"
restart:
desc: Restart docker containers
cmds:
- task: down
- task: up
network:frontend:
internal: true
desc: Create docker frontend network
cmds:
- docker network create frontend 2>/dev/null || true
# Composer
composer:
desc: Run arbitrary composer command
cmds:
- "{{.COMPOSER}} {{.CLI_ARGS}}"
composer:install:
desc: Install composer dependencies
cmds:
- "{{.COMPOSER}} install"
composer:update:
desc: Update composer dependencies
cmds:
- "{{.COMPOSER}} update"
composer:normalize:
desc: Normalize composer.json
cmds:
- "{{.COMPOSER}} normalize"
composer:check:
desc: Validate and audit composer
cmds:
- "{{.PHP}} composer validate --strict"
- "{{.COMPOSER}} normalize --dry-run"
- "{{.COMPOSER}} audit"
# Code quality
lint:
desc: Run all linters
cmds:
- task: lint:php
- task: lint:composer
- task: lint:markdown
- task: lint:yaml
lint:php:
desc: Check PHP coding standards
cmds:
- "{{.PHP}} vendor/bin/php-cs-fixer fix --dry-run --diff"
lint:php:fix:
desc: Fix PHP coding standards
cmds:
- "{{.PHP}} vendor/bin/php-cs-fixer fix"
lint:composer:
desc: Validate and audit composer
cmds:
- "{{.PHP}} composer validate --strict"
- "{{.COMPOSER}} normalize --dry-run"
- "{{.COMPOSER}} audit"
lint:markdown:
desc: Lint markdown files
cmds:
- "{{.DOCKER_COMPOSE}} run --rm markdownlint markdownlint '**/*.md'"
lint:markdown:fix:
desc: Fix markdown files
cmds:
- "{{.DOCKER_COMPOSE}} run --rm markdownlint markdownlint '**/*.md' --fix"
lint:yaml:
desc: Lint YAML files
cmds:
- "{{.DOCKER_COMPOSE}} run --rm prettier '**/*.{yml,yaml}' --check"
lint:yaml:fix:
desc: Fix YAML files
cmds:
- "{{.DOCKER_COMPOSE}} run --rm prettier '**/*.{yml,yaml}' --write"
# Analysis
analyze:php:
desc: Run PHPStan static analysis
cmds:
- "{{.PHP}} vendor/bin/phpstan"
# Testing
test:
desc: Run tests
cmds:
- "{{.PHP}} vendor/bin/phpunit"
test:coverage:
desc: Run tests with coverage
cmds:
- "{{.DOCKER_COMPOSE}} exec -e XDEBUG_MODE=coverage phpfpm vendor/bin/phpunit --coverage-text --coverage-clover=coverage/unit.xml"
test:run:
desc: "Run tests for a PHP version and dependency set (e.g. task test:run PHP=8.4 DEPS=lowest)"
vars:
PHP: '{{.PHP | default "8.3"}}'
DEPS: '{{.DEPS | default "stable"}}'
PREFER: "prefer-{{.DEPS}}"
SERVICE: 'phpfpm{{.PHP | replace "." ""}}-{{.DEPS}}'
cmds:
- cmd: |
trap 'stty sane 2>/dev/null || true' EXIT
set -e
echo "Testing PHP {{.PHP}} ({{.PREFER}})..."
{{.DOCKER_COMPOSE}} run --rm -T --user root {{.SERVICE}} chown -R deploy:deploy /app/vendor /home/deploy/.composer
{{.DOCKER_COMPOSE}} run --rm -T -e XDEBUG_MODE=coverage {{.SERVICE}} sh -c '
if [ -f /app/vendor/.composer.lock ]; then
cp /app/vendor/.composer.lock /app/composer.lock
composer install -q
else
rm -f /app/composer.lock
composer update -q --{{.PREFER}}
cp /app/composer.lock /app/vendor/.composer.lock
fi'
{{.DOCKER_COMPOSE}} run --rm -T -e XDEBUG_MODE=coverage {{.SERVICE}} vendor/bin/phpunit --coverage-clover=coverage/unit.xml
test:matrix:reset:
desc: Remove cached vendor volumes to force a fresh dependency resolve
cmds:
- "{{.DOCKER_COMPOSE}} --profile ci down --volumes"
test:matrix:
desc: Run tests across all PHP versions (mirrors CI matrix)
vars:
RESULTS_FILE:
sh: mktemp
cmds:
- task: test:matrix:run
vars: { PHP: "8.3", DEPS: lowest, RESULTS_FILE: "{{.RESULTS_FILE}}" }
- task: test:matrix:run
vars: { PHP: "8.3", DEPS: stable, RESULTS_FILE: "{{.RESULTS_FILE}}" }
- task: test:matrix:run
vars: { PHP: "8.4", DEPS: lowest, RESULTS_FILE: "{{.RESULTS_FILE}}" }
- task: test:matrix:run
vars: { PHP: "8.4", DEPS: stable, RESULTS_FILE: "{{.RESULTS_FILE}}" }
- task: test:matrix:run
vars: { PHP: "8.5", DEPS: lowest, RESULTS_FILE: "{{.RESULTS_FILE}}" }
- task: test:matrix:run
vars: { PHP: "8.5", DEPS: stable, RESULTS_FILE: "{{.RESULTS_FILE}}" }
- task: test:summary
vars: { RESULTS_FILE: "{{.RESULTS_FILE}}" }
test:matrix:run:
internal: true
desc: Run a single matrix combination and record the result
vars:
PREFER: "prefer-{{.DEPS}}"
cmds:
- cmd: |
if task test:run PHP={{.PHP}} DEPS={{.DEPS}}; then
echo "PASS PHP {{.PHP}} ({{.PREFER}})" >> "{{.RESULTS_FILE}}"
else
echo "FAIL PHP {{.PHP}} ({{.PREFER}})" >> "{{.RESULTS_FILE}}"
fi
ignore_error: true
test:summary:
internal: true
silent: true
desc: Print test matrix summary
cmds:
- cmd: |
echo ""
echo "=============================="
echo " Test Matrix Summary"
echo "=============================="
while IFS= read -r line; do
if [[ "$line" == PASS* ]]; then
echo " OK ${line#PASS }"
elif [[ "$line" == FAIL* ]]; then
echo " FAIL ${line#FAIL }"
fi
done < "{{.RESULTS_FILE}}"
echo "=============================="
if grep -q "^FAIL" "{{.RESULTS_FILE}}"; then
echo ""
echo " Failed combinations:"
grep "^FAIL" "{{.RESULTS_FILE}}" | while IFS= read -r line; do
echo " - ${line#FAIL }"
done
echo ""
rm -f "{{.RESULTS_FILE}}"
exit 1
else
echo " All tests PASSED"
echo "=============================="
rm -f "{{.RESULTS_FILE}}"
fi
# CI
pr:actions:
desc: Run all CI checks locally
cmds:
- task: composer:check
- task: lint
- task: analyze:php
- task: test:matrix