diff --git a/.github/scripts/lib/comment.ts b/.github/scripts/lib/comment.ts
index 3bec634b7..e8b140b24 100644
--- a/.github/scripts/lib/comment.ts
+++ b/.github/scripts/lib/comment.ts
@@ -3,6 +3,7 @@
*/
export const COMMENT_MARKER = '';
+export const DOCKER_COMMENT_MARKER = '';
export type BuildStatus = 'success' | 'failure' | 'cancelled' | 'pending' | 'unknown';
@@ -105,12 +106,18 @@ export function generateBuildingComment (prSha: string, targets: string[]): stri
// ============== 构建结果评论 ==============
+export interface InstallInfo {
+ installUrl: string;
+ releaseUrl: string;
+}
+
export function generateResultComment (
targets: BuildTarget[],
prSha: string,
runId: string,
repository: string,
- version?: string
+ version?: string,
+ installInfo?: InstallInfo
): string {
const runUrl = `https://github.com/${repository}/actions/runs/${runId}`;
const shortSha = formatSha(prSha);
@@ -173,6 +180,23 @@ export function generateResultComment (
`| 🕐 完成时间 | ${time} |`,
];
+ // 添加快速安装命令
+ if (installInfo) {
+ lines.push(
+ '',
+ '---',
+ '',
+ '## 🚀 快速安装 (Linux)',
+ '',
+ '```bash',
+ `curl -sSL ${installInfo.installUrl} | bash`,
+ '```',
+ '',
+ `> 📦 [查看 Release 页面](${installInfo.releaseUrl})`,
+ '> ⚠️ 此为 PR 测试版本,约 24 小时后会被自动清理。'
+ );
+ }
+
// 添加错误详情
const failedTargets = targets.filter(t => t.status === 'failure' && t.error);
if (failedTargets.length > 0) {
@@ -228,3 +252,138 @@ export function generateResultComment (
return lines.join('\n');
}
+
+// ============== Docker 构建评论 ==============
+
+export function generateDockerBuildingComment (prNumber: string, prSha: string): string {
+ const time = getTimeString();
+ const shortSha = formatSha(prSha);
+
+ const lines: string[] = [
+ DOCKER_COMMENT_MARKER,
+ '',
+ '
',
+ '',
+ '# 🐳 Docker 测试镜像构建中',
+ '',
+ '',
+ '',
+ '
',
+ '',
+ '---',
+ '',
+ '## 📋 构建信息',
+ '',
+ '| 项目 | 值 |',
+ '| :--- | :--- |',
+ `| 📝 提交 | \`${shortSha}\` |`,
+ `| 🔗 PR | #${prNumber} |`,
+ `| 🕐 触发时间 | ${time} |`,
+ '',
+ '---',
+ '',
+ '',
+ '',
+ '> ⏳ **Docker 镜像正在构建中,请稍候...**',
+ '>',
+ '> 构建完成后将自动更新此评论',
+ '',
+ '
',
+ ];
+
+ return lines.join('\n');
+}
+
+export function generateDockerResultComment (
+ prNumber: string,
+ prSha: string,
+ success: boolean,
+ dockerImage?: string,
+ error?: string
+): string {
+ const time = getTimeString();
+ const shortSha = formatSha(prSha);
+
+ const statusBadge = success
+ ? ''
+ : '';
+ const headerTitle = success ? '# ✅ Docker 测试镜像就绪' : '# ❌ Docker 测试镜像构建失败';
+
+ const lines: string[] = [
+ DOCKER_COMMENT_MARKER,
+ '',
+ '',
+ '',
+ headerTitle,
+ '',
+ statusBadge,
+ '',
+ '
',
+ '',
+ '---',
+ '',
+ '## 📋 构建信息',
+ '',
+ '| 项目 | 值 |',
+ '| :--- | :--- |',
+ `| 📝 提交 | \`${shortSha}\` |`,
+ `| 🔗 PR | #${prNumber} |`,
+ `| 🕐 完成时间 | ${time} |`,
+ ];
+
+ if (success && dockerImage) {
+ lines.push(
+ '',
+ '---',
+ '',
+ '## 🚀 快速使用',
+ '',
+ '```bash',
+ `docker pull ${dockerImage}`,
+ '```',
+ '',
+ '> ⚠️ 此为 PR 测试镜像,保留 7 天后自动清理。'
+ );
+ }
+
+ if (!success && error) {
+ lines.push(
+ '',
+ '---',
+ '',
+ '',
+ '🔴 错误详情
',
+ '',
+ '```',
+ escapeCodeBlock(error),
+ '```',
+ '',
+ ' '
+ );
+ }
+
+ lines.push('', '---', '');
+ if (success) {
+ lines.push(
+ '',
+ '',
+ '> 🎉 **Docker 测试镜像已就绪!**',
+ '>',
+ '> 使用上方命令拉取镜像进行测试',
+ '',
+ '
'
+ );
+ } else {
+ lines.push(
+ '',
+ '',
+ '> ⚠️ **Docker 镜像构建失败**',
+ '>',
+ '> 请检查错误详情',
+ '',
+ '
'
+ );
+ }
+
+ return lines.join('\n');
+}
diff --git a/.github/scripts/lib/github.ts b/.github/scripts/lib/github.ts
index 652a7f01e..3c21b36f7 100644
--- a/.github/scripts/lib/github.ts
+++ b/.github/scripts/lib/github.ts
@@ -31,6 +31,21 @@ export interface Artifact {
archive_download_url: string;
}
+export interface Release {
+ id: number;
+ tag_name: string;
+ name: string;
+ upload_url: string;
+ html_url: string;
+ created_at: string;
+}
+
+export interface ReleaseAsset {
+ id: number;
+ name: string;
+ browser_download_url: string;
+}
+
// ============== GitHub API Client ==========================
export class GitHubAPI {
@@ -150,6 +165,97 @@ export class GitHubAPI {
console.log('✓ Created new comment');
}
}
+
+ // ============== Release API ==============
+
+ async getReleaseByTag (owner: string, repo: string, tag: string): Promise {
+ try {
+ return await this.request(`/repos/${owner}/${repo}/releases/tags/${tag}`);
+ } catch {
+ return null;
+ }
+ }
+
+ async deleteRelease (owner: string, repo: string, releaseId: number): Promise {
+ await this.request(`/repos/${owner}/${repo}/releases/${releaseId}`, { method: 'DELETE' });
+ }
+
+ async deleteRef (owner: string, repo: string, ref: string): Promise {
+ try {
+ await this.request(`/repos/${owner}/${repo}/git/refs/${ref}`, { method: 'DELETE' });
+ } catch {
+ // ref may not exist, ignore
+ }
+ }
+
+ async createRelease (
+ owner: string,
+ repo: string,
+ tag: string,
+ name: string,
+ body: string,
+ prerelease = true
+ ): Promise {
+ return this.request(`/repos/${owner}/${repo}/releases`, {
+ method: 'POST',
+ body: JSON.stringify({ tag_name: tag, name, body, prerelease }),
+ headers: { 'Content-Type': 'application/json' },
+ });
+ }
+
+ async uploadReleaseAsset (
+ uploadUrl: string,
+ fileName: string,
+ data: Buffer,
+ contentType = 'application/octet-stream'
+ ): Promise {
+ const url = uploadUrl.replace(/\{[^}]*\}/g, '') + `?name=${encodeURIComponent(fileName)}`;
+ const response = await fetch(url, {
+ method: 'POST',
+ headers: {
+ Authorization: `Bearer ${this.token}`,
+ Accept: 'application/vnd.github+json',
+ 'Content-Type': contentType,
+ 'X-GitHub-Api-Version': '2022-11-28',
+ },
+ body: data,
+ });
+ if (!response.ok) {
+ throw new Error(`Upload ${fileName} failed: ${response.status} ${response.statusText}`);
+ }
+ return response.json() as Promise;
+ }
+
+ // ============== Dispatch API ==============
+
+ async repositoryDispatch (
+ owner: string,
+ repo: string,
+ eventType: string,
+ clientPayload: Record
+ ): Promise {
+ const response = await fetch(`${this.baseUrl}/repos/${owner}/${repo}/dispatches`, {
+ method: 'POST',
+ headers: {
+ Authorization: `Bearer ${this.token}`,
+ Accept: 'application/vnd.github+json',
+ 'X-GitHub-Api-Version': '2022-11-28',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ event_type: eventType, client_payload: clientPayload }),
+ });
+ if (!response.ok && response.status !== 204) {
+ throw new Error(`Dispatch failed: ${response.status} ${response.statusText}`);
+ }
+ }
+
+ // ============== Release Cleanup API ==============
+
+ async listReleases (owner: string, repo: string, perPage = 100, page = 1): Promise {
+ return this.request(
+ `/repos/${owner}/${repo}/releases?per_page=${perPage}&page=${page}`
+ );
+ }
}
// ============== Output 工具 ==============
diff --git a/.github/scripts/pr-build-result.ts b/.github/scripts/pr-build-result.ts
index 3af0ef9ca..6ebe30eeb 100644
--- a/.github/scripts/pr-build-result.ts
+++ b/.github/scripts/pr-build-result.ts
@@ -11,11 +11,13 @@
* - FRAMEWORK_ERROR: Framework 构建错误信息
* - SHELL_STATUS: Shell 构建状态
* - SHELL_ERROR: Shell 构建错误信息
+ * - INSTALL_URL: PR Release 安装脚本 URL (可选)
+ * - RELEASE_URL: PR Release 页面 URL (可选)
*/
import { GitHubAPI, getEnv, getRepository } from './lib/github.ts';
import { generateResultComment, COMMENT_MARKER } from './lib/comment.ts';
-import type { BuildTarget, BuildStatus } from './lib/comment.ts';
+import type { BuildTarget, BuildStatus, InstallInfo } from './lib/comment.ts';
function parseStatus (value: string | undefined): BuildStatus {
if (value === 'success' || value === 'failure' || value === 'cancelled') {
@@ -46,6 +48,17 @@ async function main (): Promise {
console.log(`Framework: ${frameworkStatus}${frameworkError ? ` (${frameworkError})` : ''}`);
console.log(`Shell: ${shellStatus}${shellError ? ` (${shellError})` : ''}\n`);
+ // PR Release 信息(由 publish-pr-release job 传入)
+ const installUrl = getEnv('INSTALL_URL');
+ const releaseUrl = getEnv('RELEASE_URL');
+ const installInfo: InstallInfo | undefined =
+ installUrl && releaseUrl ? { installUrl, releaseUrl } : undefined;
+
+ if (installInfo) {
+ console.log(`Install URL: ${installUrl}`);
+ console.log(`Release URL: ${releaseUrl}\n`);
+ }
+
const github = new GitHubAPI(token);
const repository = `${owner}/${repo}`;
@@ -79,7 +92,7 @@ async function main (): Promise {
},
];
- const comment = generateResultComment(targets, prSha, runId, repository, version);
+ const comment = generateResultComment(targets, prSha, runId, repository, version, installInfo);
await github.createOrUpdateComment(owner, repo, prNumber, comment, COMMENT_MARKER);
}
diff --git a/.github/scripts/pr-docker-dispatch.ts b/.github/scripts/pr-docker-dispatch.ts
new file mode 100644
index 000000000..182645bd9
--- /dev/null
+++ b/.github/scripts/pr-docker-dispatch.ts
@@ -0,0 +1,69 @@
+/**
+ * PR Build - 触发 NapCat-Docker 仓库构建 PR 测试镜像
+ *
+ * 功能:
+ * 1. 在 PR 中创建 Docker 构建中评论
+ * 2. 触发 NapCat-Docker 仓库的 repository_dispatch 事件
+ *
+ * 环境变量:
+ * DISPATCH_PAT - 具备目标仓库 dispatch 权限的 PAT
+ * GITHUB_TOKEN - GitHub API Token (用于写 PR 评论)
+ * PR_NUMBER - PR 编号
+ * PR_SHA - PR HEAD 提交 SHA
+ * PR_HEAD_REPO - PR 源仓库 (owner/repo)
+ * SOURCE_REPO - 当前仓库 (默认 NapNeko/NapCatQQ)
+ * RELEASE_REPO - PR release 仓库 (默认 NapNeko/napcat-pr-release)
+ * TARGET_REPO - Docker 仓库 (默认 NapNeko/NapCat-Docker)
+ */
+
+import { GitHubAPI, getEnv } from './lib/github.ts';
+import { generateDockerBuildingComment, DOCKER_COMMENT_MARKER } from './lib/comment.ts';
+
+async function main (): Promise {
+ console.log('🐳 Dispatching Docker build\n');
+
+ const token = getEnv('DISPATCH_PAT', true);
+ const githubToken = getEnv('GITHUB_TOKEN', true);
+ const prNumber = getEnv('PR_NUMBER', true);
+ const prSha = getEnv('PR_SHA', true);
+ const prHeadRepo = getEnv('PR_HEAD_REPO') || '';
+ const sourceRepo = getEnv('SOURCE_REPO') || 'NapNeko/NapCatQQ';
+ const releaseRepo = getEnv('RELEASE_REPO') || 'NapNeko/napcat-pr-release';
+ const targetRepo = getEnv('TARGET_REPO') || 'NapNeko/NapCat-Docker';
+
+ const [targetOwner, targetRepoName] = targetRepo.split('/');
+ const [sourceOwner, sourceRepoName] = sourceRepo.split('/');
+ const shortSha = prSha.substring(0, 7);
+
+ console.log(` PR: #${prNumber}`);
+ console.log(` SHA: ${shortSha}`);
+ console.log(` Target: ${targetRepo}`);
+ console.log(` Release: ${releaseRepo}\n`);
+
+ // 在 PR 中创建 Docker 构建中评论
+ console.log('💬 Creating Docker building comment...');
+ const prGithub = new GitHubAPI(githubToken);
+ const dockerComment = generateDockerBuildingComment(prNumber, prSha);
+ await prGithub.createOrUpdateComment(
+ sourceOwner, sourceRepoName, parseInt(prNumber, 10), dockerComment, DOCKER_COMMENT_MARKER
+ );
+
+ // 触发 Docker 仓库构建
+ const github = new GitHubAPI(token);
+
+ await github.repositoryDispatch(targetOwner, targetRepoName, 'napcatqq-pr-build', {
+ pr_number: prNumber,
+ pr_sha: prSha,
+ pr_short_sha: shortSha,
+ pr_head_repo: prHeadRepo,
+ source_repo: sourceRepo,
+ release_repo: releaseRepo,
+ });
+
+ console.log('✅ Dispatch succeeded');
+}
+
+main().catch((error) => {
+ console.error('❌ Error:', error);
+ process.exit(1);
+});
diff --git a/.github/scripts/pr-publish-release.ts b/.github/scripts/pr-publish-release.ts
new file mode 100644
index 000000000..498a4ccd4
--- /dev/null
+++ b/.github/scripts/pr-publish-release.ts
@@ -0,0 +1,164 @@
+/**
+ * PR Build - 发布构建产物到 napcat-pr-release 仓库
+ *
+ * 功能:
+ * 1. 将 CI 构建产物(Framework / Shell)打包为 zip
+ * 2. 从 NapCat-Installer 仓库拉取 install.sh 并替换下载链接
+ * 3. 发布到 napcat-pr-release 仓库的 GitHub Release
+ *
+ * 环境变量:
+ * RELEASE_PAT - 具备目标仓库 release 写权限的 PAT
+ * PR_NUMBER - PR 编号
+ * PR_SHA - PR HEAD 提交 SHA
+ * NAPCAT_VERSION - 构建版本号
+ * ARTIFACTS_DIR - 构建产物目录 (默认 ./artifacts)
+ * RELEASE_REPO - 发布仓库 (默认 NapNeko/napcat-pr-release)
+ * INSTALLER_REPO - 安装脚本仓库 (默认 NapNeko/NapCat-Installer)
+ * INSTALLER_BRANCH - 安装脚本分支 (默认 main)
+ */
+
+import { execSync } from 'node:child_process';
+import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from 'node:fs';
+import { join, basename } from 'node:path';
+import { GitHubAPI, getEnv, setOutput } from './lib/github.ts';
+
+interface AssetEntry {
+ name: string;
+ path: string;
+ contentType: string;
+}
+
+async function main (): Promise {
+ console.log('📦 PR Release Publisher\n');
+
+ const token = getEnv('RELEASE_PAT', true);
+ const prNumber = getEnv('PR_NUMBER', true);
+ const prSha = getEnv('PR_SHA', true);
+ const version = getEnv('NAPCAT_VERSION') || 'unknown';
+ const artifactsDir = getEnv('ARTIFACTS_DIR') || './artifacts';
+ const releaseRepo = getEnv('RELEASE_REPO') || 'NapNeko/napcat-pr-release';
+ const installerRepo = getEnv('INSTALLER_REPO') || 'NapNeko/NapCat-Installer';
+ const installerBranch = getEnv('INSTALLER_BRANCH') || 'main';
+
+ const [releaseOwner, releaseRepoName] = releaseRepo.split('/');
+ const shortSha = prSha.substring(0, 7);
+ const tag = `pr-${prNumber}-${shortSha}`;
+ const releaseName = `PR #${prNumber} (${shortSha})`;
+ const downloadBase = `https://github.com/${releaseRepo}/releases/download/${tag}`;
+
+ console.log(` Tag: ${tag}`);
+ console.log(` Repo: ${releaseRepo}`);
+ console.log(` Version: ${version}`);
+ console.log(` SHA: ${shortSha}\n`);
+
+ const github = new GitHubAPI(token);
+ const releaseDir = './release-assets';
+ mkdirSync(releaseDir, { recursive: true });
+
+ // ---- 打包构建产物 ----
+ const artifacts = ['NapCat.Framework', 'NapCat.Shell'];
+ for (const name of artifacts) {
+ const dir = join(artifactsDir, name);
+ if (existsSync(dir)) {
+ const zipPath = join(releaseDir, `${name}.zip`);
+ console.log(`📦 Packing ${name}...`);
+ execSync(`zip -qr "${zipPath}" .`, { cwd: dir, stdio: 'inherit' });
+ console.log(` ✓ ${name}.zip\n`);
+ } else {
+ console.log(` ⚠ ${name} 目录不存在,跳过\n`);
+ }
+ }
+
+ // ---- 拉取并修改安装脚本 ----
+ console.log('📜 Fetching install.sh...');
+ const scriptUrl = `https://raw.githubusercontent.com/${installerRepo}/${installerBranch}/script/install.sh`;
+ try {
+ const response = await fetch(scriptUrl);
+ if (response.ok) {
+ let script = await response.text();
+ // 替换下载链接(保留代理前缀 ${target_proxy:+${target_proxy}/})
+ const shellUrl = `${downloadBase}/NapCat.Shell.zip`;
+ const originalScript = script;
+ script = script.replace(
+ /napcat_download_url="\$\{target_proxy:\+\$\{target_proxy\}\/\}https:\/\/github\.com\/NapNeko\/NapCatQQ\/releases\/latest\/download\/NapCat\.Shell\.zip"/g,
+ `napcat_download_url="\${target_proxy:+\${target_proxy}/}${shellUrl}"`
+ );
+ if (script === originalScript) {
+ console.log(' ⚠ Warning: URL replacement did not match - install.sh format may have changed');
+ }
+ const scriptPath = join(releaseDir, 'install.sh');
+ writeFileSync(scriptPath, script, { mode: 0o755 });
+ console.log(` ✓ Patched download URL -> ${shellUrl}\n`);
+ } else {
+ console.log(` ⚠ Failed to fetch install.sh: ${response.status}\n`);
+ }
+ } catch (e) {
+ console.log(` ⚠ Failed to fetch install.sh: ${(e as Error).message}\n`);
+ }
+
+ // ---- 收集所有要上传的文件 ----
+ const assets: AssetEntry[] = [];
+ for (const file of readdirSync(releaseDir)) {
+ const ext = file.split('.').pop()?.toLowerCase();
+ const contentType = ext === 'zip' ? 'application/zip' : ext === 'sh' ? 'application/x-sh' : 'application/octet-stream';
+ assets.push({ name: file, path: join(releaseDir, file), contentType });
+ }
+ console.log(`📋 Assets to upload: ${assets.map(a => a.name).join(', ')}\n`);
+
+ // ---- 删除旧 release ----
+ console.log('🗑️ Checking for existing release...');
+ const existing = await github.getReleaseByTag(releaseOwner, releaseRepoName, tag);
+ if (existing) {
+ console.log(` Deleting existing release (id=${existing.id})...`);
+ await github.deleteRelease(releaseOwner, releaseRepoName, existing.id);
+ await github.deleteRef(releaseOwner, releaseRepoName, `tags/${tag}`);
+ console.log(' ✓ Deleted\n');
+ } else {
+ console.log(' No existing release\n');
+ }
+
+ // ---- 创建 Release ----
+ const releaseBody = [
+ `## NapCat PR #${prNumber} 测试版本`,
+ '',
+ `- **版本**: \`${version}\``,
+ `- **提交**: \`${prSha}\``,
+ `- **来源**: [NapCatQQ PR #${prNumber}](https://github.com/NapNeko/NapCatQQ/pull/${prNumber})`,
+ '',
+ '### 快速安装 (Linux)',
+ '',
+ '```bash',
+ `curl -sSL ${downloadBase}/install.sh | bash`,
+ '```',
+ '',
+ '> ⚠️ 此为 PR 测试版本,约 24 小时后会被自动清理。',
+ ].join('\n');
+
+ console.log('🚀 Creating release...');
+ const release = await github.createRelease(
+ releaseOwner, releaseRepoName, tag, releaseName, releaseBody, true
+ );
+ console.log(` ✓ Release created: ${release.html_url}\n`);
+
+ // ---- 上传资产 ----
+ console.log('📤 Uploading assets...');
+ for (const asset of assets) {
+ const data = readFileSync(asset.path);
+ const uploaded = await github.uploadReleaseAsset(
+ release.upload_url, asset.name, data, asset.contentType
+ );
+ console.log(` ✓ ${asset.name} -> ${uploaded.browser_download_url}`);
+ }
+
+ console.log(`\n✅ Release published: ${release.html_url}`);
+
+ // 输出供后续 job 使用
+ setOutput('release_url', release.html_url);
+ setOutput('release_tag', tag);
+ setOutput('install_url', `${downloadBase}/install.sh`);
+}
+
+main().catch((error) => {
+ console.error('❌ Error:', error);
+ process.exit(1);
+});
diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml
index f7274db30..05677e141 100644
--- a/.github/workflows/build-pr.yml
+++ b/.github/workflows/build-pr.yml
@@ -272,7 +272,7 @@ jobs:
# 使用 always() 确保即使构建失败/取消也会执行
# ---------------------------------------------------------------------------
update-comment-result:
- needs: [check-build, update-comment-building, build-framework, build-shell]
+ needs: [check-build, update-comment-building, build-framework, build-shell, publish-pr-release]
if: always() && needs.check-build.outputs.should_build == 'true'
runs-on: ubuntu-latest
steps:
@@ -301,4 +301,113 @@ jobs:
FRAMEWORK_ERROR: ${{ needs.build-framework.outputs.error }}
SHELL_STATUS: ${{ needs.build-shell.outputs.status || 'cancelled' }}
SHELL_ERROR: ${{ needs.build-shell.outputs.error }}
+ # PR Release 信息(用于在评论中显示安装命令)
+ INSTALL_URL: ${{ needs.publish-pr-release.outputs.install_url || '' }}
+ RELEASE_URL: ${{ needs.publish-pr-release.outputs.release_url || '' }}
run: node --experimental-strip-types .github/scripts/pr-build-result.ts
+
+ # ---------------------------------------------------------------------------
+ # Job 6: 发布 PR 构建产物到 napcat-pr-release 仓库
+ # ---------------------------------------------------------------------------
+ # 将所有构建产物打包 + 从 NapCat-Installer 拉取并修改安装脚本,
+ # 一起发布为 GitHub Release(公开可下载,无需登录)。
+ # Release 会由 napcat-pr-release 仓库的定时任务在 24h 后自动清理。
+ # ---------------------------------------------------------------------------
+ publish-pr-release:
+ needs: [check-build, build-framework, build-shell]
+ if: always() && needs.check-build.outputs.should_build == 'true' && (needs.build-framework.outputs.status == 'success' || needs.build-shell.outputs.status == 'success')
+ runs-on: ubuntu-latest
+ outputs:
+ release_url: ${{ steps.publish.outputs.release_url }}
+ release_tag: ${{ steps.publish.outputs.release_tag }}
+ install_url: ${{ steps.publish.outputs.install_url }}
+ steps:
+ - name: Checkout scripts
+ uses: actions/checkout@v5
+ with:
+ sparse-checkout: .github/scripts
+ sparse-checkout-cone-mode: false
+
+ - name: Setup Node.js 24
+ uses: actions/setup-node@v6
+ with:
+ node-version: 24
+
+ - name: Download Framework artifact
+ if: needs.build-framework.outputs.status == 'success'
+ uses: actions/download-artifact@v6
+ with:
+ name: NapCat.Framework
+ path: ./artifacts/NapCat.Framework
+
+ - name: Download Shell artifact
+ if: needs.build-shell.outputs.status == 'success'
+ uses: actions/download-artifact@v6
+ with:
+ name: NapCat.Shell
+ path: ./artifacts/NapCat.Shell
+
+ - name: Publish release
+ id: publish
+ continue-on-error: true
+ env:
+ RELEASE_PAT: ${{ secrets.PR_RELEASE_PAT }}
+ PR_NUMBER: ${{ needs.check-build.outputs.pr_number }}
+ PR_SHA: ${{ needs.check-build.outputs.pr_sha }}
+ NAPCAT_VERSION: ${{ needs.build-framework.outputs.version || needs.build-shell.outputs.version || '' }}
+ ARTIFACTS_DIR: ./artifacts
+ run: |
+ if [ -z "${RELEASE_PAT}" ]; then
+ echo "::warning::PR_RELEASE_PAT secret 未配置,跳过 PR Release 发布"
+ exit 0
+ fi
+ node --experimental-strip-types .github/scripts/pr-publish-release.ts
+
+ # 将修改后的安装脚本也上传为 CI artifact(自动过期)
+ - name: Upload install script as artifact
+ if: steps.publish.outcome == 'success'
+ uses: actions/upload-artifact@v6
+ with:
+ name: install-script
+ path: ./release-assets/install.sh
+ retention-days: 7
+ if-no-files-found: ignore
+
+ # ---------------------------------------------------------------------------
+ # Job 7: 触发 NapCat-Docker 仓库的 PR 测试镜像构建
+ # ---------------------------------------------------------------------------
+ # 仅当 Shell 构建成功、且 Release 已发布时触发。
+ # Docker 构建从公开 Release 下载产物,无需跨仓 artifact PAT。
+ # ---------------------------------------------------------------------------
+ trigger-docker:
+ needs: [check-build, build-shell, publish-pr-release]
+ if: needs.check-build.outputs.should_build == 'true' && needs.build-shell.outputs.status == 'success' && needs.publish-pr-release.outputs.release_tag != ''
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout scripts
+ uses: actions/checkout@v5
+ with:
+ sparse-checkout: .github/scripts
+ sparse-checkout-cone-mode: false
+
+ - name: Setup Node.js 24
+ uses: actions/setup-node@v6
+ with:
+ node-version: 24
+
+ - name: Dispatch docker build
+ continue-on-error: true
+ env:
+ DISPATCH_PAT: ${{ secrets.PR_RELEASE_PAT }}
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ PR_NUMBER: ${{ needs.check-build.outputs.pr_number }}
+ PR_SHA: ${{ needs.check-build.outputs.pr_sha }}
+ PR_HEAD_REPO: ${{ needs.check-build.outputs.pr_head_repo }}
+ SOURCE_REPO: ${{ github.repository }}
+ RELEASE_REPO: NapNeko/napcat-pr-release
+ run: |
+ if [ -z "${DISPATCH_PAT}" ]; then
+ echo "::warning::PR_RELEASE_PAT secret 未配置,跳过 Docker 测试镜像构建"
+ exit 0
+ fi
+ node --experimental-strip-types .github/scripts/pr-docker-dispatch.ts