| 1 | name: Prepare release |
| 2 | |
| 3 | on: |
| 4 | workflow_dispatch: |
| 5 | inputs: |
| 6 | version: |
| 7 | description: "Official version without a tag prefix (for example 1.20.0)" |
| 8 | required: true |
| 9 | type: string |
| 10 | |
| 11 | permissions: |
| 12 | contents: write |
| 13 | pull-requests: write |
| 14 | |
| 15 | jobs: |
| 16 | draft: |
| 17 | name: generate reviewable bilingual draft |
| 18 | runs-on: ubuntu-latest |
| 19 | steps: |
| 20 | - uses: actions/checkout@v7 |
| 21 | with: |
| 22 | fetch-depth: 0 |
| 23 | |
| 24 | - uses: actions/setup-node@v7 |
| 25 | with: |
| 26 | node-version: "22" |
| 27 | |
| 28 | - name: Select the review branch |
| 29 | env: |
| 30 | GH_TOKEN: ${{ github.token }} |
| 31 | VERSION: ${{ inputs.version }} |
| 32 | run: | |
| 33 | set -euo pipefail |
| 34 | git config user.name "github-actions[bot]" |
| 35 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 36 | git fetch origin main-v2 |
| 37 | |
| 38 | if [[ ! "$VERSION" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then |
| 39 | echo "::error::version must be MAJOR.MINOR.PATCH" |
| 40 | exit 1 |
| 41 | fi |
| 42 | branch="release-notes/v${VERSION}" |
| 43 | if git ls-remote --exit-code --heads origin "$branch" >/dev/null 2>&1; then |
| 44 | git fetch origin "refs/heads/$branch:refs/remotes/origin/$branch" |
| 45 | git checkout -b "$branch" --track "origin/$branch" |
| 46 | git merge --no-edit origin/main-v2 |
| 47 | else |
| 48 | git checkout -b "$branch" |
| 49 | fi |
| 50 | echo "RELEASE_NOTES_BRANCH=$branch" >> "$GITHUB_ENV" |
| 51 | |
| 52 | - name: Generate and validate release notes |
| 53 | env: |
| 54 | DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }} |
| 55 | DEEPSEEK_MODEL: deepseek-v4-pro |
| 56 | GH_TOKEN: ${{ github.token }} |
| 57 | VERSION: ${{ inputs.version }} |
| 58 | run: | |
| 59 | set -euo pipefail |
| 60 | node scripts/generate-release-notes.mjs --version "$VERSION" |
| 61 | node scripts/release-notes.mjs validate |
| 62 | node --test scripts/release-notes.test.mjs |
| 63 | node scripts/release-notes.mjs render --version "$VERSION" --output /tmp/release-notes.md |
| 64 | { |
| 65 | echo "## Review draft for v${VERSION#v}" |
| 66 | echo |
| 67 | cat /tmp/release-notes.md |
| 68 | } >> "$GITHUB_STEP_SUMMARY" |
| 69 | |
| 70 | - name: Open or update the review PR |
| 71 | env: |
| 72 | GH_TOKEN: ${{ github.token }} |
| 73 | VERSION: ${{ inputs.version }} |
| 74 | run: | |
| 75 | set -euo pipefail |
| 76 | git add release-notes/releases.json |
| 77 | if ! git diff --cached --quiet; then |
| 78 | git commit -m "docs(release): prepare v${VERSION#v} notes" \ |
| 79 | -m "Summary: |
| 80 | Generate a bilingual, product-focused draft from merged pull request metadata. Reuse the selected release-bound PR when one is available. |
| 81 | |
| 82 | Verification: |
| 83 | Validate the catalog, citations, bilingual fields, and rendered GitHub release notes before committing." |
| 84 | fi |
| 85 | git push -u origin "$RELEASE_NOTES_BRANCH" |
| 86 | if ! gh pr list --head "$RELEASE_NOTES_BRANCH" --state open --json number --jq 'length > 0' | grep -q true; then |
| 87 | if ! gh pr create \ |
| 88 | --base main-v2 \ |
| 89 | --head "$RELEASE_NOTES_BRANCH" \ |
| 90 | --title "docs(release): 准备 v${VERSION#v} 中英更新日志" \ |
| 91 | --body-file /tmp/release-notes.md; then |
| 92 | echo "::warning::GitHub Actions could not open the PR; the reviewed branch is preserved." |
| 93 | { |
| 94 | echo "## Manual PR handoff" |
| 95 | echo |
| 96 | echo '```sh' |
| 97 | echo "gh pr create --repo ${{ github.repository }} --base main-v2 --head $RELEASE_NOTES_BRANCH --fill" |
| 98 | echo '```' |
| 99 | } >> "$GITHUB_STEP_SUMMARY" |
| 100 | fi |
| 101 | fi |
| 102 |