Skip to content

Commit 269718b

Browse files
authored
fix: powershell build script (#2237)
* fix: powershell build script * fix: downloading latest tag version * fix: Build.ps1 gh download latest tag release version
1 parent 436a02c commit 269718b

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

Build.ps1

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ $ErrorActionPreference = "Stop"
99
$ProgressPreference = "SilentlyContinue"
1010

1111
$BuildDir = "build"
12+
$REPO_OWNER = "yetone"
13+
$REPO_NAME = "avante.nvim"
1214

1315
function Build-FromSource($feature) {
1416
if (-not (Test-Path $BuildDir)) {
@@ -41,9 +43,7 @@ function Test-GHAuth {
4143
}
4244
}
4345

44-
function Download-Prebuilt($feature) {
45-
$REPO_OWNER = "yetone"
46-
$REPO_NAME = "avante.nvim"
46+
function Download-Prebuilt($feature, $tag) {
4747

4848
$SCRIPT_DIR = $PSScriptRoot
4949
# Set the target directory to clone the artifact
@@ -65,11 +65,12 @@ function Download-Prebuilt($feature) {
6565
$TempFile = Get-Item ([System.IO.Path]::GetTempFilename()) | Rename-Item -NewName { $_.Name + ".zip" } -PassThru
6666

6767
if ((Test-Command "gh") -and (Test-GHAuth)) {
68-
gh release download --repo "$REPO_OWNER/$REPO_NAME" --pattern "*$ARTIFACT_NAME_PATTERN*" --output $TempFile --clobber
68+
write-host "Using GitHub CLI to download artifacts..."
69+
gh release download $latestTag --repo "$REPO_OWNER/$REPO_NAME" --pattern "*$ARTIFACT_NAME_PATTERN*" --output $TempFile --clobber
6970
} else {
7071
# Get the artifact download URL
71-
$LATEST_RELEASE = Invoke-RestMethod -Uri "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest"
72-
$ARTIFACT_URL = $LATEST_RELEASE.assets | Where-Object { $_.name -like "*$ARTIFACT_NAME_PATTERN*" } | Select-Object -ExpandProperty browser_download_url
72+
$RELEASE = Invoke-RestMethod -Uri "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$tag"
73+
$ARTIFACT_URL = $RELEASE.assets | Where-Object { $_.name -like "*$ARTIFACT_NAME_PATTERN*" } | Select-Object -ExpandProperty browser_download_url
7374

7475
# Download and extract the artifact
7576
Invoke-WebRequest -Uri $ARTIFACT_URL -OutFile $TempFile
@@ -103,22 +104,15 @@ function Main {
103104
if ($latestTag -eq $builtTag -and $latestTag) {
104105
Write-Host "Local build is up to date. No download needed."
105106
} elseif ($latestTag -ne $builtTag -and $latestTag) {
106-
if (Test-Command "gh" -and Test-GHAuth) {
107-
gh release download $latestTag --repo "github.com/$REPO_OWNER/$REPO_NAME" --pattern "*$ARTIFACT_NAME_PATTERN*" --clobber --output - | tar -zxvf - -C $TARGET_DIR
108-
Save-Tag $latestTag
109-
} else {
110-
$ARTIFACT_URL = Invoke-RestMethod -Uri "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$latestTag" | Select-String -Pattern "browser_download_url" | ForEach-Object { $_.Matches.Groups[1].Value } | Where-Object { $_ -match $ARTIFACT_NAME_PATTERN }
111-
112-
Invoke-WebRequest -Uri $ARTIFACT_URL -OutFile "$TempFile"
113-
Expand-Archive -Path "$TempFile" -DestinationPath "$TARGET_DIR" -Force
114-
Remove-Item "$TempFile"
115-
Save-Tag $latestTag
116-
}
107+
Write-Host "Downloading prebuilt binaries $latestTag for $Version..."
108+
Download-Prebuilt $Version $latestTag
109+
Save-Tag $latestTag
117110
} else {
118111
cargo build --release --features=$Version
119112
Get-ChildItem -Path "target/release/avante_*.dll" | ForEach-Object {
120113
Copy-Item $_.FullName "build/$($_.Name)"
121114
}
115+
Save-Tag $latestTag
122116
}
123117
}
124118
Write-Host "Completed!"

0 commit comments

Comments
 (0)