-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjustfile
208 lines (167 loc) · 7.38 KB
/
justfile
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
set dotenv-load := true
export UID := `id -u`
export GID := `id -g`
export COMPOSE_PROFILES := if env_var_or_default("CI", "0") == "true" { "test" } else { "dev" }
COMPOSE := 'docker compose -f docker/app.yml -p ' + env_var('PROJECT_NAME')
COMPOSE-RUN := COMPOSE + ' run --rm'
PHP-DB-RUN := COMPOSE-RUN + ' api'
PHP-RUN := COMPOSE-RUN + ' --no-deps api'
NODE-RUN := COMPOSE-RUN + ' --no-deps app'
MARIADB-RUN := COMPOSE-RUN + ' -T --no-deps mariadb'
# default command run when entering "just" only
default:
just --list
# load fixture data and startup all services defined in docker/app.yml
init: start
{{PHP-DB-RUN}} bin/console cache:warmup
{{PHP-DB-RUN}} bin/console doctrine:database:drop --force --if-exists
{{PHP-DB-RUN}} bin/console doctrine:database:create
{{PHP-DB-RUN}} bin/console doctrine:schema:create
{{PHP-DB-RUN}} bin/console doctrine:migrations:sync-metadata-storage --no-interaction
{{PHP-DB-RUN}} bin/console doctrine:migrations:version --add --all --no-interaction
{{PHP-DB-RUN}} php -dmemory_limit=-1 bin/console doctrine:fixtures:load -n
# start all services defined in docker/app.yml
start:
{{COMPOSE}} up -d
@echo URL: http://localhost:${PORT}
# start mariadb service defined in docker/app.yml
start-db:
{{COMPOSE}} up -d mariadb
# stop all services defined in docker/app.yml
stop:
{{COMPOSE}} stop
# Load a (gzipped) database backup for local testing
import-db-dump file name='pkgstats_archlinux_de': start
{{MARIADB-RUN}} mariadb-admin -uroot -hmariadb --skip-ssl drop -f {{name}} || true
{{MARIADB-RUN}} mariadb-admin -uroot -hmariadb --skip-ssl create {{name}}
zcat {{file}} | {{MARIADB-RUN}} mariadb -uroot -hmariadb --skip-ssl {{name}}
{{PHP-DB-RUN}} bin/console doctrine:migrations:sync-metadata-storage --no-interaction
{{PHP-DB-RUN}} bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration
# remove containers and untracked files
clean:
{{COMPOSE}} rm -vsf
git clean -fdqx -e .idea
# remove containers & untracked files, rebuild all containers, install dependencies and run "just init"
rebuild: clean
{{COMPOSE}} -f docker/cypress-run.yml -f docker/cypress-open.yml build --pull
just install
just init
# install php & js dependencies
install:
{{PHP-RUN}} composer --no-interaction install
{{NODE-RUN}} pnpm install --frozen-lockfile
# short for "docker compose -f docker/app.yml -p {{args}}"
compose *args:
{{COMPOSE}} {{args}}
# short for "docker compose -f docker/app.yml -p run --rm {{args}}"
compose-run *args:
{{COMPOSE-RUN}} {{args}}
# short for "short for "docker compose -f docker/app.yml -p run --rm php {{args}}"
php *args='-h':
{{PHP-RUN}} php {{args}}
# run composer inside a php container
composer *args:
{{PHP-RUN}} composer {{args}}
# list outdated php dependencies
composer-outdated: (composer "install") (composer "outdated --direct --strict")
# list outdated js dependencies
pnpm-outdated: (pnpm "install --frozen-lockfile") (pnpm "outdated")
# list outdated dependencies
outdated: composer-outdated pnpm-outdated
# direct access to Sf console commands
console *args:
{{PHP-RUN}} bin/console {{args}}
# run phpunit inside a php container
phpunit *args:
{{PHP-RUN}} php -dmemory_limit=-1 vendor/bin/phpunit {{args}}
# run phpstan inside a php containre
phpstan *args:
{{PHP-RUN}} php -dmemory_limit=-1 vendor/bin/phpstan {{args}}
# run node inside a node container
node *args='-h':
{{NODE-RUN}} node {{args}}
# run pnpm inside a php containre
pnpm *args='-h':
{{NODE-RUN}} pnpm {{args}}
# run jest inside a node containre
jest *args:
{{NODE-RUN}} node_modules/.bin/jest --passWithNoTests {{args}}
# run cypress-run command
cypress *args:
{{COMPOSE}} -f docker/cypress-run.yml run --rm --no-deps --entrypoint cypress cypress-run {{args}}
# run cypress tests in CLI
cypress-run *args:
{{COMPOSE}} -f docker/cypress-run.yml run --rm --no-deps cypress-run --headless --browser chrome --project tests/e2e {{args}}
# open cypress GUI to interactively run tests
cypress-open *args:
Xephyr :${PORT} -screen 1920x1080 -resizeable -name Cypress -title "Cypress - {{ env_var('PROJECT_NAME') }}" -terminate -no-host-grab -extension MIT-SHM -extension XTEST -nolisten tcp &
DISPLAY=:${PORT} DISPLAY_SOCKET=/tmp/.X11-unix/X${PORT%%:*} {{COMPOSE}} -f docker/cypress-open.yml run --rm --no-deps cypress-open --project tests/e2e --e2e {{args}}
# execute all php tests (validate composer, linting, phpunit)
test-php:
{{PHP-RUN}} composer validate
{{PHP-RUN}} vendor/bin/phpcs
{{PHP-RUN}} bin/console lint:container
{{PHP-RUN}} bin/console lint:yaml --parse-tags config
{{PHP-RUN}} bin/console lint:twig templates
{{PHP-RUN}} php -dmemory_limit=-1 vendor/bin/phpstan analyse
{{PHP-RUN}} php -dmemory_limit=-1 vendor/bin/phpunit
# execute all js tests (linting, jest, build project)
test-js:
{{NODE-RUN}} node_modules/.bin/eslint '*.js' src tests --ext js --ext vue
{{NODE-RUN}} node_modules/.bin/stylelint 'src/assets/css/**/*.scss' 'src/assets/css/**/*.css' 'src/**/*.vue'
{{NODE-RUN}} node_modules/.bin/jest --passWithNoTests
{{NODE-RUN}} pnpm run build --output-path $(mktemp -d)
# run all tests
test: test-php test-js
# run e2e tests
test-e2e:
#!/usr/bin/env bash
set -e
if [ "${CI-}" = "true" ]; then
git clean -xdf app/dist
just init
just pnpm run build
CYPRESS_baseUrl=http://nginx:8081 just cypress-run
else
just cypress-run
fi
# run database tests
test-db *args: start-db
{{PHP-DB-RUN}} vendor/bin/phpunit -c phpunit-db.xml {{args}}
# test db migrations
test-db-migrations *args: start-db
{{PHP-DB-RUN}} vendor/bin/phpunit -c phpunit-db.xml --testsuite 'Doctrine Migrations Test' {{args}}
# use jest and phpunit to generate code coverage reports
test-coverage:
{{NODE-RUN}} node_modules/.bin/jest --passWithNoTests --coverage --coverageDirectory var/coverage/jest
{{PHP-RUN}} php -d zend_extension=xdebug -d xdebug.mode=coverage -d memory_limit=-1 vendor/bin/phpunit --coverage-html var/coverage/phpunit
# run phpunit to generate db code coverage report
test-db-coverage: start-db
{{PHP-RUN}} php -d zend_extension=xdebug -d xdebug.mode=coverage -d memory_limit=-1 vendor/bin/phpunit --coverage-html var/coverage -c phpunit-db.xml
# run composer and pnpm audit commands
test-security: (composer "audit")
{{NODE-RUN}} pnpm audit --prod
# run phpcbf, eslint and stylelint to fix cs
fix-code-style:
{{PHP-RUN}} vendor/bin/phpcbf || true
{{NODE-RUN}} node_modules/.bin/eslint '*.js' src tests --ext js --ext vue --fix
{{NODE-RUN}} node_modules/.bin/stylelint --fix=strict 'src/assets/css/**/*.scss' 'src/assets/css/**/*.css' 'src/**/*.vue'
# update all project dependencies
update:
{{PHP-RUN}} composer --no-interaction update
{{PHP-RUN}} composer --no-interaction update --lock --no-scripts
{{NODE-RUN}} pnpm update --latest
deploy:
cd app && pnpm install --frozen-lockfile --prod
cd app && pnpm run build
cd app && find dist -type f -atime +512 -delete # needs to be above the highest TTL
cd app && find dist -type d -empty -delete
cd api && composer --no-interaction install --prefer-dist --no-dev --optimize-autoloader --classmap-authoritative
cd api && composer dump-env prod
systemctl restart [email protected]
cd api && bin/console doctrine:migrations:sync-metadata-storage --no-interaction
cd api && bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration
deploy-permissions:
cd api && sudo setfacl -dR -m u:php-pkgstats:rwX -m u:deployer:rwX var
cd api && sudo setfacl -R -m u:php-pkgstats:rwX -m u:deployer:rwX var
# vim: set ft=make :