Skip to content

Commit

Permalink
fix(install): prebuilt instruction (closes yetone#474) (yetone#476)
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
  • Loading branch information
aarnphm authored Sep 3, 2024
1 parent a5726bd commit 24b66e0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ https://github.com/user-attachments/assets/86140bfd-08b4-483d-a887-1b701d9e37dd

## Installation

For building binary if you wish to build from source, then `cargo` is required. Otherwise `curl` and `jq` will be used to get prebuilt binary from GitHub.

For prebuilt binary, one must set the following `GITHUB_TOKEN` in given shell (instruction for creating PAT is [here](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens))

<details open>

Expand All @@ -32,10 +35,9 @@ https://github.com/user-attachments/assets/86140bfd-08b4-483d-a887-1b701d9e37dd
opts = {
-- add any opts here
},
-- if you want to build from source, then pass source=true (requires cargo).
-- Also note that building from source will block startuptime since
-- we are compiling bindings in Rust.
build = ":AvanteBuild",
-- if you want to download pre-built binary, then pass source=false. Make sure to follow instruction above.
-- Also note that downloading prebuilt binary is a lot faster comparing to compiling from source.
build = ":AvanteBuild source=false",
dependencies = {
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
Expand Down Expand Up @@ -117,7 +119,7 @@ add({
'MunifTanjim/nui.nvim',
'echasnovski/mini.icons'
},
hooks = { post_checkout = function() vim.cmd('AvanteBuild') end }
hooks = { post_checkout = function() vim.cmd('AvanteBuild source=false') end }
})
--- optional
add({ source = 'zbirenbaum/copilot.lua' })
Expand Down
2 changes: 1 addition & 1 deletion autoload/avante.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function avante#build(...) abort
let l:source = get(a:, 1, v:false)
let l:source = get(a:, 1, v:true)
return join(luaeval("require('avante').build(_A)", l:source), "\n")
endfunction
28 changes: 22 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

set -eo pipefail

# Check if jq is installed
if ! command -v jq &>/dev/null; then
echo "Error: jq is not installed. Please install jq."
exit 1
fi

# Check if GITHUB_TOKEN is set
if [ -z "$GITHUB_TOKEN" ]; then
echo "Error: GITHUB_TOKEN is not set. Please provide a valid GitHub token."
exit 1
fi

REPO_OWNER="yetone"
REPO_NAME="avante.nvim"

Expand All @@ -11,9 +23,10 @@ SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
TARGET_DIR="${SCRIPT_DIR}/build"

# Get the latest successful run ID of the workflow
RUN_ID=$(curl -s -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows/build.yaml/runs?status=success&branch=main" |
\grep -oP '(?<="id": )\d+' | head -1)
RUN_ID=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/workflows/build.yaml/runs?status=success&branch=main&per_page=1" | jq ".workflow_runs[0].id")

# Get the artifact download URL based on the platform and Lua version
case "$(uname -s)" in
Expand All @@ -39,9 +52,12 @@ LUA_VERSION="${LUA_VERSION:-luajit}"
ARTIFACT_NAME_PATTERN="avante_lib-$PLATFORM-latest-$LUA_VERSION"

# Get the artifact download URL
ARTIFACT_URL=$(curl -s -H "Accept: application/vnd.github+json" \
ARTIFACT_URL=$(curl -s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs/$RUN_ID/artifacts" |
\grep -oP "(?<=\"archive_download_url\": \")https://[^\"]+/$ARTIFACT_NAME_PATTERN[^\"]+")
jq -r '.artifacts[] | select(.name | test("'"$ARTIFACT_NAME_PATTERN"'")) | .archive_download_url')

mkdir -p "$TARGET_DIR"
curl -L "$ARTIFACT_URL" | tar -xz -C "$TARGET_DIR" --strip-components=1

curl -L -H "Authorization: Bearer $GITHUB_TOKEN" "$ARTIFACT_URL" | tar -x -C "$TARGET_DIR"
2 changes: 1 addition & 1 deletion lua/avante/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ H.commands = function()
local key, value = arg:match("(%w+)=(%w+)")
if key and value then args[key] = value == "true" end
end
if args.source == nil then args.source = Config.debug and true or false end
if args.source == nil then args.source = true end

require("avante.api").build(args)
end, {
Expand Down

0 comments on commit 24b66e0

Please sign in to comment.