Repository navigation
Expand file tree
/
Copy pathrun
More file actions
executable file
·126 lines (113 loc) · 4.09 KB
/
Copy pathrun
File metadata and controls
executable file
·126 lines (113 loc) · 4.09 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
#! /usr/bin/env bash
NOCOLOR='\033[0m'
GREEN='\033[0;32m'
ORANGE='\033[38;5;208m' # 256-colour palette orange, ANSI 33 is yellow
GRAY='\e[2;37m'
BLACK="\033[0;30m" # Black
RED="\033[0;31m" # Red
YELLOW="\033[0;33m" # Yellow
BLUE="\033[0;34m" # Blue
PURPLE="\033[0;35m" # Purple
CYAN="\033[0;36m" # Cyan
WHITE="\033[0;37m" # White
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
SERVER="localhost:8082"
SUPPORTED_COMMANDS=(
'help'
'tests'
'browser-sync'
'status'
)
# Define it for the whole script session
# This disables twig caching and activate debugging tools
export DEV_MODE=true
# Stop browser-sync when the script exits (Ctrl-C on the PHP server included)
BROWSER_SYNC_PID=''
function cleanup() {
if [ -n "${BROWSER_SYNC_PID}" ];
then
kill "${BROWSER_SYNC_PID}" 2> /dev/null
fi
}
trap cleanup EXIT
if [ $# -gt 0 ]
then
supported_command=false
for command in ${SUPPORTED_COMMANDS[@]};
do
if [ "${command}" == "$1" ];
then
supported_command=true
break
fi
done
if [ "${supported_command}" = false ];
then
echo -e "Unknown parameter ${ORANGE}${BOLD}${1}${NORMAL}${NOCOLOR}. Type ${GREEN}${BOLD}./run help${NORMAL} to know what the valid parameters are."
exit 1
fi
fi
if [ $# -gt 0 ] && [ $1 = 'help' ]
then
echo -e "${ORANGE}${BOLD}Usage:${NORMAL}${NOCOLOR}"
echo -e " ${BOLD}run${NORMAL} Starts the PHP web server and listen to localhost:8082"
echo -e " ${BOLD}run tests${NORMAL} Runs application test suite"
echo -e " ${BOLD}run browser-sync${NORMAL} Run with browser-sync"
echo -e " ${BOLD}run status${NORMAL} Check if the current commit is on production"
echo ""
echo "Additional parameters will be ignored."
exit 0
fi
if [ $# -gt 0 ] && [ $1 = 'tests' ]
then
composer test:all
exit $?
fi
if [ $# -gt 0 ] && [ $1 = 'status' ]
then
local=`git rev-parse master`
dev=`curl -s https://dev.whattrainisitnow.nonprod.webservices.mozgcp.net/deployed-version.txt`
prod=`curl -s https://whattrainisitnow.com/deployed-version.txt`
if [ -n "$local" ] && [ "$(echo -n "$dev" | tr -d '[:space:]')" == "$local" ]
then
dev_mark=" ${GREEN}✔${NOCOLOR}"
else
dev_mark=" ${RED}✘${NOCOLOR}"
fi
local_mark="$dev_mark"
printf '%b\e]8;;%s\e\\\e[4:4m%s\e[24m\e]8;;\e\\ %s%b%b\n' "$GRAY" "https://dev.whattrainisitnow.nonprod.webservices.mozgcp.net/" "Dev" "$dev" "$NORMAL" "$dev_mark"
printf '\e]8;;%s\e\\\e[4:4m%s\e[24m\e]8;;\e\\ %s%b\n' "http://$SERVER/" "Local" "$local" "$local_mark"
printf '\e]8;;%s\e\\\e[4:4m%s\e[24m\e]8;;\e\\ %s\n' "https://whattrainisitnow.com/" "Prod" "$prod"
if [ $local == $prod ]
then
echo ""
echo -en "$GREEN""Yes, we are good""$NORMAL"
else
x=$(($(git rev-list --count $prod..$local)))
echo ""
if [ $x == 1 ]
then
echo -en "$ORANGE""No, production is 1 commit behind""$NORMAL"
else
echo -en "$ORANGE""No, production is $x commits behind""$NORMAL"
fi
fi
exit 0
fi
echo -e "${GREEN}${BOLD}Launching PHP development server on http://fxtrains.${SERVER}${NORMAL}${NOCOLOR}"
if command -v browser-sync &> /dev/null; then
if [ $# -gt 0 ] && [ $1 = 'browser-sync' ]
then
echo -e "${GREEN}browser-sync is installed on the system, launching it in the background${NOCOLOR}"
browser-sync start --proxy "localhost:8082" --files "**/*" &
BROWSER_SYNC_PID=$!
else
echo -e "${ORANGE}browser-sync is installed on the system but won't be launched${NOCOLOR}"
fi
fi
# The "[date] PHP x.y.z Development Server (http://...) started" banner is
# hardcoded in PHP, rewrite it without the timestamp and URL (printed above).
# cli_server.color keeps the colored log output even though stderr is piped.
php -d opcache.jit=disable -d cli_server.color=1 -S ${SERVER} -t public/ app/inc/router.php 2>&1 \
| sed -u -E "s|^\[[^]]*\] (PHP [^ ]+ Development Server) \(http://${SERVER}\) started$|\1 started (CTRL+C to stop)|"