ci: avoid cross-step env in Windows workflow
Some checks failed
Build Windows Release / Build Windows x64 Release (push) Failing after 25s

This commit is contained in:
luochen570
2026-05-30 21:29:49 +08:00
parent aa18669312
commit 2968dd7caa

View File

@@ -110,9 +110,6 @@ jobs:
$zipPath = Join-Path $sourceDir $zipName
$hash = (Get-FileHash $zipPath -Algorithm SHA256).Hash.ToLowerInvariant()
"$hash $zipName" | Out-File -FilePath "$zipPath.sha256" -Encoding ascii
"PACKAGE_ZIP=$zipPath" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
"PACKAGE_SHA256=$zipPath.sha256" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
"RELEASE_TAG=$version" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
Write-Host "Package: $zipPath"
Write-Host "SHA256: $hash"
@@ -120,9 +117,16 @@ jobs:
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
if (-not (Test-Path $env:PACKAGE_ZIP)) { throw "zip does not exist: $env:PACKAGE_ZIP" }
if (-not (Test-Path $env:PACKAGE_SHA256)) { throw "sha256 does not exist: $env:PACKAGE_SHA256" }
if ((Get-Item $env:PACKAGE_ZIP).Length -le 0) { throw "zip file is empty: $env:PACKAGE_ZIP" }
$shortSha = $env:GITHUB_SHA.Substring(0, 10)
$version = if ($env:GITHUB_REF_TYPE -eq 'tag') { $env:GITHUB_REF_NAME } else { "build-$shortSha" }
$zipName = "$env:PACKAGE_BASENAME-$version.zip"
$sourceDir = Join-Path $env:RUNNER_TEMP 'chengnan-work'
$zipPath = Join-Path $sourceDir $zipName
$shaPath = "$zipPath.sha256"
if (-not (Test-Path $zipPath)) { throw "zip does not exist: $zipPath" }
if (-not (Test-Path $shaPath)) { throw "sha256 does not exist: $shaPath" }
if ((Get-Item $zipPath).Length -le 0) { throw "zip file is empty: $zipPath" }
Write-Host "Verified package: $zipPath"
- name: Upload package to repository release
shell: powershell
@@ -134,11 +138,18 @@ jobs:
if ([string]::IsNullOrWhiteSpace($token)) { $token = $env:GITHUB_TOKEN }
if ([string]::IsNullOrWhiteSpace($token)) { throw 'Missing release token. Configure RELEASE_TOKEN in repository secrets or ensure GITHUB_TOKEN is available.' }
$shortSha = $env:GITHUB_SHA.Substring(0, 10)
$version = if ($env:GITHUB_REF_TYPE -eq 'tag') { $env:GITHUB_REF_NAME } else { "build-$shortSha" }
$zipName = "$env:PACKAGE_BASENAME-$version.zip"
$sourceDir = Join-Path $env:RUNNER_TEMP 'chengnan-work'
$zipPath = Join-Path $sourceDir $zipName
$shaPath = "$zipPath.sha256"
$serverUrl = if ($env:GITHUB_SERVER_URL) { $env:GITHUB_SERVER_URL.TrimEnd('/') } else { 'https://git.luochen570.cn' }
$repo = $env:GITHUB_REPOSITORY
$apiBase = "$serverUrl/api/v1/repos/$repo"
$tagName = $env:RELEASE_TAG
$releaseName = if ($env:GITHUB_REF_TYPE -eq 'tag') { $env:GITHUB_REF_NAME } else { "chengnan $($env:GITHUB_SHA.Substring(0, 10))" }
$tagName = $version
$releaseName = if ($env:GITHUB_REF_TYPE -eq 'tag') { $env:GITHUB_REF_NAME } else { "chengnan $shortSha" }
$isPrerelease = if ($env:GITHUB_REF_TYPE -eq 'tag') { $false } else { $true }
$headers = @{ Authorization = "token $token"; Accept = 'application/json' }
@@ -186,6 +197,6 @@ jobs:
Write-Host "Uploaded release asset: $name"
}
Upload-Asset $env:PACKAGE_ZIP
Upload-Asset $env:PACKAGE_SHA256
Upload-Asset $zipPath
Upload-Asset $shaPath
Write-Host "Release assets uploaded to $serverUrl/$repo/releases/tag/$tagName"