-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevelop.sh
executable file
·161 lines (151 loc) · 5.56 KB
/
develop.sh
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
#!/usr/bin/env bash
#================================================================
# HEADER
#================================================================
#% SYNOPSIS
#+ [DOCKER_CONTAINER] /.${SCRIPT_NAME}
#%
#% DESCRIPTION
#% This is a script to automate and simplify menial daily tasks.
#%
#% EXAMPLES
#% DOCKER_CONTAINER=telemetry-service /.${SCRIPT_NAME}
#%./developi
#================================================================
#- IMPLEMENTATION
#- version ${SCRIPT_NAME} 0.0.1
#- author Ryan Grippeling <R.Grippeling@hotmail.nl>
#- license MIT
#-
#================================================================
# HISTORY
# 2024-04-23 : Ryan Grippeling : Started this script
#
#================================================================
# END_OF_HEADER
#================================================================
SCRIPT_HEADSIZE=$(head -200 ${0} |grep -n "^# END_OF_HEADER" | cut -f1 -d:)
SCRIPT_NAME="$(basename ${0})"
usage() { printf "Usage: "; head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#+" | sed -e "s/^#+[ ]*//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g" ; }
usagefull() { head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#[%+-]" | sed -e "s/^#[%+-]//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g" ; }
scriptinfo() { head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#-" | sed -e "s/^#-//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g"; }
checkVar () {
if [ -z "$1" ]; then
echo -n "You need to enter '$2': "
exit 1
fi
}
checkLastCommand () {
if [ ! $? -eq 0 ]; then
echo "Script failed."
exit 1
fi
}
export DOCKER_CONTAINER=${DOCKER_CONTAINER:-telemetry-service}
runOnDocker () {
if [ ! $(docker inspect -f '{{.State.Running}}' $DOCKER_CONTAINER 2> /dev/null ) ]; then
echo "Docker container \"$DOCKER_CONTAINER\" not running... Try \"docker-compose up -d $DOCKER_CONTAINER\"" > /dev/stderr
exit 1
fi
docker exec -it $DOCKER_CONTAINER "$@"
}
# If we pass any arguments...
if [ $# -gt 0 ];then
case "$1" in
"info")
scriptinfo
;;
"help")
usagefull
;;
"enter")
runOnDocker bash
;;
"doctrine-migrations")
shift
runOnDocker php ./vendor/bin/doctrine-migrations "$@"
;;
"console")
shift
runOnDocker php ./public/console.php "$@"
;;
"phpcs")
shift
docker run --rm -it -v $(pwd):/app -w /app php:8.3-cli php ./vendor/bin/phpcs --standard=phpcs.xml --extensions=php ./src
;;
"phpcbf")
shift
docker run --rm -it -v $(pwd):/app -w /app php:8.3-cli php ./vendor/bin/phpcbf --standard=phpcs.xml --extensions=php ./src
;;
"phpmd")
shift
docker run --rm -itv $(pwd):/app -w /app php:8.3-fpm php ./vendor/bin/phpmd src text phpmd.xml
;;
"phpstan")
shift
docker run --rm -it -v $(pwd):/app -w /app php:8.3-fpm php ./vendor/bin/phpstan analyse src --level 8
;;
"psalm")
shift
docker run --rm -itv $(pwd):/app -w /app php:8.3-fpm php ./vendor/bin/psalm --config=psalm.xml "$@"
;;
"rector")
shift
docker run --rm -itv $(pwd):/app -w /app php:8.3-fpm php vendor/bin/rector process ./src
;;
"composer-normalize")
shift
docker run --rm -itv $(pwd):/app -w /app composer:latest composer normalize
;;
"test") # https://www.php.net/manual/en/intro.phpdbg.php -> TODO BETER DAN XDEBUG, gebruiken ipv php
shift
docker run --rm -itv $(pwd):/app -w /app php:8.3-fpm php vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist --testsuite unit --fail-on-risky $@
;;
"integration")
shift
runOnDocker vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist --testsuite integration --fail-on-risky $@
;;
"analyze")
docker run --rm -itv $(pwd):/app -w /app php:8.3-fpm php vendor/bin/phpcs --standard=phpcs.xml --extensions=php --report=full pub
;;
"pre-commit-phpcs")
php vendor/bin/phpcs --standard=phpcs.xml pub
;;
"pre-commit-static-analysis-changed")
$(git --no-pager diff --name-only --diff-filter=MARC| grep -E 'pub/')
if [ $? -eq 0 ]; then
docker run --rm -v /$(pwd):/app phpstan/phpstan analyse --level max --no-progress $(git --no-pager diff --name-only --diff-filter=MARC| grep -E 'pub/')
fi
;;
# "jsinstall")
# docker run --rm -v /${pwd:/app -w /app node:10-alpine npm install
# ;;
# "jsclean")
# docker run --rm -v /${pwd:/app -w /app node:10-alpine sh -c "rm -rf public/js"
# ;;
# "jsbuild")
# docker run --rm -v /${pwd:/app -w /app node:10-alpine sh -c "rm -rf public/js && npm run build"
# ;;
# "jswatch")
# docker run --rm -v /${pwd:/app -w /app node:10-alpine npm run watch
# ;;
# "cy:open")
# echo "Cypress is opening..."
# node_modules/.bin/cypress open &
# ;;
# "cy:run")
# node_modules/.bin/cypress run
# ;;
"log")
runOnDocker tail -f /var/log/app.log
;;
"composer")
docker run --rm -itv $(pwd):/app -w /app composer "$@"
;;
*)
runOnDocker "$@"
;;
esac
else
usage
fi