diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 211ad2b65..c9d357ca6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -128,6 +128,12 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + # pull-requests: write —— 发版后给本版本包含的 PR 逐条留「Released in vX.Y.Z」 + # 评论(见下方 Comment "Released in" 步骤)。GitHub 原生那个侧栏 released 徽标 + # 判定用的是 PR 分支的原始 head commit,squash 合并会把它变成孤儿 commit → 徽标 + # 永远不显示(即便 squash 出的新 commit 能从 tag 到达也不行)。此权限用于发一条 + # 可见的时间线评论作为 squash 兼容的替代。 + pull-requests: write steps: - uses: actions/checkout@v6 with: @@ -287,6 +293,13 @@ jobs: done SECTIONS=$(node .github/scripts/changelog-sections.mjs < "$RAW") + # 复用上面已算好的 PR 列表(不再多打一次 API),抽出本版本包含的**去重** PR + # 号,持久化到 $RUNNER_TEMP,交给后面的「Comment "Released in"」步骤逐个留言。 + # 从 $RAW 里 type=='pr' 的行取第 2 列(PR number),排序去重。可能为空(纯直推 + # commit、无关联 PR)——那样评论步骤自然什么都不做。 + awk -F'\t' '$1=="pr"{print $2}' "$RAW" | sort -un > "$RUNNER_TEMP/released_prs.txt" + echo "PRs in this release: $(paste -sd' ' "$RUNNER_TEMP/released_prs.txt")" + { echo 'body<` 的评论,有就跳过。 + # - 只在有 PR 时动作;纯直推(released_prs.txt 为空)自然 no-op。 + continue-on-error: true + env: + GH_TOKEN: ${{ github.token }} + RELEASE_TAG: ${{ github.ref_name }} + run: | + PR_FILE="$RUNNER_TEMP/released_prs.txt" + if [ ! -s "$PR_FILE" ]; then + echo "No PRs associated with this release; nothing to comment." + exit 0 + fi + RELEASE_URL="https://github.com/${GITHUB_REPOSITORY}/releases/tag/${RELEASE_TAG}" + MARKER="" + # 从 FD 3 读 PR 列表(而非 stdin),避免循环体内的 gh 子进程吃掉 stdin 里剩余的 + # PR 行导致漏评论。 + while read -r pr <&3; do + [ -n "$pr" ] || continue + # 幂等检查:该 PR 是否已有本版本的「已发布」评论 + if gh api "repos/${GITHUB_REPOSITORY}/issues/${pr}/comments" \ + --jq '.[].body' 2>/dev/null | grep -qF "$MARKER"; then + echo "PR #${pr}: already has released-in ${RELEASE_TAG} comment, skipping." + continue + fi + BODY="${MARKER} + 🚀 Released in [**${RELEASE_TAG}**](${RELEASE_URL})" + if gh pr comment "$pr" --repo "$GITHUB_REPOSITORY" --body "$BODY" 2>/dev/null; then + echo "PR #${pr}: commented released-in ${RELEASE_TAG}." + else + echo "PR #${pr}: comment failed (non-fatal), continuing." >&2 + fi + done 3< "$PR_FILE" + - name: Note — desktop assets pending # Make the npm-first window visible in the run log: npm + Release are # live now; the macOS .dmg/.zip attach in the parallel attach-desktop-assets