-
Notifications
You must be signed in to change notification settings - Fork 0
/
set-packages.sh
executable file
·200 lines (170 loc) · 8.77 KB
/
set-packages.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
200
#!/bin/bash
# Path where we'll put the BeamableSource folder and make it into a nuget source feed
HOME_FOR_BUILD=${1:-$HOME_OVERRIDE}
HOME_FOR_BUILD=${HOME_FOR_BUILD:-$HOME}
# The name of the source in the format UNITY_|UNREAL_|WHATEVER_
SOURCE_NAME=${2-"BeamableNugetSource"}
# Look at PKG_ variables and separated by '|'
PACKAGES_TO_SET=${3:-''}
# Either "", "Local" or "Global"
INSTALL_CLI=${4:-""}
# When not "", this should be the absolute path we'll call dotnet restore in after the script has run
PATH_TO_DOTNET_RESTORE=${5:-""}
# This is used because we need to set the correct version for release flows in Github Actions
VERSION=${6:-"0.0.123"}
# Overridable via EnvVars only
PROJECTS_DIR=${PROJECT_DIR_OVERRIDE:-"ProjectsSource"}
PROJECTS_SOURCE="$HOME_FOR_BUILD/BeamableSource/"
PKG_COMMON="./cli/beamable.common/"
PKG_SERVER_COMMON="./cli/beamable.server.common/"
PKG_MICROSERVICE_TOOLING_COMMON="./microservice/beamable.tooling.common/"
PKG_MICROSERVICE_UNITY_ENGINE_STUBS="./microservice/unityEngineStubs/"
PKG_MICROSERVICE_UNITY_ENGINE_STUBS_ADDRESSABLES="./microservice/unityEngineStubs.addressables/"
PKG_CLI="./cli/cli"
PKG_MICROSERVICE="./microservice/microservice"
PKG_TEMPLATES="./templates"
PKG_MICROSERVICE_SOURCE_GEN="./templates/MicroserviceSourceGen/MicroserviceSourceGen"
PACKAGES_TO_SET_ARR[0]=$PKG_COMMON
PACKAGES_TO_SET_ARR[1]=$PKG_SERVER_COMMON
PACKAGES_TO_SET_ARR[2]=$PKG_MICROSERVICE_TOOLING_COMMON
PACKAGES_TO_SET_ARR[3]=$PKG_MICROSERVICE_UNITY_ENGINE_STUBS
PACKAGES_TO_SET_ARR[4]=$PKG_MICROSERVICE_UNITY_ENGINE_STUBS_ADDRESSABLES
PACKAGES_TO_SET_ARR[5]=$PKG_CLI
PACKAGES_TO_SET_ARR[6]=$PKG_MICROSERVICE
PACKAGES_TO_SET_ARR[7]=$PKG_TEMPLATES
PACKAGES_TO_SET_ARR[8]=$PKG_MICROSERVICE_SOURCE_GEN
if [[ "$PACKAGES_TO_SET" != "" ]]; then
echo "Filtering packages to set..."
unset PACKAGES_TO_SET_ARR
PACKAGES_TO_SET_ARR=$(echo $PACKAGES_TO_SET | tr "|" " ")
printf '%s, ' "${PACKAGES_TO_SET_ARR[@]}"
echo ""
fi
if [ ! -d "$PROJECTS_DIR" ]; then
echo "Creating projects source folder!"
mkdir "$PROJECTS_DIR"
else
echo "Projects source folder ($PROJECTS_DIR) already exists!"
fi
ls $PROJECTS_DIR
if [ ! -d "$PROJECTS_SOURCE" ]; then
echo "Creating source feed folder!"
mkdir "$PROJECTS_SOURCE"
else
echo "Projects source feed ($PROJECTS_SOURCE) already exists!"
fi
# Clean up the path so that it works on all OSs
if [[ $PROJECTS_SOURCE == *:* ]];then
case "$OSTYPE" in
solaris*) PROJECTS_SOURCE=$PROJECTS_SOURCE ;;
darwin*) PROJECTS_SOURCE=$PROJECTS_SOURCE ;;
linux*) PROJECTS_SOURCE=$PROJECTS_SOURCE ;;
bsd*) PROJECTS_SOURCE=$PROJECTS_SOURCE ;;
msys*) PROJECTS_SOURCE=${PROJECTS_SOURCE/\//\/\/} ;;
cygwin*) PROJECTS_SOURCE=${PROJECTS_SOURCE/\//\/\/} ;;
*) echo "Should never see this!!" ;;
esac
fi
# Clean up the path so that it works on all OSs
if [[ $PATH_TO_DOTNET_RESTORE == *:* ]];then
case "$OSTYPE" in
solaris*) PATH_TO_DOTNET_RESTORE=$PATH_TO_DOTNET_RESTORE ;;
darwin*) PATH_TO_DOTNET_RESTORE=$PATH_TO_DOTNET_RESTORE ;;
linux*) PATH_TO_DOTNET_RESTORE=$PATH_TO_DOTNET_RESTORE ;;
bsd*) PATH_TO_DOTNET_RESTORE=$PATH_TO_DOTNET_RESTORE ;;
msys*) PATH_TO_DOTNET_RESTORE=${PATH_TO_DOTNET_RESTORE/\//\/\/} ;;
cygwin*) PATH_TO_DOTNET_RESTORE=${PATH_TO_DOTNET_RESTORE/\//\/\/} ;;
*) echo "Should never see this!!" ;;
esac
fi
echo "I'm a fake nupkg that exist here so that our sample microservices' Dockerfile-BeamableDev can work properly." >> "$PROJECTS_SOURCE"/DONT_MIND_ME.nupkg
echo "Creating nupkg files for our packages"
## Check if we should be building each of the possible packages and then correctly build them (this grep is just a contain
## The "rm -rf" invalidates the nuget cache for the previous cached version of this package version
if printf '%s\0' "${PACKAGES_TO_SET_ARR[@]}" | grep -qwz "$PKG_COMMON"; then
dotnet pack "$PKG_COMMON" --configuration Release --include-source -o $PROJECTS_DIR -p:PackageVersion=$VERSION -p:InformationalVersion=$VERSION
rm -rf ~/.nuget/packages/beamable.common
fi
if printf '%s\0' "${PACKAGES_TO_SET_ARR[@]}" | grep -qwz "$PKG_SERVER_COMMON"; then
dotnet pack "$PKG_SERVER_COMMON" --configuration Release --include-source -o $PROJECTS_DIR -p:PackageVersion=$VERSION -p:InformationalVersion=$VERSION
rm -rf ~/.nuget/packages/beamable.tooling.common
fi
if printf '%s\0' "${PACKAGES_TO_SET_ARR[@]}" | grep -qwz "$PKG_MICROSERVICE_TOOLING_COMMON"; then
dotnet pack "$PKG_MICROSERVICE_TOOLING_COMMON" --configuration Release --include-source -o $PROJECTS_DIR -p:PackageVersion=$VERSION -p:InformationalVersion=$VERSION
rm -rf ~/.nuget/packages/beamable.server
fi
if printf '%s\0' "${PACKAGES_TO_SET_ARR[@]}" | grep -qwz "$PKG_MICROSERVICE_UNITY_ENGINE_STUBS"; then
dotnet pack "$PKG_MICROSERVICE_UNITY_ENGINE_STUBS" --configuration Release --include-source -o $PROJECTS_DIR -p:PackageVersion=$VERSION -p:InformationalVersion=$VERSION
rm -rf ~/.nuget/packages/beamable.unityengine
fi
if printf '%s\0' "${PACKAGES_TO_SET_ARR[@]}" | grep -qwz "$PKG_MICROSERVICE_UNITY_ENGINE_STUBS_ADDRESSABLES"; then
dotnet pack "$PKG_MICROSERVICE_UNITY_ENGINE_STUBS_ADDRESSABLES" --configuration Release --include-source -o $PROJECTS_DIR -p:PackageVersion=$VERSION -p:InformationalVersion=$VERSION
rm -rf ~/.nuget/packages/beamable.unity.addressables
fi
if printf '%s\0' "${PACKAGES_TO_SET_ARR[@]}" | grep -qwz "$PKG_CLI"; then
dotnet build "$PKG_CLI" --configuration Release -p:PackageVersion=$VERSION -p:CombinedVersion=$VERSION -p:InformationalVersion=$VERSION
dotnet pack "$PKG_CLI" --configuration Release --no-build --include-source -o $PROJECTS_DIR -p:PackageVersion=$VERSION -p:CombinedVersion=$VERSION -p:InformationalVersion=$VERSION
rm -rf ~/.nuget/packages/beamable.tools
fi
if printf '%s\0' "${PACKAGES_TO_SET_ARR[@]}" | grep -qwz "$PKG_MICROSERVICE"; then
dotnet build "$PKG_MICROSERVICE" --configuration Release -p:PackageVersion=$VERSION -p:CombinedVersion=$VERSION -p:InformationalVersion=$VERSION
dotnet pack "$PKG_MICROSERVICE" --configuration Release --no-build --include-source -o $PROJECTS_DIR -p:PackageVersion=$VERSION -p:CombinedVersion=$VERSION -p:InformationalVersion=$VERSION
rm -rf ~/.nuget/packages/beamable.microservice.runtime
fi
if printf '%s\0' "${PACKAGES_TO_SET_ARR[@]}" | grep -qwz "$PKG_MICROSERVICE_SOURCE_GEN"; then
dotnet build "$PKG_MICROSERVICE_SOURCE_GEN" --configuration Release -p:PackageVersion=$VERSION -p:CombinedVersion=$VERSION -p:InformationalVersion=$VERSION
dotnet pack "$PKG_MICROSERVICE_SOURCE_GEN" --configuration Release --no-build --include-source -o $PROJECTS_DIR -p:PackageVersion=$VERSION -p:CombinedVersion=$VERSION -p:InformationalVersion=$VERSION
rm -rf ~/.nuget/packages/beamable.microservice.sourcegen
fi
if printf '%s\0' "${PACKAGES_TO_SET_ARR[@]}" | grep -qwz "$PKG_TEMPLATES"; then
OUTPUT=$PROJECTS_DIR VERSION=$VERSION "$PKG_TEMPLATES"/build.sh
fi
# Print out the source list
echo "List of Sources"
dotnet nuget list source
if dotnet nuget list source | grep -q $SOURCE_NAME; then
echo "Source already exists!"
else
echo "Source does not exists!!"
echo "Setting the projects folder as a source folder for nuget"
echo "$PROJECTS_SOURCE"
echo "$SOURCE_NAME"
dotnet nuget add source "$PROJECTS_SOURCE" -n "$SOURCE_NAME"
echo "Added source $SOURCE_NAME bound to path $PROJECTS_SOURCE"
dotnet nuget list source
fi
echo "Pushing"
echo $PROJECTS_DIR
echo $PROJECTS_SOURCE
ls $PROJECTS_DIR
ls $PROJECTS_SOURCE
# Nuget push seems to need the actual files on windows (it doesn't automatically get all the files if you just pass in a directory)
# The $PACKAGE_SOURCE_SUFFIX_BLOB is set from the buildPR.yml file.
for i in `find $PROJECTS_DIR -name "*.nupkg" -type f`; do
echo "pushing nuget package $i to $SOURCE_NAME"
dotnet nuget push "$i" -s "$SOURCE_NAME"
done
dotnet nuget update source "$SOURCE_NAME"
## If we also want to install the CLI in our Engine Integration SDK Repo (this will install the CLI in the first found .config/dotnet-tools.json while walking up the hierarchy)
if [[ "$INSTALL_CLI" == "Local" ]];then
echo "Uninstalling CLI"
cd $PROJECTS_SOURCE..
dotnet tool uninstall beamable.tools || true
echo "Installing CLI"
dotnet new tool-manifest --force
dotnet tool install beamable.tools --version "$VERSION"
dotnet tool restore
fi
## If we also want to install the CLI
if [[ "$INSTALL_CLI" == "Global" ]];then
dotnet tool uninstall beamable.tools -g || true
dotnet tool install beamable.tools --global --version "$VERSION"
fi
## If we want to restore the project in a particular path...
if [[ "$PATH_TO_DOTNET_RESTORE" != "" ]];then
echo "Restoring project at $PATH_TO_DOTNET_RESTORE"
cd "$PROJECTS_SOURCE/.."
dotnet tool restore || true
cd "$PATH_TO_DOTNET_RESTORE"
dotnet restore || true
fi