-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdotnet-build.sh
91 lines (73 loc) · 2.78 KB
/
dotnet-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
#!/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="${ROOTDIRECTORY:-"/api"}"
# go to the workdir
if [ -n "$BITBUCKET_CLONE_DIR" ]; then
cd "$BITBUCKET_CLONE_DIR" || return
ROOTDIRECTORY="$BITBUCKET_CLONE_DIR"
else
cd "$ROOTDIRECTORY" || return
fi
# Add nuget source if access token is set
if [ -n "$MYGET_ACCESS_TOKEN" ]; then
NUGET_CONFIG=~/.nuget/NuGet/NuGet.Config
echo "Adding private myget source"
SOURCE="https://www.myget.org/F/frontliners/auth/$MYGET_ACCESS_TOKEN/api/v3/index.json"
if ! grep -q "$SOURCE" $NUGET_CONFIG; then
VAR=$(sed "/<\/packageSources>/i <add key=\"Frontliners MyGet package source\" value=\"$SOURCE\" protocolVersion=\"3\" />" $NUGET_CONFIG)
echo "$VAR" >$NUGET_CONFIG
fi
fi
CS_PROJECT_FILE="${CS_PROJECT_FILE:-"src/Api/Api.csproj"}"
CS_PROJECT_NAME="Api"
DIST="./dist"
RELEASE="Release"
# change project name from default "Api"
if [ -n "$PROJECT_NAME" ]; then
CS_PROJECT_NAME="$PROJECT_NAME"
fi
# change project file location from default "Api.csproj" if specified
if [ -n "$PROJECT_FILE" ]; then
CS_PROJECT_FILE="$PROJECT_FILE"
fi
PROJECT_DIST="$DIST/$CS_PROJECT_NAME"
ARTIFACTS_DIST="$DIST/artifacts"
rm -rf ./**/bin
rm -rf ./**/obj
rm -rf "$DIST"
# create artifacts dir
mkdir -p "$ARTIFACTS_DIST"
# clean dependencies
echo "cleaning $CS_PROJECT_FILE"
dotnet clean "$CS_PROJECT_FILE"
# restore dependencies
echo "restoring $CS_PROJECT_FILE"
dotnet restore "$CS_PROJECT_FILE"
# build project
echo "building $CS_PROJECT_FILE"
dotnet build --configuration $RELEASE --no-restore "$CS_PROJECT_FILE"
# run tests
shopt -s nocaseglob # disable casing
echo "running tests"
for f in *.test/*.csproj; do
echo "Processing $f file..."
dotnet add "$f" package JUnitTestLogger
dotnet test "$f" --logger "junit" --configuration $RELEASE --results-directory "$DIST/test-results" /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:CoverletOutput="$DIST/test-coverlet"
done
shopt -u nocaseglob # enable casing
# collect codecoverage files and generate report for sonarcloud (warning is for backwards compatability)
reportgenerator -reports:"**/*.opencover*.xml" -targetdir:"$DIST/coverage" -reporttypes:"Cobertura;HTMLInline;HTMLChart;SonarQube" || echo -e "\033[33mWARNING: codecoverage not succesfull\033[0m"
# publish
echo "publishing $CS_PROJECT_FILE"
dotnet publish --configuration $RELEASE --output "$PROJECT_DIST" "$CS_PROJECT_FILE"
# copy deployment files over
if [ -d "deployment/" ]; then
echo "copying deployment files $CS_PROJECT_FILE"
cp -r deployment/ "$PROJECT_DIST"
fi
# generate artifacts dir
echo "generating artifacts"
zip -r "$ARTIFACTS_DIST/$CS_PROJECT_NAME.zip" "$PROJECT_DIST/"