-
Notifications
You must be signed in to change notification settings - Fork 343
/
Copy pathbuild.sh
81 lines (65 loc) · 1.59 KB
/
build.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
#!/usr/bin/env bash
set -e
REPO_OWNER="yetone"
REPO_NAME="avante.nvim"
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
# Set the target directory to clone the artifact
TARGET_DIR="${SCRIPT_DIR}/build"
# Get the artifact download URL based on the platform and Lua version
case "$(uname -s)" in
Linux*)
PLATFORM="linux"
;;
Darwin*)
PLATFORM="darwin"
;;
CYGWIN* | MINGW* | MSYS*)
PLATFORM="windows"
;;
*)
echo "Unsupported platform"
exit 1
;;
esac
# Get the architecture (x86_64 or aarch64)
case "$(uname -m)" in
x86_64)
ARCH="x86_64"
;;
aarch64)
ARCH="aarch64"
;;
arm64)
ARCH="aarch64"
;;
*)
echo "Unsupported architecture"
exit 1
;;
esac
# Set the Lua version (lua54 or luajit)
LUA_VERSION="${LUA_VERSION:-luajit}"
# Set the artifact name pattern
ARTIFACT_NAME_PATTERN="avante_lib-$PLATFORM-$ARCH-$LUA_VERSION"
test_command() {
command -v "$1" >/dev/null 2>&1
}
test_gh_auth() {
if gh api user >/dev/null 2>&1; then
return 0
else
return 1
fi
}
if [ ! -d "$TARGET_DIR" ]; then
mkdir -p "$TARGET_DIR"
fi
if test_command "gh" && test_gh_auth; then
gh release download --repo "github.com/$REPO_OWNER/$REPO_NAME" --pattern "*$ARTIFACT_NAME_PATTERN*" --clobber --output - | tar -zxv -C "$TARGET_DIR"
else
# Get the artifact download URL
ARTIFACT_URL=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest" | grep "browser_download_url" | cut -d '"' -f 4 | grep $ARTIFACT_NAME_PATTERN)
set -x
mkdir -p "$TARGET_DIR"
curl -L "$ARTIFACT_URL" | tar -zxv -C "$TARGET_DIR"
fi