Repository navigation
Expand file tree
/
Copy pathBuildLinuxPackages.sh
More file actions
executable file
·200 lines (182 loc) · 5.59 KB
/
Copy pathBuildLinuxPackages.sh
File metadata and controls
executable file
·200 lines (182 loc) · 5.59 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
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
APP_NAME="PixelViewer"
FRAMEWORK="net11.0"
DEFAULT_RID_LIST=("linux-x64" "linux-arm64")
RID_LIST=()
CONFIG="Release"
TRIM_ASSEMBLIES="true"
READY_TO_RUN="false"
GENERATE_DIFF_PACKAGES="true"
RUN_TESTS="true"
TESTS_ONLY="false"
# Print usage of this script.
print_usage() {
echo "Usage: BuildLinuxPackages.sh [options]"
echo " "
echo "Options:"
echo " -h, --help Print this help message and exit."
echo " --config <name> Build configuration to use. (Default: $CONFIG)"
echo " --rid <rid> Runtime identifier to build package for, can be specified multiple times."
echo " Supported: ${DEFAULT_RID_LIST[*]}. (Default: all of them)"
echo " --no-trim Do not trim assemblies while publishing the application."
echo " --no-tests Do not run test cases before building packages."
echo " --tests-only Only run test cases without building packages."
echo " --no-diff-packages Do not generate diff packages."
}
# Parse arguments
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
print_usage
exit 0
;;
--config)
if [ -z "$2" ]; then
echo "Missing value of '--config'"
exit 1
fi
CONFIG="$2"
shift 2
;;
--rid)
if [ -z "$2" ]; then
echo "Missing value of '--rid'"
exit 1
fi
IS_RID_SUPPORTED="false"
for SUPPORTED_RID in "${DEFAULT_RID_LIST[@]}"; do
if [ "$SUPPORTED_RID" = "$2" ]; then
IS_RID_SUPPORTED="true"
break
fi
done
if [ "$IS_RID_SUPPORTED" = "false" ]; then
echo "Unsupported runtime identifier: $2"
echo "Supported runtime identifiers: ${DEFAULT_RID_LIST[*]}"
exit 1
fi
IS_RID_SELECTED="false"
for SELECTED_RID in "${RID_LIST[@]}"; do
if [ "$SELECTED_RID" = "$2" ]; then
IS_RID_SELECTED="true"
break
fi
done
if [ "$IS_RID_SELECTED" = "false" ]; then
RID_LIST+=("$2")
fi
shift 2
;;
--no-trim)
TRIM_ASSEMBLIES="false"
shift
;;
--no-tests)
RUN_TESTS="false"
shift
;;
--tests-only)
TESTS_ONLY="true"
shift
;;
--no-diff-packages)
GENERATE_DIFF_PACKAGES="false"
shift
;;
*)
echo "Unknown argument: $1"
echo " "
print_usage
exit 1
;;
esac
done
# Select all runtime identifiers if none of them was specified
if [ ${#RID_LIST[@]} -eq 0 ]; then
RID_LIST=("${DEFAULT_RID_LIST[@]}")
fi
# Check conflict between arguments
if [ "$TESTS_ONLY" = "true" ] && [ "$RUN_TESTS" = "false" ]; then
echo "Cannot specify both '--no-tests' and '--tests-only'"
exit 1
fi
echo "********** Start building $APP_NAME **********"
# Run test cases
if [ "$RUN_TESTS" = "true" ]; then
echo "Run test cases"
dotnet test $APP_NAME.Test -c $CONFIG
if [ "$?" != "0" ]; then
echo "Test cases failed"
exit 1
fi
fi
# Stop if only test cases need to be run
if [ "$TESTS_ONLY" = "true" ]; then
exit 0
fi
# Get application version
VERSION=$(dotnet run PackagingTool.cs -- get-current-version $APP_NAME/$APP_NAME.csproj)
if [ "$?" != "0" ]; then
echo "Unable to get version of $APP_NAME"
exit 1
fi
INFORMATIONAL_VERSION=$(dotnet run PackagingTool.cs -- get-current-informational-version $APP_NAME/$APP_NAME.csproj)
PACKAGE_VERSION=$VERSION
if [ ! -z "$INFORMATIONAL_VERSION" ]; then
PACKAGE_VERSION=$INFORMATIONAL_VERSION
fi
echo "Version: $VERSION ($PACKAGE_VERSION)"
if [ "$GENERATE_DIFF_PACKAGES" = "true" ]; then
PREV_VERSION=$(dotnet run PackagingTool.cs -- get-previous-version $APP_NAME/$APP_NAME.csproj $VERSION)
if [ ! -z "$PREV_VERSION" ]; then
echo "Previous version: $PREV_VERSION"
fi
fi
# Create output directory
if [[ ! -d "./Packages" ]]; then
echo "Create directory 'Packages'"
mkdir ./Packages
if [ "$?" != "0" ]; then
exit 1
fi
fi
if [[ ! -d "./Packages/$VERSION" ]]; then
echo "Create directory 'Packages/$VERSION'"
mkdir ./Packages/$VERSION
if [ "$?" != "0" ]; then
exit 1
fi
fi
# Build packages
for i in "${!RID_LIST[@]}"; do
RID=${RID_LIST[$i]}
echo " "
echo "[$RID]"
echo " "
# clean
rm -r ./$APP_NAME/bin/$CONFIG/$FRAMEWORK/$RID
dotnet restore $APP_NAME -r $RID
if [ "$?" != "0" ]; then
exit 1
fi
dotnet clean $APP_NAME -c $CONFIG -r $RID
if [ "$?" != "0" ]; then
exit 1
fi
# build
dotnet publish $APP_NAME -c $CONFIG -r $RID --self-contained true -p:PublishTrimmed=$TRIM_ASSEMBLIES -p:PublishReadyToRun=$READY_TO_RUN
if [ "$?" != "0" ]; then
exit 1
fi
# zip package
ditto -c -k --sequesterRsrc "./$APP_NAME/bin/$CONFIG/$FRAMEWORK/$RID/publish/" "./Packages/$VERSION/$APP_NAME-$PACKAGE_VERSION-$RID.zip"
if [ "$?" != "0" ]; then
exit 1
fi
done
# Generate diff packages
if [ "$GENERATE_DIFF_PACKAGES" = "true" ] && [ ! -z "$PREV_VERSION" ]; then
dotnet run PackagingTool.cs -- create-diff-packages linux $PREV_VERSION $VERSION
fi
# Generate package manifest
# dotnet run PackagingTool.cs -- create-package-manifest linux $APP_NAME $VERSION