1+ name: Release
2+
3+ on:
4+ push:
5+ branches:
6+ - main
7+
8+ concurrency: ${{ github.workflow }}-${{ github.ref }}
9+
10+ jobs:
11+ release:
12+ name: Release
13+ runs-on: ubuntu-latest
14+ permissions:
15+ contents: write
16+ issues: write
17+ pull-requests: write
18+ id-token: write
19+ steps:
20+ - name: Checkout
21+ uses: actions/checkout@v4
22+ with:
23+ fetch-depth: 0
24+ token: ${{ secrets.GITHUB_TOKEN }}
25+
26+ - name: Setup Node.js
27+ uses: actions/setup-node@v4
28+ with:
29+ node-version: '22.10.0'
30+ registry-url: 'https://registry.npmjs.org/'
31+
32+ - name: Setup pnpm
33+ uses: pnpm/action-setup@v2
34+ with:
35+ version: latest
36+
37+ - name: Install dependencies
38+ run: pnpm install
39+
40+ - name: Check for changesets
41+ id: changesets-check
42+ run: |
43+ if [ -n "$(ls -A .changeset/*.md 2>/dev/null | grep -v README.md)" ]; then
44+ echo "has_changesets=true" >> $GITHUB_OUTPUT
45+ else
46+ echo "has_changesets=false" >> $GITHUB_OUTPUT
47+ fi
48+
49+ - name: Create Release Branch
50+ if: steps.changesets-check.outputs.has_changesets == 'true'
51+ run: |
52+ # Get current version from package.json
53+ CURRENT_VERSION=$(node -p "require('./package.json').version")
54+
55+ # Create release branch
56+ RELEASE_BRANCH="release/v${CURRENT_VERSION}"
57+ git checkout -b $RELEASE_BRANCH
58+
59+ # Apply changesets version updates
60+ pnpm changeset version
61+
62+ # Get new version after changesets
63+ NEW_VERSION=$(node -p "require('./package.json').version")
64+
65+ # If version changed, update branch name
66+ if [ "$CURRENT_VERSION" != "$NEW_VERSION" ]; then
67+ git branch -m "release/v${NEW_VERSION}"
68+ RELEASE_BRANCH="release/v${NEW_VERSION}"
69+ fi
70+
71+ # Commit version changes
72+ git config user.name "github-actions[bot]"
73+ git config user.email "github-actions[bot]@users.noreply.github.com"
74+ git add -A
75+ git commit -m "chore: release v${NEW_VERSION}" || echo "No changes to commit"
76+
77+ # Push release branch
78+ git push origin $RELEASE_BRANCH
79+
80+ echo "release_branch=$RELEASE_BRANCH" >> $GITHUB_OUTPUT
81+ echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
82+
83+ - name: Build packages
84+ if: steps.changesets-check.outputs.has_changesets == 'true'
85+ run: pnpm build:all
86+
87+ - name: Publish to npm
88+ if: steps.changesets-check.outputs.has_changesets == 'true'
89+ run: |
90+ # Use custom release script for fault-tolerant publishing
91+ node scripts/release-packages.js
92+ env:
93+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
94+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
95+ NPM_TOKEN_SUMIN: ${{ secrets.NPM_TOKEN_SUMIN }}
96+
97+ - name: Create GitHub Release
98+ if: steps.changesets-check.outputs.has_changesets == 'true'
99+ uses: actions/create-release@v1
100+ env:
101+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+ with:
103+ tag_name: v${{ steps.release.outputs.version }}
104+ release_name: Release v${{ steps.release.outputs.version }}
105+ draft: false
106+ prerelease: false
107+
108+ - name: Create sync PR to develop
109+ if: steps.changesets-check.outputs.has_changesets == 'true'
110+ run: |
111+ # Create PR from release branch to develop
112+ gh pr create \
113+ --base develop \
114+ --head ${{ steps.release.outputs.release_branch }} \
115+ --title "chore: sync release v${{ steps.release.outputs.version }} to develop" \
116+ --body "## 🔄 Release Sync
117+
118+ This PR syncs the following changes from release v${{ steps.release.outputs.version }}:
119+ - ✅ Version bumps
120+ - ✅ Consumed changesets (deleted)
121+ - ✅ Updated CHANGELOG.md files
122+
123+ **Important**: Please review carefully and resolve any conflicts." \
124+ || echo "Sync PR creation skipped"
0 commit comments