feat: download release only when needed (#1751)

* feat: download release only when needed in build.sh

* fix(build.sh): get latest tag time locally

* feat: download release only when needed in Build.ps1

* fix(build.sh): fix gt to ge
This commit is contained in:
xsy420
2025-03-28 10:23:27 +08:00
committed by GitHub
parent b6000d5bbc
commit ae9787d716
2 changed files with 22 additions and 2 deletions

View File

@@ -89,6 +89,20 @@ function Main {
Write-Host "Building for $Version..."
Build-FromSource $Version
} else {
$latestTag = git tag --sort=-creatordate | Select-Object -First 1
$latestTagTime = [int](git log -1 $latestTag --format=%at 2>&1 | Where-Object { $_ -match '^\d+$' })
$currentBuildTime = if ($buildFiles = Get-ChildItem -Path "build/avante_html2md*" -ErrorAction SilentlyContinue) {
[long](($buildFiles | ForEach-Object { $_.LastWriteTime } |
Measure-Object -Maximum).Maximum.Subtract([datetime]'1970-01-01').TotalSeconds)
} else {
$latestTagTime
}
if ($latestTagTime -lt $currentBuildTime) {
Write-Host "Local build is up to date. No download needed."
return
}
Write-Host "Downloading for $Version..."
Download-Prebuilt $Version
}

View File

@@ -66,9 +66,12 @@ if [ ! -d "$TARGET_DIR" ]; then
mkdir -p "$TARGET_DIR"
fi
if test_command "gh" && test_gh_auth; then
latest_tag_time=$(git tag --sort=-creatordate | xargs git log -1 --format=%at)
current_build_time=$(stat -c %Y build/avante_html2md* 2>/dev/null || echo "$latest_tag_time")
if [[ "$latest_tag_time" -ge "$current_build_time" ]]; then
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
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)
@@ -77,4 +80,7 @@ else
mkdir -p "$TARGET_DIR"
curl -L "$ARTIFACT_URL" | tar -zxv -C "$TARGET_DIR"
fi
else
echo "Local build is up to date. No download needed."
fi