forked from cisagov/cset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
144 lines (120 loc) · 4.27 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
#!/bin/bash
shopt extglob dotglob nullglob
############################
####### CONSTANTS ########
############################
#if not passed in on command line, set to web deployment values
# if [ -z "$ng_config" ]; then
# ng_config=production
# fi
# if [ -z "$reports_config" ]; then
# reports_config=production
# fi
# if [ -z "$msbuild_config" ]; then
# msbuild_config=Release
# fi
# if [ -z "$mspublish_config" ]; then
# mspublish_config=FolderProfile
# fi
# if [ -z "$mspublish_folder" ]; then
# mspublish_folder=$msbuild_config
# fi
if [ -z "$ng_config" ]; then
ng_config=production
fi
if [ -z "$reports_config" ]; then
reports_config=production
fi
if [ -z "$msbuild_config" ]; then
msbuild_config=localdb
fi
if [ -z "$mspublish_config" ]; then
mspublish_config=runlocal
fi
if [ -z "$mspublish_folder" ]; then
mspublish_folder=$msbuild_config
fi
#StandAlone values
# ng_config=local reports_config=local msbuild_config=localdb mspublish_config=runlocal
#Enterprise install default values
# msbuild_config=localhost mspublish_folder=Release
############################
####### VARIABLES ########
############################
# run vswhere, and convert to POSIX path format
vs_install_dir=$( echo "$(./vswhere.bat | tail -n 1)" | sed -e 's/\\/\//g' -e 's/://' -e 's/^/\//' )
echo "Visual Studio Installation Directory: $vs_install_dir"
echo ''
echo 'Finding MSBuild Versions...'
msbuild_version=0.0
build_dir=$(pwd) # so we can get back to the build directory after finding MSBuild
cd "$vs_install_dir/MSBuild"
for i in *.*; # the directories we are looking for are all similar to 5.0/
do
if [ -d $i ]; # make sure it is a directory
then
echo "Found Version $i";
fi
if [ ${i%.*} -eq ${msbuild_version%.*} ] && [ ${i#*.} \> ${msbuild_version#*.} ] || [ ${i%.*} -gt ${msbuild_version%.*} ];
then
msbuild_version=$i
fi
done
if [ $msbuild_version = 0.0 ];
then
echo 'MSBuild not found! Build cancelled!'
exit 1
fi
cd $build_dir
echo "Selected MSBuild version: $msbuild_version"
echo ''
# The path to the MSBuild executable
msbuild="'$vs_install_dir/MSBuild/$msbuild_version/Bin/MSBuild.exe'"
echo "MSBuild Path: $msbuild"
echo ''
############################
####### FUNCTIONS ########
############################
# NOTE: Throughout, the output of asynchronous processes is prefixed with a descriptive tag by piping to sed
build_ng() {
echo 'Angular Build'
cd CSETWebNg
echo 'building CSET app'
ng build --configuration=$ng_config --source-map=false | sed "s/^/APP: /" > ../ng-build.log 2> ../ng-errors.log
echo 'building Reports app'
ng build reports --configuration=$reports_config --source-map=false --base-href="./" | sed "s/^/REPORTS: /" > ../reports-build.log 2> ../reports-errors.log
echo 'done building Angular project'
echo 'PLEASE WAIT'
}
build_api() {
cd CSETWebApi
echo 'Cleaning solution...'
eval "$msbuild CSETWeb_Api/CSETWeb_Api.sln -property:Configuration=$msbuild_config -t:Clean" | sed "s/^/CLEAN: /" > ../api-build.log 2> ../api-errors.log
echo 'Building solution...'
eval "$msbuild CSETWeb_Api/CSETWeb_Api.sln -property:Configuration=$msbuild_config -t:Build" | sed "s/^/BUILD: /" >> ../api-build.log 2>> ../api-errors.log
echo 'Solution built.'
echo 'Publishing project...'
eval "$msbuild CSETWeb_Api/CSETWeb_Api/CSETWeb_Api.csproj -p:DeployOnBuild=true -p:PublishProfile=$mspublish_config -p:Configuration=$msbuild_config" | sed "s/^/PUBLISH: /" > ../api-publish.log 2> publish-errors.log
echo 'Project published.'
echo 'PLEASE WAIT'
}
publish_dist() {
echo 'Cleaning up dist folder.'
rm -rf dist | sed "s/^/DIST CLEANUP: /"
#NOTE: the Angular dist must be copied into the API dist, and not vice versa
echo 'Publishing to dist folder'
mv "CSETWebApi/CSETWeb_Api/CSETWeb_Api/bin/$mspublish_folder/Publish" dist | sed "s/^/API PUBLISH: /"
cp -r CSETWebNg/dist . | sed "s/^/NG PUBLISH: /"
echo 'dist Folder is ready for deployment.'
}
############################
########## MAIN ##########
############################
echo 'Beginning asynchronous build processes...'
build_ng | sed "s/^/NG BUILD: /" &
build_api | sed "s/^/API BUILD: /" &
echo 'Processes started.'
wait
echo 'All build processes complete.'
publish_dist
echo 'CSETWeb BUILD COMPLETE'