From d92a4cff8dae2d9ba289c5a013e1ebe73ab8b0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E7=91=BE?= <74231782+sj817@users.noreply.github.com> Date: Sat, 18 Apr 2026 00:18:46 +0800 Subject: [PATCH] fix: zip absolute path, publish failure comment, pass publish_status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pr-publish-release.ts: Use resolve() for releaseDir to get absolute path; zip command runs with cwd=artifactDir so relative path was resolving wrong - build-pr.yml: Expose steps.publish.outcome as publish_status job output; pass PUBLISH_STATUS env to update-comment-result job - pr-build-result.ts: Read PUBLISH_STATUS, pass publishFailed to comment - comment.ts: Show '⚠️ Release 发布失败' section in PR comment when publish failed but installInfo is absent --- .github/scripts/lib/comment.ts | 13 ++++++++++++- .github/scripts/pr-build-result.ts | 6 +++++- .github/scripts/pr-publish-release.ts | 4 ++-- .github/workflows/build-pr.yml | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/scripts/lib/comment.ts b/.github/scripts/lib/comment.ts index e8b140b2..0966c77a 100644 --- a/.github/scripts/lib/comment.ts +++ b/.github/scripts/lib/comment.ts @@ -117,7 +117,8 @@ export function generateResultComment ( runId: string, repository: string, version?: string, - installInfo?: InstallInfo + installInfo?: InstallInfo, + publishFailed?: boolean ): string { const runUrl = `https://github.com/${repository}/actions/runs/${runId}`; const shortSha = formatSha(prSha); @@ -195,6 +196,16 @@ export function generateResultComment ( `> 📦 [查看 Release 页面](${installInfo.releaseUrl})`, '> ⚠️ 此为 PR 测试版本,约 24 小时后会被自动清理。' ); + } else if (publishFailed) { + lines.push( + '', + '---', + '', + '## ⚠️ Release 发布失败', + '', + '> ❌ PR Release 发布过程中出现错误,无法提供快速安装命令。', + `> 🔗 [查看构建日志](${runUrl}) 了解详情。` + ); } // 添加错误详情 diff --git a/.github/scripts/pr-build-result.ts b/.github/scripts/pr-build-result.ts index 6ebe30ee..1f9931e1 100644 --- a/.github/scripts/pr-build-result.ts +++ b/.github/scripts/pr-build-result.ts @@ -51,12 +51,16 @@ async function main (): Promise { // PR Release 信息(由 publish-pr-release job 传入) const installUrl = getEnv('INSTALL_URL'); const releaseUrl = getEnv('RELEASE_URL'); + const publishStatus = getEnv('PUBLISH_STATUS'); // 'success' | 'failure' | 'skipped' | '' const installInfo: InstallInfo | undefined = installUrl && releaseUrl ? { installUrl, releaseUrl } : undefined; + const publishFailed = publishStatus === 'failure'; if (installInfo) { console.log(`Install URL: ${installUrl}`); console.log(`Release URL: ${releaseUrl}\n`); + } else if (publishFailed) { + console.log('Publish status: FAILED\n'); } const github = new GitHubAPI(token); @@ -92,7 +96,7 @@ async function main (): Promise { }, ]; - const comment = generateResultComment(targets, prSha, runId, repository, version, installInfo); + const comment = generateResultComment(targets, prSha, runId, repository, version, installInfo, publishFailed); await github.createOrUpdateComment(owner, repo, prNumber, comment, COMMENT_MARKER); } diff --git a/.github/scripts/pr-publish-release.ts b/.github/scripts/pr-publish-release.ts index 498a4ccd..293ad397 100644 --- a/.github/scripts/pr-publish-release.ts +++ b/.github/scripts/pr-publish-release.ts @@ -19,7 +19,7 @@ import { execSync } from 'node:child_process'; import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from 'node:fs'; -import { join, basename } from 'node:path'; +import { join, basename, resolve } from 'node:path'; import { GitHubAPI, getEnv, setOutput } from './lib/github.ts'; interface AssetEntry { @@ -52,7 +52,7 @@ async function main (): Promise { console.log(` SHA: ${shortSha}\n`); const github = new GitHubAPI(token); - const releaseDir = './release-assets'; + const releaseDir = resolve('./release-assets'); // 使用绝对路径,避免 zip cwd 切换后相对路径解析错误 mkdirSync(releaseDir, { recursive: true }); // ---- 打包构建产物 ---- diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index caebddbd..2cdda9ba 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -304,6 +304,7 @@ jobs: # PR Release 信息(用于在评论中显示安装命令) INSTALL_URL: ${{ needs.publish-pr-release.outputs.install_url || '' }} RELEASE_URL: ${{ needs.publish-pr-release.outputs.release_url || '' }} + PUBLISH_STATUS: ${{ needs.publish-pr-release.outputs.publish_status || '' }} run: node --experimental-strip-types .github/scripts/pr-build-result.ts # --------------------------------------------------------------------------- @@ -321,6 +322,7 @@ jobs: release_url: ${{ steps.publish.outputs.release_url }} release_tag: ${{ steps.publish.outputs.release_tag }} install_url: ${{ steps.publish.outputs.install_url }} + publish_status: ${{ steps.publish.outcome }} # 'success' | 'failure' | 'skipped' steps: - name: Checkout scripts uses: actions/checkout@v5