1+ name : Create Release PR
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ version :
7+ description : ' Version type (patch, minor, major)'
8+ required : true
9+ default : ' patch'
10+ type : choice
11+ options :
12+ - patch
13+ - minor
14+ - major
15+
16+ permissions :
17+ contents : write
18+ pull-requests : write
19+
20+ jobs :
21+ create-release-pr :
22+ name : Create Release PR
23+ runs-on : ubuntu-latest
24+
25+ steps :
26+ - name : Checkout code
27+ uses : actions/checkout@v4
28+ with :
29+ token : ${{ secrets.GITHUB_TOKEN }}
30+
31+ - name : Setup Node.js
32+ uses : actions/setup-node@v4
33+ with :
34+ node-version : ' 20.x'
35+ cache : ' npm'
36+
37+ - name : Configure Git
38+ run : |
39+ git config --global user.name "github-actions[bot]"
40+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
41+
42+ - name : Create release branch
43+ run : |
44+ git checkout -b release/v${{ github.run_number }}
45+
46+ - name : Bump version
47+ id : version
48+ run : |
49+ # Get current version
50+ CURRENT_VERSION=$(node -p "require('./package.json').version")
51+ echo "Current version: $CURRENT_VERSION"
52+
53+ # Bump version
54+ npm version ${{ github.event.inputs.version }} --no-git-tag-version
55+
56+ # Get new version
57+ NEW_VERSION=$(node -p "require('./package.json').version")
58+ echo "New version: $NEW_VERSION"
59+ echo "new-version=$NEW_VERSION" >> $GITHUB_OUTPUT
60+
61+ - name : Update CHANGELOG
62+ run : |
63+ # Create or update CHANGELOG.md
64+ if [ ! -f CHANGELOG.md ]; then
65+ echo "# Changelog" > CHANGELOG.md
66+ echo "" >> CHANGELOG.md
67+ fi
68+
69+ # Add new version entry at the top
70+ TEMP_FILE=$(mktemp)
71+ echo "# Changelog" > $TEMP_FILE
72+ echo "" >> $TEMP_FILE
73+ echo "## v${{ steps.version.outputs.new-version }} - $(date +%Y-%m-%d)" >> $TEMP_FILE
74+ echo "" >> $TEMP_FILE
75+ echo "### Changed" >> $TEMP_FILE
76+ echo "- Version bump from workflow" >> $TEMP_FILE
77+ echo "" >> $TEMP_FILE
78+ tail -n +2 CHANGELOG.md >> $TEMP_FILE
79+ mv $TEMP_FILE CHANGELOG.md
80+
81+ - name : Commit changes
82+ run : |
83+ git add package.json package-lock.json CHANGELOG.md
84+ git commit -m "chore: bump version to v${{ steps.version.outputs.new-version }}"
85+
86+ - name : Push branch
87+ run : |
88+ git push -u origin release/v${{ github.run_number }}
89+
90+ - name : Create Pull Request
91+ uses : actions/github-script@v7
92+ with :
93+ script : |
94+ const { data: pr } = await github.rest.pulls.create({
95+ owner: context.repo.owner,
96+ repo: context.repo.repo,
97+ title: `Release v${{ steps.version.outputs.new-version }}`,
98+ body: `## 🚀 Release v${{ steps.version.outputs.new-version }}
99+
100+ This PR was automatically created to release version v${{ steps.version.outputs.new-version }}.
101+
102+ ### Checklist
103+ - [ ] Update CHANGELOG.md with actual changes
104+ - [ ] Review version bump is correct
105+ - [ ] All tests are passing
106+
107+ ### What happens when merged
108+ When this PR is merged to \`master\`:
109+ 1. The npm publish workflow will automatically trigger
110+ 2. The package will be published to npm
111+
112+ ---
113+ _Created by release workflow_`,
114+ head: `release/v${{ github.run_number }}`,
115+ base: 'master',
116+ draft: false
117+ });
118+
119+ console.log(`Pull request created: ${pr.html_url}`);
0 commit comments