Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
274 lines (244 loc) · 8.93 KB
/
Copy pathTaskfile.yml
File metadata and controls
274 lines (244 loc) · 8.93 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# https://taskfile.dev
version: "3"
vars:
APP_FOLDER: "app"
TEST_FOLDER: "tests"
FEATURES_FOLDER: "features"
PORT_LOCAL_SERVER: 8888
CURRENT_E2E_TEST: "@CURRENT"
tasks:
build:
aliases:
- default
cmds:
- task: rollup:build
- task: minify-widget
rollup:build:
deps: [npm:install]
sources:
- "{{.APP_FOLDER}}/data/**/*.md"
- "{{.APP_FOLDER}}/index.md"
- "{{.APP_FOLDER}}/css/**/*.css"
- "{{.APP_FOLDER}}/js/**/*.mjs"
- "{{.APP_FOLDER}}/js/**/*.js"
- "{{.APP_FOLDER}}/index.html"
- "{{.APP_FOLDER}}/DEBUG" # On vérifie si ce fichier a changé (parce qu'on a lancé une nouvelle version pour le DEBUG), afin de pouvoir relancer le build pour la version PROD
- rollup.config.mjs
generates:
- "{{.APP_FOLDER}}/css/styles.min.css"
- "{{.APP_FOLDER}}/script.min.js"
- "{{.APP_FOLDER}}/script.min.js.map"
method: timestamp
cmds:
- cmd: npx rollup --config
- cmd: | # On supprime le fichier DEBUG si on build en version PROD
if [ -e "{{.APP_FOLDER}}/DEBUG" ]; then
rm "{{.APP_FOLDER}}/DEBUG"
fi
silent: true
npm:install:
sources:
- package.json
- package-lock.json
generates:
- node_modules/.package-lock.json
cmds:
- npm install
debug:
deps: [npm:install]
sources:
cmds:
- cmd: npx rollup --config --environment DEBUG
- cmd: touch "{{.APP_FOLDER}}/DEBUG" # On ajoute un fichier DEBUG pour indiquer qu'on n'est pas en mode prod (warning pour ne pas push le build de l'application)
silent: true
minify-widget:
sources:
- widget/widget.js
- widget/widget.min.js
generates:
- widget/widget.min.js
cmds:
- npx rollup widget/widget.js --file widget/widget.min.js --format iife --compact -p @rollup/plugin-terser
init-repo:
cmds:
- git remote add chatmd git@forge.apps.education.fr:chatMD/chatMD.forge.apps.education.fr.git
- git remote add apps git@forge.apps.education.fr:eyssette/chatMD.git
- git remote add drane git@forge.apps.education.fr:drane-lyon/chatmd.git
- git remote add github git@github.com:eyssette/chatMD.git
- git remote add gitlab git@gitlab.com:chatmd/chatmd.gitlab.io.git
- git remote add frama git@framagit.org:chatmd/chatmd.frama.io.git
push:
vars:
GIT_REPO_NAMES: [apps, drane, chatmd, github, gitlab, frama]
preconditions:
- test ! -f app/DEBUG
cmds:
- task: lint
- task: tests
- for: { var: GIT_REPO_NAMES }
cmd: git push {{.ITEM}} && git push {{.ITEM}} --tags
tag:
desc: "Crée un tag avec pour date du tag la date du commit (usage: task tag -- <commit> <tag>)"
cmds:
- |
bash -c '
set -- "{{.CLI_ARGS}}"
COMMIT=$1
TAG=$2
if [ -z "$COMMIT" ] || [ -z "$TAG" ]; then
echo "❌ Usage: task tag -- <commit> <tag>"
exit 1
fi
TAG_DATE=$(git show -s --format=%aD "$COMMIT")
echo "📌 Création du tag \"$TAG\" sur le commit $COMMIT (date: $TAG_DATE)"
GIT_COMMITTER_DATE="$TAG_DATE" git tag -a "$TAG" "$COMMIT" -m ""
'
silent: false
tests:
desc: Lance les tests unitaires et e2e, et vérifie la compatibilité ECMAScript
cmds:
- task: ecma
- task: tests:unit
# On lance la tâche tests:check-if-can-run-e2e et si il n'y a pas de code d'erreur, on lance la tâche tests:e2e.
# Sinon, on ne lance pas les tests e2e et on retourne un code de sortie 0 pour ne pas bloquer le processus de build.
# On demande à l'utilisateur s'il veut continuer malgré tout, et si il répond "y", on retourne un code de sortie 0 pour ne pas bloquer le processus de build, sinon on retourne un code de sortie 1 pour bloquer le processus de build.
- cmd: |
if task tests:check-if-can-run-e2e; then
task tests:e2e
else
read -p "❌ Les tests e2e ne peuvent pas être lancés. Voulez-vous continuer malgré tout ? (y/n) " CONTINUE
if [ "$CONTINUE" = "y" ]; then
echo "⚠️ Vous avez choisi de continuer malgré l'impossibilité de lancer les tests e2e."
exit 0
else
echo "❌ Arrêt du processus de build à cause de l'impossibilité de lancer les tests e2e."
exit 1
fi
fi
silent: true
tests:e2e:
desc: Lance les tests e2e avec CodeceptJS
aliases:
- tests:codeceptjs
sources:
- "{{.APP_FOLDER}}/css/**/*.css"
- "{{.APP_FOLDER}}/js/**/*.mjs"
- "{{.APP_FOLDER}}/js/**/*.js"
- "{{.APP_FOLDER}}/index.html"
- "{{.TEST_FOLDER}}/e2e/**/*.js"
- "{{.TEST_FOLDER}}/e2e/**/*.mjs"
- "{{.FEATURES_FOLDER}}/**/*.feature"
cmds:
- task: tests:check-if-can-run-e2e
# On vérifie avant qu'il n'y ait pas le terme "@CURRENT" dans les fichiers tests e2e
- cmd: |
bash -c '
set -e
if grep -R --line-number --exclude-dir=node_modules "{{.CURRENT_E2E_TEST}}" tests/e2e features; then
echo "❌ {{.CURRENT_E2E_TEST}} trouvé dans les tests e2e — supprimez-le avant de lancer les tests."
exit 1
fi
'
silent: true
- task: server:start
- defer: { task: server:stop }
- npx codeceptjs run --steps --grep '(?=.*)^(?!.*@WIP)'
tests:e2e:current:
desc: Lance les tests e2e pour le test courant (utile pour le développement des tests e2e)
cmds:
- task: tests:check-if-can-run-e2e
- task: server:start
- defer: { task: server:stop }
- npx codeceptjs run --steps --verbose --grep '(?=.*)^(?!.*@WIP)(?=.*{{.CURRENT_E2E_TEST}})'
tests:check-if-can-run-e2e:
desc: Vérifie si les tests e2e peuvent être lancés dans l'environnement actuel
silent: true
cmds:
- cmd: |
if ! npx playwright install; then
echo "❌ Impossible d'installer Playwright et ses dépendances. Les tests e2e ne peuvent pas être lancés."
exit 1
fi
silent: true
tests:unit:
aliases:
- tests:jasmine
sources:
- "{{.APP_FOLDER}}/js/**/*.mjs"
- "{{.TEST_FOLDER}}/unit/**/*.mjs"
cmds:
- npx jasmine --config='tests/unit/.config/jasmine.mjs'
tests:createSteps:
sources:
- tests/e2e/.config/generateStepsDefinitionsFromFeatures.js
- features/**/*.feature
- tests/e2e/step_definitions/**/*.js
cmds:
- node tests/e2e/.config/generateStepsDefinitionsFromFeatures.js
tests:widget:
cmds:
- node tests/test-widget.mjs
bump:
generates:
- VERSION
- package.json
- package-lock.json
cmds:
- task: lint
- task: tests
- cz bump
server:start:
cmds:
- node --env-file=.env server.js {{.PORT_LOCAL_SERVER}} & # On lance le serveur en arrière-plan
- until nc -z localhost {{.PORT_LOCAL_SERVER}}; do sleep 1; done # On attend que le port soit ouvert avant de lancer la suite
server:stop:
cmds:
- bash -c 'kill $(lsof -ti :{{.PORT_LOCAL_SERVER}}) 2>/dev/null' || true
ecma:
sources:
- "{{.APP_FOLDER}}/js/**/*.mjs"
cmds:
- npx es-check es2018 "{{.APP_FOLDER}}/js/**/*.mjs" --module
format:
desc: Formate les fichiers .mjs avec Oxfmt
cmds:
- npx oxfmt --config .oxfmtrc.json . --ignore-path .oxfmtignore
format:check:
desc: Vérifie le format des fichiers avec Oxfmt
cmds:
- npx oxfmt --config .oxfmtrc.json --check . --ignore-path .oxfmtignore
format:check:staged:
desc: Vérifie le format des fichiers staged avec Oxfmt (pour le hook pre-commit)
silent: true
cmds:
- |
FILES=$(git diff --cached --name-only --diff-filter=ACM)
if [ -z "$FILES" ]; then
exit 0
fi
npx oxfmt --config .oxfmtrc.json --check $FILES --no-error-on-unmatched-pattern --ignore-path .oxfmtignore
lint:
desc: Lint les fichiers .mjs avec Oxlint, en affichant uniquement les erreurs principales
silent: true
cmds:
- SHOW_MAIN_ERRORS_ONLY=1 npx oxlint --config oxlint.config.mjs . -f stylish
lint:staged:
desc: Lint uniquement les fichiers .mjs staged (pour le hook pre-commit)
silent: true
cmds:
- |
FILES=$(git diff --cached --name-only --diff-filter=ACM -- '{{.APP_FOLDER}}/**/*.mjs')
if [ -z "$FILES" ]; then
exit 0
fi
SHOW_MAIN_ERRORS_ONLY=1 npx oxlint --config oxlint.config.mjs $FILES -f stylish
lint:errors:
desc: Lint les fichiers .mjs avec Oxlint, en affichant seulement les erreurs bloquantes
silent: true
cmds:
- SHOW_MAIN_ERRORS_ONLY=1 npx oxlint --config oxlint.config.mjs --quiet . -f stylish
lint:all:
desc: Lint tous les fichiers .mjs avec Oxlint, en affichant toutes les erreurs, même les simples warnings
silent: true
cmds:
- npx oxlint --config oxlint.config.mjs --report-unused-disable-directives-severity "warn" . -f stylish