-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtoolbox
More file actions
executable file
·226 lines (170 loc) · 6.91 KB
/
Copy pathtoolbox
File metadata and controls
executable file
·226 lines (170 loc) · 6.91 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
#!/usr/bin/env bash
set -euo pipefail
readonly PROJECT_NAME="${FUZZRAKE_DEV_PROJECT_NAME:-fuzzrake}"
readonly SNAPSHOTS_REL_PATH='var/snapshots' # grep-code-snapshots-dir-path
readonly DATABASE_REL_PATH='var/db.sqlite' # grep-code-database-path
readonly DB_DUMP_DIR_REL_PATH='db_dump'
readonly DB_DUMP_COPY_DIR_REL_PATH="$DB_DUMP_DIR_REL_PATH/$(date -u '+%Y-%m-%d_%H-%M-%S')"
readonly PROD_ENV_SSH_PATH='getfursu.it:/var/www/prod'
readonly BETA_ENV_SSH_PATH='getfursu.it:/var/www/beta'
readonly DOCKER_EXEC_EXTRA_ARGS=(
--user "$(echo -n "$(id -u):www-data")"
--interactive
--tty
# Uncomment below to debug tests
# --env XDEBUG_TRIGGER=1
)
function run_command() {
echo "Executing: $*"
"$@"
}
function run_docker_compose() {
run_command docker compose --project-directory docker --project-name "$PROJECT_NAME" "$@"
}
function run_docker_compose_exec() {
run_docker_compose exec "${DOCKER_EXEC_EXTRA_ARGS[@]}" php "$@"
}
function run_composer() {
run_docker_compose_exec composer "$@"
}
function run_console() {
run_docker_compose_exec ./bin/console "$@"
}
function run_yarn() {
# Known issue: requires local installation of Yarn
run_command yarn "$@"
}
function action_get_snapshots() {
run_command rsync --recursive --progress --human-readable --compress --checksum \
"$PROD_ENV_SSH_PATH/$SNAPSHOTS_REL_PATH/" "$SNAPSHOTS_REL_PATH"
}
function action_dbcommit() {
pushd "$DB_DUMP_DIR_REL_PATH"
run_command git reset HEAD
run_command git commit -m 'Updated DB dump' -p
run_command git push
run_command git show -q
popd
}
function action_dbpull() {
run_command scp -p "$PROD_ENV_SSH_PATH/$DATABASE_REL_PATH" "$DATABASE_REL_PATH"
run_command chmod a+w "$DATABASE_REL_PATH"
run_command cp "$DATABASE_REL_PATH"{,.bak}
}
function action_dbpush_main() {
echo "$(tput setaf 1)$(tput bold)WARNING!$(tput sgr0) Destructive action."
read -rp 'Confirm by typing "overwrite": ' user_input
if [[ $user_input != 'overwrite' ]]; then
exit 1
fi
run_command scp -p "$DATABASE_REL_PATH" "$PROD_ENV_SSH_PATH/$DATABASE_REL_PATH"
}
function action_dbpush_beta() {
run_command scp -p "$DATABASE_REL_PATH" "$BETA_ENV_SSH_PATH/$DATABASE_REL_PATH"
}
function action_dbdump() {
# shellcheck disable=SC2207 # Yes, split by whitespace
TABLE_NAMES=($(sqlite3 "$DATABASE_REL_PATH" .tables))
mkdir "$DB_DUMP_COPY_DIR_REL_PATH"
for TABLE_NAME in "${TABLE_NAMES[@]}"; do
local SQL_DUMP_PATH="$DB_DUMP_COPY_DIR_REL_PATH/$TABLE_NAME.sql"
local JSON_DUMP_PATH="$DB_DUMP_COPY_DIR_REL_PATH/$TABLE_NAME.json"
run_command sqlite3 "$DATABASE_REL_PATH" ".output $SQL_DUMP_PATH" ".dump $TABLE_NAME"
echo 'Dumping to JSON...'
if grep -q 'CREATE TABLE creators_urls (' "$SQL_DUMP_PATH"; then
order_by='ORDER BY creator_id, type, url'
elif grep -q 'CREATE TABLE creators_values (' "$SQL_DUMP_PATH"; then
order_by='ORDER BY creator_id, field_name, value'
elif grep -q 'CREATE TABLE doctrine_migration_versions (' "$SQL_DUMP_PATH"; then
order_by=''
else
order_by='ORDER BY id'
fi
sqlite3 -json "$DATABASE_REL_PATH" "SELECT * FROM $TABLE_NAME $order_by" | jq > "$JSON_DUMP_PATH"
done
rm -f "$DB_DUMP_DIR_REL_PATH"/*.{json,sql}
cp "$DB_DUMP_COPY_DIR_REL_PATH"/*.{json,sql} "$DB_DUMP_DIR_REL_PATH"
}
function error() {
local message="$1"
echo "ERROR: $message" >&2
echo ''
usage
exit 1
}
function usage() {
cat << EOF
Usage:
$0 ACTION [arguments ...]
Available actions:
branch docker-up + composer install + yarn install + yep
docker-up "ups" the Docker Compose project
docker-down "downs" the Docker Compose project
docker-re docker-down + docker-up
composer run Composer
yarn run Yarn (needs to be installed locally)
yep execute 'yarn encore production'
console run Symfony console command
cc clear cache
pu run PHPUnit tests
pus run PHPUnit tests, "small" group
pum run PHPUnit tests, "medium" group
pul run PHPUnit tests, "large" group
pcf run PHP CS Fixer
tcf run Twig CS Fixer
ps run PHPStan
rector run Rector
el run ESLint
prettier run Prettier
EOF
}
function action() {
[[ $# -ge 1 ]] || error 'Not enough arguments'
local action="$1"
shift
case $action in
'branch')
action docker-up
run_composer install
run_yarn install
run_yarn encore production
;;
'docker-up') run_docker_compose up --detach --build ;;
'docker-down') run_docker_compose down ;;
'docker-re') action docker-down && action docker-up ;;
'yep') run_yarn encore production ;;
'composer') run_composer "$@" ;;
'yarn') run_yarn "$@" ;;
'console') run_console "$@" ;;
'cc') run_console cache:clear && run_console app:precompute-data ;;
'cc-beta') run_command ssh getfursu.it \
'docker exec fuzzrake-beta bin/console cache:clear && docker exec fuzzrake-beta bin/console app:precompute-data' ;;
'cc-prod') run_command ssh getfursu.it \
'docker exec fuzzrake-prod bin/console cache:clear && docker exec fuzzrake-prod bin/console app:precompute-data' ;;
'pu') run_docker_compose_exec ./bin/phpunit --order-by size,reverse "$@" ;;
'pus') action pu --group small "$@" ;;
'pum') action pu --group medium "$@" ;;
'pul') action pu --group large "$@" ;;
'pcf') run_docker_compose_exec ./vendor/bin/php-cs-fixer fix "$@" ;;
'tcf') run_docker_compose_exec ./vendor/bin/twig-cs-fixer lint --fix "$@" ;;
'ps') run_docker_compose_exec ./vendor/bin/phpstan analyse -c phpstan.neon "$@" ;;
'rector') run_docker_compose_exec ./vendor/bin/rector process "$@" ;;
'el') run_yarn eslint assets/scripts/ "$@" ;;
'prettier') run_yarn prettier . --write "$@" ;;
'al') pushd ansible; ansible-lint *.yaml ;;
'yl') yamllint . ;;
'tidy') run_console app:data:tidy "$@" ;;
'tidyc') action tidy --commit "$@" ;;
'dbpull') action_dbpull ;;
'dbdump') action_dbdump ;;
'dbcommit') action_dbcommit ;;
'dbpdc') action_dbpull && action_dbdump && action_dbcommit ;;
'dbpush-beta') action_dbpush_beta ;;
'dbpush-prod') action_dbpush_prod ;;
'release') run_command ansible/release.yaml --diff "$@" ;;
'get-snapshots') action_get_snapshots ;;
*) error "Unknown action: '$action'" ;;
esac
}
pushd "$(dirname "$(realpath "$0")")"
action "$@"