-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.sh
76 lines (58 loc) · 2.18 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
#!/bin/bash
# return failing exit code if any command fails
set -e
# enable nullglob - allows filename patterns which match no files to expand to a null string, rather than themselves
shopt -s nullglob
ROOTDIRECTORY="/source"
# go to the workdir
if [ -n "$BITBUCKET_CLONE_DIR" ]; then
cd "$BITBUCKET_CLONE_DIR" || return
ROOTDIRECTORY="$BITBUCKET_CLONE_DIR"
else
cd /source || return
fi
# Add nuget source if access token is set
if [ -n "$MYGET_ACCESS_TOKEN" ]; then
echo "Adding private myget source"
SOURCE="https://www.myget.org/F/inforit/auth/$MYGET_ACCESS_TOKEN/api/v3/index.json"
VAR=$(sed "/<\/packageSources>/i <add key=\"inforit.org\" value=\"$SOURCE\" protocolVersion=\"3\" />" ~/.nuget/NuGet/NuGet.Config)
echo "$VAR" > ~/.nuget/NuGet/NuGet.Config
echo -e "\n@inforit:registry=https://www.myget.org/F/inforit/npm/\n//www.myget.org/F/inforit/npm/:_authToken=$MYGET_ACCESS_TOKEN" >> ~/.npmrc
fi
CS_PROJECT_NAME="Api"
DIST="$ROOTDIRECTORY/dist"
# change project name from default "Api"
if [ -n "$PROJECT_NAME" ]; then
CS_PROJECT_NAME="$PROJECT_NAME"
fi
PROJECT_DIST="$DIST/$CS_PROJECT_NAME"
ARTIFACTS_DIST="$DIST/artifacts"
mkdir -p $ARTIFACTS_DIST
# Location of the back-end (always server in legacy projects)
cd server
echo "Building .NET solution"
nuget restore
msbuild *.sln
echo "Moving .NET artifact to output"
cd Inforit.*.Web
mv bin "$PROJECT_DIST"
echo "Moving .NET configurations to output"
find -type f -iname 'nlog.config' -exec cp {} $PROJECT_DIST \;
find -type f -iname 'appsettings.config' -exec cp {} $PROJECT_DIST \;
find -type f -iname 'web.config' -exec cp {} $PROJECT_DIST \;
find -type f -iname 'connectionstrings.config' -exec cp {} $PROJECT_DIST \;
# build and copy the front-end artifact
cd "$ROOTDIRECTORY"/client
echo "Building the front-end artifact"
# nodejs is managed via nvm, it must be started to use nodejs commands
. ~/.nvm/nvm.sh
source ~/.bashrc
nvm use ${NODEVERSION}
npm install
npm run build --if-present
npm run test --if-present
echo "Moving the front-end artifact to output"
mv ./dist "$PROJECT_DIST"/client
# generate artifacts dir
echo "generating artifacts"
zip -r "$ARTIFACTS_DIST/$CS_PROJECT_NAME.zip" "$PROJECT_DIST/"