fix(release): dynamically locate Git and provide API zip archive fallback on Windows runner
Release Binaries & Installers / Build & Release Linux Binaries (push) Canceled after 0s
CI Test Suite / Run Component Tests & Pipeline Verification (push) Canceled after 1m34s
Release Binaries & Installers / Build & Release Windows Binaries & Installers (push) Canceled after 9m33s
Release Binaries & Installers / Build & Release Linux Binaries (push) Canceled after 0s
CI Test Suite / Run Component Tests & Pipeline Verification (push) Canceled after 1m34s
Release Binaries & Installers / Build & Release Windows Binaries & Installers (push) Canceled after 9m33s
This commit is contained in:
@@ -61,17 +61,53 @@ jobs:
|
||||
$server = "${{ github.server_url }}"
|
||||
$token = "${{ secrets.TAG_TOKEN || github.token }}"
|
||||
$repo = "${{ github.repository }}"
|
||||
$sha = "${{ github.sha }}"
|
||||
$cleanUrl = $server -replace "^https?://", ""
|
||||
$authUrl = "https://${token}@${cleanUrl}/${repo}.git"
|
||||
|
||||
if (-not (Test-Path ".git")) {
|
||||
git init
|
||||
git remote add origin $authUrl
|
||||
} else {
|
||||
git remote set-url origin $authUrl
|
||||
# Discover and append Git install paths to PATH if missing
|
||||
$gitCandidatePaths = @(
|
||||
"C:\Program Files\Git\cmd",
|
||||
"C:\Program Files\Git\bin",
|
||||
"C:\Program Files (x86)\Git\cmd",
|
||||
"C:\Program Files (x86)\Git\bin",
|
||||
"C:\ProgramData\chocolatey\bin",
|
||||
"$env:LOCALAPPDATA\Programs\Git\cmd"
|
||||
)
|
||||
foreach ($p in $gitCandidatePaths) {
|
||||
if ((Test-Path $p) -and ($env:PATH -notlike "*$p*")) {
|
||||
$env:PATH = "$p;$env:PATH"
|
||||
}
|
||||
}
|
||||
|
||||
$gitCmd = Get-Command "git" -ErrorAction SilentlyContinue
|
||||
if ($gitCmd) {
|
||||
Write-Host "[+] Found Git at $($gitCmd.Source)"
|
||||
if (-not (Test-Path ".git")) {
|
||||
& git init
|
||||
& git remote add origin $authUrl
|
||||
} else {
|
||||
& git remote set-url origin $authUrl
|
||||
}
|
||||
& git fetch --depth 1 origin $sha
|
||||
& git checkout -f FETCH_HEAD
|
||||
} else {
|
||||
Write-Host "[!] Git binary not found in PATH. Downloading repository archive via Gitea API..."
|
||||
$zipUrl = "$server/api/v1/repos/$repo/archive/$sha.zip"
|
||||
$headers = @{ "Authorization" = "token $token" }
|
||||
$zipPath = "$env:TEMP\repo_$sha.zip"
|
||||
$extractPath = "$env:TEMP\repo_extract_$sha"
|
||||
Invoke-RestMethod -Uri $zipUrl -Headers $headers -OutFile $zipPath -ErrorAction Stop
|
||||
Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force
|
||||
$inner = Get-ChildItem -Path $extractPath | Where-Object { $_.PSIsContainer } | Select-Object -First 1
|
||||
if ($inner) {
|
||||
Copy-Item -Path "$($inner.FullName)\*" -Destination "." -Recurse -Force
|
||||
} else {
|
||||
Copy-Item -Path "$extractPath\*" -Destination "." -Recurse -Force
|
||||
}
|
||||
Remove-Item -Path $zipPath, $extractPath -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Write-Host "[+] Repository successfully extracted from ZIP archive."
|
||||
}
|
||||
git fetch --depth 1 origin "${{ github.sha }}"
|
||||
git checkout -f FETCH_HEAD
|
||||
|
||||
- name: Install Dependencies
|
||||
shell: powershell
|
||||
|
||||
Reference in New Issue
Block a user