From 2968dd7caa26226be45d2be0b136989c0167e49b Mon Sep 17 00:00:00 2001 From: luochen570 <1160510664@qq.com> Date: Sat, 30 May 2026 21:29:49 +0800 Subject: [PATCH] ci: avoid cross-step env in Windows workflow --- .gitea/workflows/build-windows-release.yml | 31 +++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/build-windows-release.yml b/.gitea/workflows/build-windows-release.yml index a3c4028..4a43e7e 100644 --- a/.gitea/workflows/build-windows-release.yml +++ b/.gitea/workflows/build-windows-release.yml @@ -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"