forked from databricks/setup-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_snapshot.sh
executable file
·90 lines (76 loc) · 1.7 KB
/
setup_snapshot.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
#!/usr/bin/env bash
set -euo pipefail
# Synthesize the directory name for the snapshot build.
function cli_snapshot_directory() {
dir="cli"
# Append correct os name.
case $RUNNER_OS in
Linux)
dir="${dir}_linux"
;;
Windows)
dir="${dir}_windows"
;;
macOS)
dir="${dir}_darwin"
;;
esac
# Append correct arch name.
case $RUNNER_ARCH in
X86)
dir="${dir}_386"
;;
X64)
dir="${dir}_amd64_v1"
;;
ARM)
dir="${dir}_arm_6"
;;
ARM64)
dir="${dir}_arm64"
;;
esac
echo $dir
}
# Default to main branch if branch is not specified.
if [ -z "$BRANCH" ]; then
BRANCH=main
fi
# Find last successful build on $BRANCH.
last_successful_run_id=$(
gh run list -b "$BRANCH" -w release-snapshot --json 'databaseId,conclusion' |
jq 'limit(1; .[] | select(.conclusion == "success")) | .databaseId'
)
if [ -z "$last_successful_run_id" ]; then
echo "Unable to find last successful build"
exit 1
fi
# Determine artifact name with the right binaries for this runner.
case $RUNNER_OS in
Linux)
artifact="cli_linux_snapshot"
;;
Windows)
artifact="cli_windows_snapshot"
;;
macOS)
artifact="cli_darwin_snapshot"
;;
esac
# Change into temporary directory.
cd "$RUNNER_TEMP"
gh run download "$last_successful_run_id" -n "$artifact" -D .bin
dir="$PWD/.bin/$(cli_snapshot_directory)"
if [ ! -d "$dir" ]; then
echo "Directory does not exist: $dir"
exit 1
fi
if [ "$RUNNER_OS" == "Windows" ]; then
(
cd "$dir"
mv ./databricks.exe ./databricks
)
fi
# Add databricks to path.
chmod +x "$dir/databricks"
echo "$dir" >> "$GITHUB_PATH"