forked from vmware-tanzu/cloud-suitability-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·175 lines (144 loc) · 3.45 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
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
#!/bin/bash
echo "Build started at $(date -u +%s)"
#--- this corrects and issue with go mod tidy
export GOSUMDB=off
#--- set module mode
export GO111MODULE=on
cleanup() {
rm -rf ${PWD}/csa-app/dist/* ${PWD}/csa-app/frontend/build
}
compilePackageFrontEnd() {
echo "~~~> Compile/Minify UI"
pushd ${PWD}/csa-app/frontend
echo "~~~> Running npm ci"
export NODE_OPTIONS="--max_old_space_size=4096"
npm update && npm fund
npm ci -s --no-optional --force --legacy-peer-deps
if [ $? -eq 0 ]
then
echo "~~~> npm ci succeeded"
else
echo "~~~> npm ci failed" >&2
exit 1
fi
echo "~~~> Running npm production-build"
npm run -s production-build
if [ $? -eq 0 ]
then
echo "~~~> production-build succeeded"
else
echo "~~~> production-build failed " >&2
exit 1
fi
bindDataFile=${PWD}/csa-app/frontend/resources/web-site.go
if [ -f "$bindDataFile" ]; then
echo "~~~> web-site.go found, removing"
rm $bindDataFile
fi
echo "~~~> Binding in web assets"
mkdir -p ${PWD}/csa-app/frontend/resources
go-bindata -o resources/web-site.go -pkg resources build/...
if [ $? -eq 0 ]
then
echo "~~~> go-bindata succeeded!"
else
echo "~~~> go-bindata failed " >&2
exit 1
fi
popd
}
stashFiles() {
git stash
}
#--- Run go generate
runGoGenerate() {
pushd ${PWD}/csa-app
echo "~~~> Binding rules and bins"
go generate #>&2
if [ $? -eq 0 ]
then
echo "~~~> go generate succeeded"
else
echo "~~~> go generate failed " >&2
exit 1
fi
echo "~~~> Updating dependencies"
go mod tidy
if [ $? -eq 0 ]
then
echo "~~~> go mod tidy succeeded"
else
echo "~~~> go mod tidy failed " >&2
exit 1
fi
popd
}
# Create csa executables
generateCSAExecutables() {
pushd ${PWD}/csa-app
OS=$(uname)
if [[ "$OS" == "Linux" ]]; then
echo "Building executables for linux and windows"
goreleaser build --skip-validate --snapshot --id='linux' --id='windows' --clean
elif [[ "$OS" == "Darwin" && "$RELEASE" == true ]]; then
echo "Building executables for darwin, linux and windows"
goreleaser build --clean
elif [[ "$OS" == "Darwin" ]]; then
echo "Building executables for darwin, linux and windows"
goreleaser build --skip-validate --snapshot --clean
fi
popd
}
# Create csa test executables
generateRuleTestExecutables() {
echo "Build Rule Test executables under csa-app/test-exe"
sh build-test-clis.sh
}
# Run tests to validate the correctness of the rules
runRuleTests() {
CURRENT_DIR=${PWD}
cd ${PWD}/csa-app/tests
go test -v
if [ $? -eq 0 ]
then
echo "~~~> Rule test passed!"
else
echo "~~~> Rule test failed!" >&2
exit 1
fi
cd ${CURRENT_DIR}
}
helpText() {
echo "./build.sh - Generate binaries"
echo " -h|--help Help!!"
echo " -r|--release Specify this flag if you want to generate the release builds"
}
while [[ $# -gt 0 ]]; do
case $1 in
-r|--release)
RELEASE=true
shift
shift
;;
-h|--help)
helpText
exit 1
;;
*)
echo "Invalid option"
helpText
exit 1
;;
esac
done
./download-dependencies.sh
cleanup
compilePackageFrontEnd
runGoGenerate
if [[ ! -z "$RELEASE" ]]; then
stashFiles
fi
runRuleTests
generateCSAExecutables
generateRuleTestExecutables
echo "Build ended at $(date -u +%s)"