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