---
name: github-actions-release
description: GitHub Actions Release 工作流设计、权限配置与失败诊断能力单元。当涉及创建 Release job、遇到 403 权限错误、artifact 路径配置、用 MCP/curl 监控 Actions 状态、tag 触发发布流程时触发。关键词：GitHub Actions、Release、contents write、artifact、tag、发布、403、权限、Smithery、MCP、监控、CI 失败。
metadata:
  type: procedural
  category: engineering
  scope: generic
  role: skill-unit
title: github-actions-release
canonical_url: https://skilld.dev/gh/qiao-925/qiao-skills/github-actions-release
last_updated: 2026-09-28T18:03:37.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/workflow-template.yml](https://skilld.dev/api/skills-raw/qiao-925/qiao-skills/github-actions-release/references/workflow-template.yml).
>
> If the user asked to install this Skill, run `npx skilld install qiao-925/qiao-skills/github-actions-release`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/github-actions-release`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/qiao-925/qiao-skills/github-actions-release) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/github-actions-release`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/github-actions-release --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/github-actions-release --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# GitHub Actions Release

> 这个 skill-unit 处理的是"Release 工作流如何正确配置，失败时如何诊断和修复"的问题。核心价值：避免重复踩权限坑，提供可复用的诊断路径和监控命令模板。

## 负责与不负责

**负责：**
- Release job 权限配置规范
- 常见失败模式识别与修复
- Actions 状态诊断三段式
- 监控命令模板（curl / Smithery MCP）
- tag 触发发布的标准流程

**不负责：**
- 构建工具选型（PyInstaller、Docker 等）
- 代码打包逻辑
- 仓库结构设计

## 核心配置规范

### Release job 必须显式声明权限

```yaml
release:
  needs: build
  runs-on: ubuntu-latest
  if: startsWith(github.ref, 'refs/tags/')
  permissions:
    contents: write   # ← 缺少此项必然 403
```

`GITHUB_TOKEN` 默认权限为 read-only。`softprops/action-gh-release` 等 Release action 需要写权限，**不显式声明则 Create Release 步骤必然以 403 失败**，且错误信息不够直观，容易被误判为 token 问题。

### artifact 路径须与 upload 名称对齐

```yaml
# upload 阶段
- uses: actions/upload-artifact@v4
  with:
    name: MyApp-${{ matrix.name }}        # artifact 名
    path: dist/MyApp${{ matrix.ext }}     # 实际文件路径

# release 阶段下载后路径为：
# artifacts/MyApp-windows/MyApp.exe
# artifacts/MyApp-macos/MyApp
# artifacts/MyApp-linux/MyApp
```

upload 的 `name` 决定下载后的子目录名，release 的 `files` 路径必须与之完全对应。

## 失败诊断三段式

遇到 Actions 运行失败时，按以下顺序定位：

### Step 1：获取最新运行摘要

```bash
curl -s -H "Authorization: token $GH_TOKEN" \
  "https://api.github.com/repos/OWNER/REPO/actions/runs?per_page=5" | \
  python3 -c "
import json, sys
for r in json.load(sys.stdin)['workflow_runs']:
    print(r['id'], r['head_branch'], r['status'], r['conclusion'])
"
```

### Step 2：定位失败 job

```bash
curl -s -H "Authorization: token $GH_TOKEN" \
  "https://api.github.com/repos/OWNER/REPO/actions/runs/RUN_ID/jobs" | \
  python3 -c "
import json, sys
for j in json.load(sys.stdin)['jobs']:
    e = '✅' if j['conclusion']=='success' else '❌' if j['conclusion']=='failure' else '🔄'
    print(e, j['name'], '|', j['status'], '|', j.get('conclusion','...'))
"
```

### Step 3：查看失败 job 的 steps

定位到失败 job 后，检查其 `steps` 列表中哪一步 `conclusion == failure`，结合 step name 判断根因。

## 状态轮询监控模板

适用于推送 tag 后等待构建完成的场景：

```bash
RUN_ID="<从 Step 1 获取>"
for i in $(seq 1 20); do
  echo "=== $(date '+%H:%M:%S') ==="
  curl -s -H "Authorization: token $GH_TOKEN" \
    "https://api.github.com/repos/OWNER/REPO/actions/runs/$RUN_ID/jobs" | \
  python3 -c "
import json, sys
for j in json.load(sys.stdin)['jobs']:
    e = '✅' if j['conclusion']=='success' else '❌' if j['conclusion']=='failure' else '🔄' if j['status']=='in_progress' else '⏳'
    print(f'  {e} {j[\"name\"]} | {j[\"status\"]} | {j.get(\"conclusion\",\"...\")}')
"
  STATUS=$(curl -s -H "Authorization: token $GH_TOKEN" \
    "https://api.github.com/repos/OWNER/REPO/actions/runs/$RUN_ID" | \
    python3 -c "import json,sys; d=json.load(sys.stdin); print(d['status']+'|'+str(d['conclusion']))")
  echo "  整体: $STATUS"
  [[ "$STATUS" == completed* ]] && break
  sleep 30
done
```

## Smithery MCP 工具速查

通过 Smithery 连接 GitHub MCP 后，可用以下工具替代 curl：

```bash
# 列出工作流
smithery tool call github actions_list \
  '{"method": "list_workflows", "owner": "OWNER", "repo": "REPO"}'

# 列出最近运行
smithery tool call github actions_list \
  '{"method": "list_workflow_runs", "owner": "OWNER", "repo": "REPO", "per_page": 5}'

# 列出某次运行的 jobs
smithery tool call github actions_list \
  '{"method": "list_workflow_jobs", "owner": "OWNER", "repo": "REPO", "resource_id": "RUN_ID"}'

# 获取运行日志下载链接
smithery tool call github actions_get \
  '{"method": "get_workflow_run_logs_url", "owner": "OWNER", "repo": "REPO", "resource_id": "RUN_ID"}'

# 触发 workflow dispatch
smithery tool call github actions_run_trigger \
  '{"method": "run_workflow", "owner": "OWNER", "repo": "REPO", "workflow_id": "build.yml", "ref": "main"}'
```

**注意：** `rerun_workflow_run` 需要仓库写权限，Smithery OAuth 授权范围可能不包含，遇到 403 时改用重新推送 tag 触发。

## 标准发布流程

```bash
# 1. 确认代码已推送到主分支
git push origin main

# 2. 打 tag 并推送（触发 Actions）
git tag vX.Y.Z && git push origin vX.Y.Z

# 3. 等待触发（约 10s）后获取 run_id
sleep 10
curl -s -H "Authorization: token $GH_TOKEN" \
  "https://api.github.com/repos/OWNER/REPO/actions/runs?per_page=1" | \
  python3 -c "import json,sys; r=json.load(sys.stdin)['workflow_runs'][0]; print(r['id'], r['head_branch'], r['status'])"

# 4. 用轮询模板监控直到 completed
# 5. 验证 conclusion == success
```

## 常见失败模式速查

| 现象 | 根因 | 修复 |
|------|------|------|
| Create Release 步骤 403 | 缺少 `contents: write` 权限 | release job 添加 `permissions: contents: write` |
| Download artifact 找不到文件 | release `files` 路径与 upload `name` 不匹配 | 对齐路径：`artifacts/<upload-name>/<filename>` |
| Build 成功但 release job 未触发 | `if: startsWith(github.ref, 'refs/tags/')` 条件未满足 | 确认推送的是 tag 而非 branch |
| rerun 返回 403 | Smithery OAuth 权限不足 | 删除旧 tag，重新推送新 tag 触发 |

## 参考资料

- `references/workflow-template.yml` - 完整的跨平台构建 + Release 工作流模板
