diff --git a/Build.ps1 b/Build.ps1 index 5f8710c..c9db75f 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -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 } diff --git a/build.sh b/build.sh index 6c79c9a..6e5c032 100644 --- a/build.sh +++ b/build.sh @@ -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