-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish_nuget.sh
156 lines (139 loc) · 3.67 KB
/
publish_nuget.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
#!/usr/bin/env bash
# Useful script to publish a C# NuGet package
PN_Version="1.0"
echo "Publish Nuget version $PN_Version"
echo ""
# Get absolute folder for this script
bu_pn_selfFolderPath="`cd "${BASH_SOURCE[0]%/*}"; pwd -P`/" # Command to get the absolute path
# Include util functions
. "${bu_pn_selfFolderPath}utils.sh"
# Default values
defaultOutputFolder="_publish"
defaultConfigType="Release"
# Parse variables
outputFolder="$defaultOutputFolder"
configType="$defaultConfigType"
nugetSource=""
nugetApiKey=""
libName=""
add_cmake_opt=()
while [ $# -gt 0 ]
do
case "$1" in
-h)
echo "Usage: publish_nuget.sh [options] -- [cmake options]"
echo "Everything passed after -- will be passed directly to the cmake command"
echo "Available options:"
echo " -h -> Display this help"
echo " -o <folder> -> Output folder (Default: ${defaultOutputFolder})"
echo " -c <config> -> Configuration type (Default: ${defaultConfigType})"
echo " -s <source> -> NuGet source (Mandatory)"
echo " -k <apiKey -> NuGet API key (Mandatory)"
echo " -l <libName> -> Library name (Mandatory)"
exit 3
;;
-o)
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -o option, see help (-h)"
exit 4
fi
outputFolder="$1"
;;
-c)
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -c option, see help (-h)"
exit 4
fi
configType="$1"
;;
-s)
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -s option, see help (-h)"
exit 4
fi
nugetSource="$1"
;;
-k)
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -k option, see help (-h)"
exit 4
fi
nugetApiKey="$1"
;;
-l)
shift
if [ $# -lt 1 ]; then
echo "ERROR: Missing parameter for -l option, see help (-h)"
exit 4
fi
libName="$1"
;;
--)
shift
while [ $# -gt 0 ]
do
# Ignore another "--" if present
if [ "$1" == "--" ]; then
shift
continue
fi
add_cmake_opt+=("$1")
shift
done
break
;;
*)
echo "ERROR: Unknown option '$1' (use -h for help)"
exit 4
;;
esac
shift
done
# Error if the output folder already exists
if [ -d $outputFolder ]; then
echo "Output folder already exists ($outputFolder). Please remove it before running this script."
exit 1
fi
# Error if the nugetSource is empty
if [ -z "$nugetSource" ]; then
echo "NuGet source is mandatory, please provide it using -s option."
exit 1
fi
# Error if the nugetApiKey is empty
if [ -z "$nugetApiKey" ]; then
echo "NuGet API key is mandatory, please provide it using -k option."
exit 1
fi
# Error if the libName is empty
if [ -z "$libName" ]; then
echo "Library name is mandatory, please provide it using -l option."
exit 1
fi
publishTargetName=${libName}-csharp-nuget-push
# Additional cmake parameters
add_cmake_opt+=("-DNUGET_PUBLISH_SOURCE_URL=$nugetSource" "-DNUGET_PUBLISH_API_KEY=$nugetApiKey")
# Additional gen_cmake parameters
declare -a params=()
# On windows, use x64 architecture
if isWindows; then
params+=("-arch" "x64")
# On macOS, use all archs and Ninja generator
elif isMac; then
# params+=("-all-archs") # Currently disabling multi-arch builds, until a solution is found to correctly generate multi-arch NuGet packages (assemblies)
params+=("-arch" "x64")
params+=("-c" "Ninja")
params+=("-${configType,,}")
# On Linux, use x64 architecture and Ninja generator
elif isLinux; then
params+=("-arch" "x64")
params+=("-c" "Ninja")
params+=("-${configType,,}")
fi
# Generate solution
$SHELL "${bu_pn_selfFolderPath}gen_cmake.sh" -o $outputFolder ${params[@]} -- "${add_cmake_opt[@]}"
# Build and publish
cmake --build $outputFolder --target $publishTargetName --config $configType