From b0181edbd37c1d470d00eada8cb4c0a7270ec1d5 Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Fri, 28 Aug 2026 13:07:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DGitea=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=9E=84=E5=BB=BA=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/salon-prod-prepare.yml | 2 ++ docs/scripts/deploy-jayucloud-salon-production.ps1 | 12 ++++++++++-- docs/项目变更记录.md | 6 ++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/salon-prod-prepare.yml b/.gitea/workflows/salon-prod-prepare.yml index fd9503db..0300073a 100644 --- a/.gitea/workflows/salon-prod-prepare.yml +++ b/.gitea/workflows/salon-prod-prepare.yml @@ -14,6 +14,8 @@ jobs: github.event.pull_request.base.ref == 'prod' && github.event.pull_request.head.ref == 'sit' runs-on: jayucloud + env: + GITHUB_REF_NAME: prod steps: - name: 检出合并提交 uses: actions/checkout@v4 diff --git a/docs/scripts/deploy-jayucloud-salon-production.ps1 b/docs/scripts/deploy-jayucloud-salon-production.ps1 index 176fffd5..01a0040d 100644 --- a/docs/scripts/deploy-jayucloud-salon-production.ps1 +++ b/docs/scripts/deploy-jayucloud-salon-production.ps1 @@ -475,8 +475,16 @@ function Invoke-RemoteShellMany { function Test-GitState { Push-Location $resolvedRepoRoot try { - $commit = (& git rev-parse HEAD).Trim() - $branch = (& git branch --show-current).Trim() + $commitOutput = & git rev-parse HEAD + if ($LASTEXITCODE -ne 0 -or $null -eq $commitOutput) { + throw "无法读取当前 Git 提交号。" + } + $commit = ([string]$commitOutput).Trim() + $branchOutput = & git branch --show-current + $branch = if ($null -ne $branchOutput) { ([string]$branchOutput).Trim() } else { "" } + if (-not $branch) { + $branch = if ($env:GITHUB_REF_NAME) { ([string]$env:GITHUB_REF_NAME).Trim() } else { "DETACHED_HEAD" } + } $status = @(& git status --porcelain) if ($status.Count -gt 0) { Write-Warning "当前工作区有 $($status.Count) 个变更路径。" diff --git a/docs/项目变更记录.md b/docs/项目变更记录.md index e7285b76..d78ed18a 100644 --- a/docs/项目变更记录.md +++ b/docs/项目变更记录.md @@ -1,5 +1,11 @@ # 项目变更记录 +## 2026-08-28 修复 Gitea Detached HEAD 构建失败 + +- 修复 Gitea Actions 检出合并提交后处于 detached HEAD,`git branch --show-current` 返回空值导致 PowerShell `.Trim()` 空引用异常的问题。 +- `Test-GitState` 现在在 CI 中使用 `GITHUB_REF_NAME` 作为分支名,并在本地 detached HEAD 场景使用明确的 `DETACHED_HEAD` 标识。 +- Salon 生产准备工作流显式设置 `GITHUB_REF_NAME=prod`,保持合并提交构建行为不变。 + ## 2026-08-27 Gitea Runner 构建工具链修复 - 修复 `jayucloud` Runner 任务容器缺少 `pwsh` 导致 Salon 发布包构建失败的问题。