diff --git a/Build.ps1 b/Build.ps1 index 9ea78f6..327dbd2 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -9,6 +9,8 @@ $ErrorActionPreference = "Stop" $ProgressPreference = "SilentlyContinue" $BuildDir = "build" +$REPO_OWNER = "yetone" +$REPO_NAME = "avante.nvim" function Build-FromSource($feature) { if (-not (Test-Path $BuildDir)) { @@ -41,9 +43,7 @@ function Test-GHAuth { } } -function Download-Prebuilt($feature) { - $REPO_OWNER = "yetone" - $REPO_NAME = "avante.nvim" +function Download-Prebuilt($feature, $tag) { $SCRIPT_DIR = $PSScriptRoot # Set the target directory to clone the artifact @@ -65,11 +65,12 @@ function Download-Prebuilt($feature) { $TempFile = Get-Item ([System.IO.Path]::GetTempFilename()) | Rename-Item -NewName { $_.Name + ".zip" } -PassThru if ((Test-Command "gh") -and (Test-GHAuth)) { - gh release download --repo "$REPO_OWNER/$REPO_NAME" --pattern "*$ARTIFACT_NAME_PATTERN*" --output $TempFile --clobber + write-host "Using GitHub CLI to download artifacts..." + gh release download $latestTag --repo "$REPO_OWNER/$REPO_NAME" --pattern "*$ARTIFACT_NAME_PATTERN*" --output $TempFile --clobber } else { # Get the artifact download URL - $LATEST_RELEASE = Invoke-RestMethod -Uri "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest" - $ARTIFACT_URL = $LATEST_RELEASE.assets | Where-Object { $_.name -like "*$ARTIFACT_NAME_PATTERN*" } | Select-Object -ExpandProperty browser_download_url + $RELEASE = Invoke-RestMethod -Uri "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$tag" + $ARTIFACT_URL = $RELEASE.assets | Where-Object { $_.name -like "*$ARTIFACT_NAME_PATTERN*" } | Select-Object -ExpandProperty browser_download_url # Download and extract the artifact Invoke-WebRequest -Uri $ARTIFACT_URL -OutFile $TempFile @@ -103,22 +104,15 @@ function Main { if ($latestTag -eq $builtTag -and $latestTag) { Write-Host "Local build is up to date. No download needed." } elseif ($latestTag -ne $builtTag -and $latestTag) { - if (Test-Command "gh" -and Test-GHAuth) { - gh release download $latestTag --repo "github.com/$REPO_OWNER/$REPO_NAME" --pattern "*$ARTIFACT_NAME_PATTERN*" --clobber --output - | tar -zxvf - -C $TARGET_DIR - Save-Tag $latestTag - } else { - $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 } - - Invoke-WebRequest -Uri $ARTIFACT_URL -OutFile "$TempFile" - Expand-Archive -Path "$TempFile" -DestinationPath "$TARGET_DIR" -Force - Remove-Item "$TempFile" - Save-Tag $latestTag - } + Write-Host "Downloading prebuilt binaries $latestTag for $Version..." + Download-Prebuilt $Version $latestTag + Save-Tag $latestTag } else { cargo build --release --features=$Version Get-ChildItem -Path "target/release/avante_*.dll" | ForEach-Object { Copy-Item $_.FullName "build/$($_.Name)" } + Save-Tag $latestTag } } Write-Host "Completed!"