-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·188 lines (160 loc) · 4.38 KB
/
build.sh
File metadata and controls
executable file
·188 lines (160 loc) · 4.38 KB
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
#!/bin/bash
die () {
echo "$*" >&2
exit 1
}
make_absolute () {
case "$1" in
/*)
echo "$1"
;;
*)
echo "$PWD/$1"
;;
esac
}
#####################################################################
# Building
#####################################################################
echo "Building Packaging.Linux..."
# Parse script arguments
for i in "$@"
do
case "$i" in
--configuration=*)
CONFIGURATION="${i#*=}"
shift # past argument=value
;;
--version=*)
VERSION="${i#*=}"
shift # past argument=value
;;
--runtime=*)
RUNTIME="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
# Fall back to host architecture if no explicit runtime is given.
if test -z "$RUNTIME"; then
HOST_ARCH="`dpkg-architecture -q DEB_HOST_ARCH`"
case $HOST_ARCH in
amd64)
RUNTIME="linux-x64"
;;
arm64)
RUNTIME="linux-arm64"
;;
*)
die "Could not determine host architecture!"
;;
esac
fi
# Directories
THISDIR="$( cd "$(dirname "$0")" ; pwd -P )"
ROOT="$( cd "$THISDIR"/../../.. ; pwd -P )"
SRC="$ROOT/src"
OUT="$ROOT/out"
GCM_SRC="$SRC/shared/Git-Credential-Manager"
PROJ_OUT="$OUT/linux/Packaging.Linux"
# Build parameters
FRAMEWORK=netcoreapp3.1
case $RUNTIME in
linux-x64)
ARCH="amd64"
;;
linux-arm64)
ARCH="arm64"
;;
*)
die "Incompatible runtime architecture given for build.sh"
;;
esac
echo "Building for runtime ${RUNTIME} and arch ${ARCH}"
# Perform pre-execution checks
CONFIGURATION="${CONFIGURATION:=Debug}"
if [ -z "$VERSION" ]; then
die "--version was not set"
fi
# Outputs
PAYLOAD="$PROJ_OUT/payload/$CONFIGURATION"
SYMBOLOUT="$PROJ_OUT/payload.sym/$CONFIGURATION"
TAROUT="$PROJ_OUT/tar/$CONFIGURATION"
TARBALL="$TAROUT/gcmcore-linux_$ARCH.$VERSION.tar.gz"
SYMTARBALL="$TAROUT/symbols-linux_$ARCH.$VERSION.tar.gz"
DEBOUT="$PROJ_OUT/deb/$CONFIGURATION"
DEBROOT="$DEBOUT/root"
DEBPKG="$DEBOUT/gcmcore-linux_$ARCH.$VERSION.deb"
# Cleanup payload directory
if [ -d "$PAYLOAD" ]; then
echo "Cleaning existing payload directory '$PAYLOAD'..."
rm -rf "$PAYLOAD"
fi
# Cleanup symbol directory
if [ -d "$SYMBOLOUT" ]; then
echo "Cleaning existing symbols directory '$SYMBOLOUT'..."
rm -rf "$SYMBOLOUT"
fi
# Ensure directories exists
mkdir -p "$PAYLOAD" "$SYMBOLOUT" "$DEBROOT"
# Publish core application executables
echo "Publishing core application..."
dotnet publish "$GCM_SRC" \
--configuration="$CONFIGURATION" \
--framework="$FRAMEWORK" \
--runtime="$RUNTIME" \
--self-contained=true \
"/p:PublishSingleFile=True" \
--output="$(make_absolute "$PAYLOAD")" || exit 1
# Collect symbols
echo "Collecting managed symbols..."
mv "$PAYLOAD"/*.pdb "$SYMBOLOUT" || exit 1
echo "Build complete."
#####################################################################
# PACKING
#####################################################################
echo "Packing Packaging.Linux..."
# Cleanup any old archive files
if [ -e "$TAROUT" ]; then
echo "Deleteing old archive '$TAROUT'..."
rm "$TAROUT"
fi
# Ensure the parent directory for the archive exists
mkdir -p "$TAROUT" || exit 1
# Set full read, write, execute permissions for owner and just read and execute permissions for group and other
echo "Setting file permissions..."
/bin/chmod -R 755 "$PAYLOAD" || exit 1
# Build binaries tarball
echo "Building binaries tarball..."
pushd "$PAYLOAD"
tar -czvf "$TARBALL" * || exit 1
popd
# Build symbols tarball
echo "Building symbols tarball..."
pushd "$SYMBOLOUT"
tar -czvf "$SYMTARBALL" * || exit 1
popd
# Build .deb
INSTALL_TO="$DEBROOT/usr/bin/"
mkdir -p "$DEBROOT/DEBIAN" "$INSTALL_TO" || exit 1
# make the debian control file
cat >"$DEBROOT/DEBIAN/control" <<EOF
Package: gcmcore
Version: $VERSION
Section: vcs
Priority: optional
Architecture: $ARCH
Depends:
Maintainer: GCM-Core <gcmsupport@microsoft.com>
Description: Cross Platform Git Credential Manager Core command line utility.
GCM Core supports authentication with a number of Git hosting providers
including GitHub, BitBucket, and Azure DevOps.
For more information see https://aka.ms/gcmcore
EOF
# Copy single binary to target installation location
cp "$PAYLOAD/git-credential-manager-core" "$INSTALL_TO" || exit 1
dpkg-deb --build "$DEBROOT" "$DEBPKG" || exit 1
echo "Pack complete."