-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathupm_release.sh
145 lines (126 loc) · 3.92 KB
/
upm_release.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
#!/bin/bash
absolute_path() {
DIR="$(echo "$(cd "$(dirname "$1")"; pwd)")"
case $(basename $1) in
..) echo "$(dirname $DIR)";;
.) echo "$DIR";;
*) echo "$DIR/$(basename $1)";;
esac
}
# checking if a directory is provided
if [ -z "$1" ] ; then
echo "Please provide a directory to setup the sandbox. The directory should be outside analytics-csharp's directory"
echo "Usage: $0 <directory to setup sandbox>"
exit 1
fi
if ! [ -d "$1" ]; then
echo "$1 does not exist."
exit 1
fi
if [[ "$(absolute_path "$1")" = $PWD* ]]; then
echo "Please provide a directory outside analytics-csharp's directory"
exit 1
fi
cd "$1" || exit
echo "checking required tools..."
# checking required tools
if ! command -v git &> /dev/null
then
echo "git could not be found"
exit 1
fi
if ! command -v nuget &> /dev/null
then
echo "nuget could not be found"
exit 1
fi
if ! command -v jq &> /dev/null
then
echo "jq could not be found"
exit 1
fi
echo "looking for unity executable path..."
UNITY=$(find /Applications/Unity -type f -name 'Unity' | head -n 1)
echo "Unity executable found at $UNITY"
if [ -z "$UNITY" ]
then
echo "unity executable is not found. make sure you have installed unity"
exit
else
echo "Unity executable found at $UNITY"
fi
echo "setting up release sandbox ..."
rm -rf sandbox
mkdir -m 777 sandbox
cd sandbox
# download analytics-csharp, so it's isolated
git clone https://github.com/segmentio/Analytics-CSharp.git
cd Analytics-CSharp || exit
echo "fetching the current version of project ..."
VERSION=$(grep '<Version>' Analytics-CSharp/Analytics-CSharp.csproj | sed "s@.*<Version>\(.*\)</Version>.*@\1@")
echo "copy README.md ..."
README=$(<README.md)
echo "releasing version $VERSION ..."
git checkout upm
cd ..
echo "packing ..."
if [ "$(jq -r '.version' Analytics-CSharp/package.json)" == $VERSION ]
then
echo "$VERSION is the same as the current package version"
exit
fi
# update version in package.json
echo "$(jq --arg VERSION "$VERSION" '.version=$VERSION' Analytics-CSharp/package.json)" > Analytics-CSharp/package.json
echo "$README" > Analytics-CSharp/README.md
# remove all files in Plugins folder recursively
rm -rf Analytics-CSharp/Plugins/*
# download analytics-csharp and its dependencies from nuget
nuget install Segment.Analytics.CSharp -Version "$VERSION" -OutputDirectory Analytics-CSharp/Plugins
# remove dependencies that are not required
declare -a deps=(Analytics-CSharp/Plugins/Coroutine.NET.* Analytics-CSharp/Plugins/Serialization.NET.* Analytics-CSharp/Plugins/Sovran.NET.* Analytics-CSharp/Plugins/Segment.Analytics.CSharp.*)
for dir in Analytics-CSharp/Plugins/*; do
if [ -d "$dir" ]; then
in_deps=false
for dep in "${deps[@]}"; do
if [[ $dir == $dep ]]; then
in_deps=true
break
fi
done
if [ $in_deps == false ]; then
rm -rf "$dir"
fi
fi
done
# loop over all the libs and remove any non-netstandard1.3 libs
for dir in Analytics-CSharp/Plugins/*; do
if [ -d "$dir" ]; then
for lib in "$dir"/lib/*; do
if [ "$lib" != "$dir/lib/netstandard1.3" ]; then
echo $lib
rm -rf "$lib"
fi
done
fi
done
echo "generating meta files ..."
# launch unity to create a dummy head project
"$UNITY" -batchmode -quit -createProject dummy
# update the manifest of dummy head to import the package
echo "$(jq '.dependencies += {"com.segment.analytics.csharp": "file:../../Analytics-CSharp"}' dummy/Packages/manifest.json)" > dummy/Packages/manifest.json
# launch unity in quit mode to generate meta files
"$UNITY" -batchmode -quit -projectPath dummy
echo "releasing ..."
# commit all the changes
cd Analytics-CSharp || exit
git add .
git commit -m "prepare release $VERSION"
# create and push a new tag, openupm will pick up this new tag and release it automatically
git tag unity/"$VERSION"
git push && git push --tags
cd ..
echo "cleaning up"
# clean up sandbox
cd ..
rm -rf sandbox
echo "done!"