forked from googleapis/google-cloud-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect-pr-changes.sh
executable file
·96 lines (79 loc) · 2.85 KB
/
detect-pr-changes.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
#!/bin/bash
set -e
if [[ -d "owl-bot-staging" ]]
then
echo "OwlBot post-processor has not run: failing diff."
exit 1
fi
ALLOW_BREAKING_CHANGES=
if [[ $1 == "--allow-breaking-changes" ]]
then
ALLOW_BREAKING_CHANGES=true
echo "(Breaking changes allowed during diff)"
fi
# Writes the argument to the console in bold magenta, to make it stand out.
log_header() {
echo -e "\e[1;35m$1\e[0m"
}
# Fails the whole script (exit code 1) if and only if ALLOW_BREAKING_CHANGES isn't true
maybe_fail() {
if [[ $ALLOW_BREAKING_CHANGES != "true" ]]
then
exit 1
else
echo -e "\e[1;31mWarning: breaking change detected, but the error has been suppressed by options.\e[0m"
fi
}
# Find the APIs that have changed, excluding ServiceDirectory (which isn't a real API)
apis=$(git diff main --name-only | grep -e 'apis/.*/' | cut -d/ -f 2 | grep -v '^ServiceDirectory$' | uniq)
if [[ "$apis" == "" ]]
then
log_header "No APIs have changed in this PR. Exiting diff."
exit 0
fi
git clone . tmpgit --no-local -q -b main --depth 1 --recursive
mkdir tmpgit/old
mkdir tmpgit/new
# First build everything, so we can get straight to the good stuff at the end of the log.
dotnet build -nologo -clp:NoSummary -v quiet tools/Google.Cloud.Tools.CompareVersions
dotnet build -nologo -clp:NoSummary -v quiet tools/Google.Cloud.Tools.ReleaseManager
for api in $apis
do
if [[ -d tmpgit/apis/$api/$api && -d apis/$api/$api ]]
then
# We expect almost all libraries to support netstandard2.1.
# When moving from GAX v3 to GAX v4 this will fail as we used to target
# netstandard2.0, but that's a single PR (which we expect to have breaking changes anyway).
targetVersion="netstandard2.1"
if [[ $api == "Google.Cloud.Diagnostics.AspNetCore3" ]]
then
targetVersion="netcoreapp3.1"
fi
log_header "Building $api"
apidir=apis/$api/$api
dotnet build -c Release -f $targetVersion -v quiet -nologo -clp:NoSummary -p:SourceLinkCreate=false tmpgit/$apidir
dotnet build -c Release -f $targetVersion -v quiet -nologo -clp:NoSummary -p:SourceLinkCreate=false $apidir
asm=apis/$api/$api/bin/Release/$targetVersion/$api.dll
cp tmpgit/$asm tmpgit/old
cp $asm tmpgit/new
fi
done
releasedApis=()
for api in $apis
do
log_header "Detecting changes for $api"
if [[ ! -d tmpgit/apis/$api/$api ]]
then
echo "$api is new"
elif [[ ! -d apis/$api/$api ]]
then
echo "$api was deleted"
else
releasedApis+=($api)
dotnet run --no-build --project tools/Google.Cloud.Tools.CompareVersions -- --file1=tmpgit/old/$api.dll --file2=tmpgit/new/$api.dll
fi
done
log_header "Checking compatibility with previous releases"
# Make sure all the tags are available for checking compatibility
git fetch --tags -q
dotnet run --no-build --project tools/Google.Cloud.Tools.ReleaseManager -- check-version-compatibility "${releasedApis[@]}" || maybe_fail