forked from keith/pre-commit-buildifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetshas.sh
More file actions
executable file
·46 lines (38 loc) · 1.03 KB
/
getshas.sh
File metadata and controls
executable file
·46 lines (38 loc) · 1.03 KB
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
#!/usr/bin/env bash
set -euo pipefail
getsha() {
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$1"
else
shasum -a 256 "$1"
fi
}
readonly version="$1"
echo "readonly version=$version"
# List of operating systems and architectures
for os in darwin linux windows
do
for arch in amd64 arm64
do
# Skip arm64 for windows since there is no build for it
if [[ $os == windows && $arch == arm64 ]]; then
continue
fi
# Special handling for Windows to include ".exe" extension
if [[ $os == windows ]]; then
filename="buildifier-$os-$arch.exe"
else
filename="buildifier-$os-$arch"
fi
url="https://github.com/bazelbuild/buildtools/releases/download/$version/$filename"
bin=$(mktemp)
if ! curl --fail --silent -L "$url" -o "$bin"; then
echo "error: failed to download $url, is the version correct?"
exit 1
fi
sha=$(getsha "$bin" | cut -d ' ' -f 1)
echo "# shellcheck disable=SC2034"
echo "readonly ${os}_${arch}_sha=$sha"
rm -f "$bin"
done
done