-
Notifications
You must be signed in to change notification settings - Fork 4
/
bisect.sh
executable file
·126 lines (110 loc) · 3.32 KB
/
bisect.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
#!/usr/bin/env bash
notice() {
cat <<EOF
notice:
* currently you have to edit this script for each use
maintenance status:
* this is somewhat rough, but hopefully already useful
* pull requests with improvements welcome
EOF
}
die () {
echo "$@"
exit 1
}
repo_dir=$(git rev-parse --show-toplevel) || die "Run this script in a Scala git checkout"
current () {
local sha=$(cat "$repo_dir/.git/BISECT_HEAD")
echo ${sha:0:10}
}
scalaVersion () {
local sha=$(current)
sha=${sha:0:7}
local artifact=$(curl -s "https://scala-ci.typesafe.com/artifactory/api/search/artifact?name=$sha" | jq -r '.results | .[] | .uri' | grep "/scala-compiler-.*-$sha.jar")
# scala version is in second-to-last column
# http://scala-ci.typesafe.com/artifactory/api/storage/scala-integration/org/scala-lang/scala-compiler/2.13.0-pre-d40e267/scala-compiler-2.13.0-pre-d40e267.jar
res=$(echo $artifact | awk -F/ '{print $(NF-1)}' 2> /dev/null)
echo $res
}
# Use `return` instead of `exit` to get some additional logging (using `exit` also works)
# Return 125 for commits that need to be skipped
run () {
local sha=$(current)
local num=$(git rev-list --parents -n 1 $sha | wc -w | tr -d ' ')
[[ $num -gt 2 ]] || {
echo "Not a merge commit: $sha"
return 125
}
local br="2.12.x"
local brs=$(git branch --contains $sha)
if $(grep 2.10.x <<< $brs > /dev/null) ; then
[[ "$br" == "2.10.x" ]] || {
echo "Merge commit from 2.10.x: $sha"
return 125
}
elif $(grep 2.11.x <<< $brs > /dev/null) ; then
[[ "$br" == "2.11.x" || "$br" == "2.10.x" ]] || {
echo "Merge commit from 2.11.x: $sha"
return 125
}
elif $(grep 2.12.x <<< $brs > /dev/null) ; then
[[ "$br" == "2.12.x" || "$br" == "2.11.x" || "$br" == "2.10.x" ]] || {
echo "Merge commit from 2.12.x: $sha"
return 125
}
elif $(grep 2.13.x <<< $brs > /dev/null) ; then
[[ "$br" == "2.13.x" || "$br" == "2.12.x" || "$br" == "2.11.x" || "$br" == "2.10.x" ]] || {
echo "Merge commit from 2.13.x: $sha"
return 125
}
fi
local sv=$(scalaVersion)
[[ ! -z "$sv" ]] || {
echo "Could not find artifact for $sha on scala-integration"
return 125
}
# local cp=$(coursier fetch -p -r https://scala-ci.typesafe.com/artifactory/scala-integration org.scala-lang:scala-compiler:$sv)
# [[ ! -z "$cp" ]] || {
# echo "Coursier failed to download Scala version $sv"
# return 125
# }
# ! java -cp $cp scala.tools.nsc.Main -usejavacp Test.scala 2>&1 | grep "unreachable code"
cd /Users/luc/Downloads/scala-sweble-bug
sbt "++$sv!" 'set resolvers += "scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/"' compile
}
if [[ $1 == "run-the-run" ]]; then
echo "=== TESTING $(current) ==="
cd "$2"
run
res=$?
case $res in
0)
echo "good: $(current)"
;;
125)
echo "skip: $(current)"
;;
*)
echo "bad: $(current)"
;;
esac
echo
exit $res
elif [[ $# -ne 2 ]]; then
notice
die "usage: $0 <good> <bad>"
else
notice
fi
good=$1
bad=$2
script_path="$(cd "$(dirname "$0")" ; pwd -P)/$(basename "$0")"
current_dir=$(pwd)
cd "$repo_dir"
# git fetch --quiet --all
git bisect start --no-checkout
git bisect good $good
git bisect bad $bad
git bisect run "$script_path" run-the-run "$current_dir"
git bisect log > "bisect_$good-$bad.log"
git bisect reset