-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathci.sh
executable file
·202 lines (178 loc) · 5.24 KB
/
ci.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
201
202
#!/usr/bin/env bash
set -Eeuxo pipefail
[[ "$RUNNER_OS" == 'Windows' ]] && IS_WIN=true || IS_WIN=false
BIN=$(pwd)/bin
EXT=""
$IS_WIN && EXT=".exe"
mkdir -p "$BIN"
is_exe() { [[ -x "$1/$2$EXT" ]] || command -v "$2" > /dev/null 2>&1; }
extract_exe() {
exe="$(find "${3:-dist-newstyle}" -type f -name "$1$EXT" | sort -g | tail -1)"
name="$(basename "$exe")"
echo "Copying $name to $2"
mkdir -p "$2"
cp -f "$exe" "$2/$name"
$IS_WIN || chmod +x "$2/$name"
}
retry() {
echo "Attempting with retry:" "$@"
local n=1
while true; do
if "$@"; then
break
else
if [[ $n -lt 3 ]]; then
sleep $n # don't retry immediately
((n++))
echo "Command failed. Attempt $n/3:"
else
echo "The command has failed after $n attempts."
return 1
fi
fi
done
}
setup_dist_bins() {
if $IS_WIN; then
is_exe "dist/bin" "saw" && return
else
is_exe "dist/bin" "saw" && is_exe "dist/bin" "saw-remote-api" && return
extract_exe "saw-remote-api" "dist/bin"
fi
extract_exe "saw" "dist/bin"
export PATH=$PWD/dist/bin:$PATH
echo "$PWD/dist/bin" >> "$GITHUB_PATH"
strip dist/bin/saw* || echo "Strip failed: Ignoring harmless error"
}
install_z3() {
is_exe "$BIN" "z3" && return
case "$RUNNER_OS" in
Linux) file="ubuntu-18.04.zip" ;;
macOS) file="osx-10.15.7.zip" ;;
Windows) file="win.zip" ;;
esac
curl -o z3.zip -sL "https://github.com/Z3Prover/z3/releases/download/z3-$Z3_VERSION/z3-$Z3_VERSION-x64-$file"
if $IS_WIN; then 7z x -bd z3.zip; else unzip z3.zip; fi
cp z3-*/bin/z3$EXT $BIN/z3$EXT
$IS_WIN || chmod +x $BIN/z3
rm z3.zip
}
install_cvc4() {
is_exe "$BIN" "cvc4" && return
version="${CVC4_VERSION#4.}" # 4.y.z -> y.z
case "$RUNNER_OS" in
Linux) file="x86_64-linux-opt" ;;
Windows) file="win64-opt.exe" ;;
macOS) file="macos-opt" ;;
esac
# Temporary workaround
if [[ "$RUNNER_OS" == "Linux" ]]; then
curl -o cvc4$EXT -sL "https://cvc4.cs.stanford.edu/downloads/builds/x86_64-linux-opt/unstable/cvc4-2020-08-18-x86_64-linux-opt"
else
curl -o cvc4$EXT -sL "https://github.com/CVC4/CVC4/releases/download/$version/cvc4-$version-$file"
fi
$IS_WIN || chmod +x cvc4$EXT
mv cvc4$EXT "$BIN/cvc4$EXT"
}
install_yices() {
is_exe "$BIN" "yices" && return
ext=".tar.gz"
case "$RUNNER_OS" in
Linux) file="pc-linux-gnu-static-gmp.tar.gz" ;;
macOS) file="apple-darwin18.7.0-static-gmp.tar.gz" ;;
Windows) file="pc-mingw32-static-gmp.zip" && ext=".zip" ;;
esac
curl -o "yices$ext" -sL "https://yices.csl.sri.com/releases/$YICES_VERSION/yices-$YICES_VERSION-x86_64-$file"
if $IS_WIN; then
7z x -bd "yices$ext"
mv "yices-$YICES_VERSION"/bin/*.exe "$BIN"
else
tar -xzf "yices$ext"
(cd "yices-$YICES_VERSION" && sudo ./install-yices)
fi
rm -rf "yices$ext" "yices-$YICES_VERSION"
}
build() {
ghc_ver="$(ghc --numeric-version)"
cp cabal.GHC-"$ghc_ver".config cabal.project.freeze
cabal v2-update
cabal v2-configure -j --enable-tests
git status --porcelain
if $IS_WIN; then
pkgs=(saw)
else
pkgs=(saw saw-remote-api)
fi
tee -a cabal.project.local > /dev/null < cabal.project.ci
if ! retry cabal v2-build "$@" "${pkgs[@]}"; then
if [[ "$RUNNER_OS" == "macOS" ]]; then
echo "Working around a dylib issue on macos by removing the cache and trying again"
cabal v2-clean
retry cabal v2-build "$@" "${pkgs[@]}"
else
return 1
fi
fi
}
build_abc() {
arch=X86_64
case "$RUNNER_OS" in
Linux) os="Linux" ;;
macOS) os="OSX" ;;
Windows) os="Windows" ;;
esac
(cd deps/abcBridge &&
scripts/build-abc.sh $arch $os &&
cp abc-build/abc $BIN/abc)
output path $BIN/abc
}
install_system_deps() {
install_z3 &
install_cvc4 &
install_yices &
wait
export PATH="$BIN:$PATH"
echo "$BIN" >> "$GITHUB_PATH"
is_exe "$BIN" z3 && is_exe "$BIN" cvc4 && is_exe "$BIN" yices
}
build_cryptol() {
is_exe "dist/bin" "cryptol" && return
(cd deps/cryptol &&
git submodule update --init &&
.github/ci.sh build)
}
bundle_files() {
mkdir -p dist dist/{bin,doc,examples,include,lib}
cp LICENSE README.md dist/
$IS_WIN || chmod +x dist/bin/*
cp doc/extcore.md dist/doc
cp doc/tutorial/sawScriptTutorial.pdf dist/doc/tutorial.pdf
cp doc/manual/manual.pdf dist/doc/manual.pdf
cp -r doc/tutorial/code dist/doc
cp intTests/jars/galois.jar dist/lib
cp -r deps/cryptol/lib/* dist/lib
cp -r examples/* dist/examples
}
sign() {
gpg --batch --import <(echo "$SIGNING_KEY")
fingerprint="$(gpg --list-keys | grep galois -a1 | head -n1 | awk '{$1=$1};1')"
echo "$fingerprint:6" | gpg --import-ownertrust
gpg --yes --no-tty --batch --pinentry-mode loopback --default-key "$fingerprint" --detach-sign -o "$1".sig --passphrase-file <(echo "$SIGNING_PASSPHRASE") "$1"
}
zip_dist() {
name="$1"
cp -r dist "$name"
tar -czf "$name".tar.gz "$name"
}
output() { echo "::set-output name=$1::$2"; }
ver() { grep Version saw-script.cabal | awk '{print $2}'; }
set_version() { output saw-version "$(ver)"; }
set_files() { output changed-files "$(files_since "$1" "$2")"; }
files_since() {
changed_since="$(git log -1 --before="@{$2}")"
files="${changed_since:+"$(git diff-tree --no-commit-id --name-only -r "$1" | xargs)"}"
echo "$files"
}
COMMAND="$1"
shift
"$COMMAND" "$@"