-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
executable file
·201 lines (152 loc) · 5.49 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash -e
# ----- Variables -------------------------------------------------------------
# Variables in the build.properties file will be available to Jenkins
# build steps. Variables local to this script can be defined below.
. ./build.properties
# -----------------------------------------------------------------------------
# fix for jenkins inserting the windows-style path in $WORKSPACE
cd "$WORKSPACE"
export WORKSPACE=`pwd`
# ----- Utility functions -----------------------------------------------------
function winpath() {
# Convert gitbash style path '/c/Users/Big John/Development' to 'c:\Users\Big John\Development',
# via dumb substitution. Handles drive letters; incurs process creation penalty for sed.
if [ -e /etc/bash.bashrc ] ; then
# Cygwin specific settings
echo "`cygpath -w $1`"
else
# Msysgit specific settings
echo "$1" | sed -e 's|^/\(\w\)/|\1:\\|g;s|/|\\|g'
fi
}
function bashpath() {
# Convert windows style path 'c:\Users\Big John\Development' to '/c/Users/Big John/Development'
# via dumb substitution. Handles drive letters; incurs process creation penalty for sed.
if [ -e /etc/bash.bashrc ] ; then
# Cygwin specific settings
echo "`cygpath $1`"
else
# Msysgit specific settings
echo "$1" | sed -e 's|\(\w\):|/\1|g;s|\\|/|g'
fi
}
function parentwith() { # used to find $WORKSPACE, below.
# Starting at the current dir and progressing up the ancestors,
# retuns the first dir containing $1. If not found returns pwd.
SEARCHTERM="$1"
DIR=`pwd`
while [ ! -e "$DIR/$SEARCHTERM" ]; do
NEWDIR=`dirname "$DIR"`
if [ "$NEWDIR" = "$DIR" ]; then
pwd
return
fi
DIR="$NEWDIR"
done
echo "$DIR"
}
# If we aren't running under jenkins. some variables will be unset.
# So set them to a reasonable value
if [ -z "$WORKSPACE" ]; then
export WORKSPACE=`parentwith .git`;
fi
TOOLSDIRS=". $WORKSPACE/GetBuildTools $WORKSPACE/v1_build_tools $WORKSPACE/../v1_build_tools $WORKSPACE/nuget_tools"
#TOOLSDIRS="."
for D in $TOOLSDIRS; do
if [ -d "$D/bin" ]; then
export BUILDTOOLS_PATH="$D/bin"
fi
done
echo $(which $BUILDTOOLS_PATH/NuGet.exe)
echo $(which $WORKSPACE/.nuget/NuGet.exe)
if [ ! $(which $BUILDTOOLS_PATH/NuGet.exe) ] && [ $(which $WORKSPACE/.nuget/NuGet.exe) ]; then
export BUILDTOOLS_PATH="$WORKSPACE/.nuget"
fi
echo "Using $BUILDTOOLS_PATH for NuGet"
if [ -z "$DOTNET_PATH" ]; then
for D in `bashpath "$SYSTEMROOT\\Microsoft.NET\\Framework\\v*"`; do
if [ -d $D ]; then
export DOTNET_PATH="$D"
fi
done
fi
echo "Using $DOTNET_PATH for .NET"
export PATH="$PATH:$BUILDTOOLS_PATH:$DOTNET_PATH"
if [ -z "$SIGNING_KEY_DIR" ]; then
export SIGNING_KEY_DIR=`pwd`;
fi
export SIGNING_KEY="$SIGNING_KEY_DIR/VersionOne.snk"
if [ -f "$SIGNING_KEY" ]; then
export SIGN_ASSEMBLY="true"
else
export SIGN_ASSEMBLY="false"
echo "Please place VersionOne.snk in `pwd` or $SIGNING_KEY_DIR to enable signing.";
fi
if [ -z "$VERSION_NUMBER" ]; then
export VERSION_NUMBER="0.0.0"
fi
if [ -z "$BUILD_NUMBER" ]; then
# presume local workstation, use date-based build number
export BUILD_NUMBER=`date +%H%M` # hour + minute
fi
function update_nuget_deps() {
install_nuget_deps
NuGet.exe update $SOLUTION_FILE -Verbose -Source $NUGET_FETCH_URL
}
function install_nuget_deps() {
PKGSDIRW=`winpath "$WORKSPACE/packages"`
for D in $WORKSPACE/*; do
if [ -d $D ] && [ -f $D/packages.config ]; then
PKGSCONFIGW=`winpath "$D/packages.config"`
NuGet.exe install "$PKGSCONFIGW" -o "$PKGSDIRW" -Source "$NUGET_FETCH_URL"
fi
done
}
# ---- Produce .NET Metadata -------------------------------------------------
COMPONENTS="VersionOne.Integration.JIRA"
for COMPONENT_NAME in $COMPONENTS; do
cat > "$WORKSPACE/$COMPONENT_NAME/Properties/AssemblyInfo.cs" <<EOF
// Auto generated by build.sh at `date -u`
using System;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyVersion("$VERSION_NUMBER.$BUILD_NUMBER")]
[assembly: AssemblyFileVersion("$VERSION_NUMBER.$BUILD_NUMBER")]
[assembly: AssemblyInformationalVersion("See $GITHUB_WEB_URL/wiki")]
[assembly: AssemblyProduct("$COMPONENT_NAME")]
[assembly: AssemblyTitle("$COMPONENT_NAME")]
[assembly: AssemblyDescription("$PRODUCT_NAME $COMPONENT_NAME $Configuration Build")]
[assembly: AssemblyCompany("$ORGANIZATION_NAME")]
[assembly: AssemblyCopyright("Copyright $COPYRIGHT_RANGE, $ORGANIZATION_NAME, Licensed under modified BSD.")]
[assembly: AssemblyConfiguration("$Configuration")]
EOF
done
# ---- Clean solution ---------------------------------------------------------
rm -rf $WORKSPACE/*.nupkg
MSBuild.exe $SOLUTION_FILE -m \
-t:Clean \
-p:Configuration="$Configuration" \
-p:Platform="$Platform" \
-p:Verbosity=Diagnostic
# ---- Update NuGet Packages --------------------------------------------------
# Suspending update
# update_nuget_deps
install_nuget_deps
# ---- Build solution using msbuild -------------------------------------------
WIN_SIGNING_KEY="`winpath "$SIGNING_KEY"`"
MSBuild.exe $SOLUTION_FILE \
-p:SignAssembly=$SIGN_ASSEMBLY \
-p:AssemblyOriginatorKeyFile=$WIN_SIGNING_KEY \
-p:RequireRestoreConsent=false \
-p:Configuration="$Configuration" \
-p:Platform="$Platform" \
-p:Verbosity=Diagnostic
# ---- Produce NuGet .nupkg file ----------------------------------------------------------
unset Platform
cd $WORKSPACE/$MAIN_DIR
NuGet.exe pack $MAIN_CSPROJ \
-Symbols \
-Properties Configuration="$Configuration"
cd $WORKSPACE