generated from sknups/github-action-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·149 lines (107 loc) · 4.76 KB
/
build.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
#!/usr/bin/env bash
set -e
###############################################################################
# CONSTANTS #
###############################################################################
# exit codes
FAILURE=1
# colors
# shellcheck disable=SC2034
ANSI_BRIGHT="\033[1m"
ANSI_LIGHT_RED="\033[91m"
ANSI_LIGHT_GREEN="\033[92m"
ANSI_LIGHT_YELLOW="\033[93m"
ANSI_RESET="\033[0m"
###############################################################################
# VARIABLES #
###############################################################################
SCRIPT_START_TIME=0
SCRIPT_ELAPSED_TIME=0
###############################################################################
# ALIASES #
###############################################################################
shopt -s expand_aliases
alias now="date +%s"
alias echo="echo -e"
###############################################################################
# FUNCTIONS #
###############################################################################
function build {
echo "Checking shell scripts..."
if ! [[ $(command -v shellcheck) ]] ; then
error "shellcheck must be installed!"
fi
shellcheck ./*.sh || error
echo "Checking YAML.."
if ! [[ $(command -v yamllint) ]] ; then
error "yamllint must be installed!"
fi
find . \( -name "*.yml" -o -name "*.yaml" \) -not -path "./node_modules/*" -print0 | \
while IFS= read -r -d '' YAML
do
yamllint -s "${YAML}" || error
done
}
function start_timing {
SCRIPT_START_TIME=$(now)
}
function stop_timing {
SECONDS=$(($(now) - SCRIPT_START_TIME))
SCRIPT_ELAPSED_TIME=""
if [ ${SECONDS} -eq 0 ] ; then
SCRIPT_ELAPSED_TIME="nil"
else
if [ ${SECONDS} -ge 60 ] ; then
SCRIPT_ELAPSED_TIME="$(( SECONDS / 60 )) min "
fi
SCRIPT_ELAPSED_TIME="${SCRIPT_ELAPSED_TIME}$(( SECONDS % 60 )) sec"
fi
}
function success {
stop_timing
echo "${ANSI_LIGHT_GREEN}"
echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
echo "┃ ⭐️ SUCCESS ┃"
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
echo
echo " Time elapsed: ${SCRIPT_ELAPSED_TIME}"
echo "${ANSI_RESET}"
echo
}
function error {
MESSAGE=$1
stop_timing
echo "${ANSI_LIGHT_RED}"
echo
echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
echo "┃ 🛑 ERROR ┃"
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
echo
echo " ${MESSAGE}" > /dev/stderr
echo
echo " Time elapsed: ${SCRIPT_ELAPSED_TIME}"
echo "${ANSI_RESET}"
exit ${FAILURE}
}
function abort {
stop_timing
echo "${ANSI_LIGHT_YELLOW}"
echo
echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
echo "┃ ⚠️ ABORTED ┃"
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
echo
echo " Time elapsed: ${SCRIPT_ELAPSED_TIME}"
echo "${ANSI_RESET}"
exit ${FAILURE}
}
###############################################################################
# SCRIPT #
###############################################################################
start_timing
# if "CTRL-C" is seen, abort
trap abort INT
# Execute from the root of our Git repository
cd "$(dirname "$0")"
build
success