1
+ name : Version Bump
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ inputs :
6
+ version_type :
7
+ description : ' Version bump type'
8
+ required : true
9
+ default : ' patch'
10
+ type : choice
11
+ options :
12
+ - patch
13
+ - minor
14
+ - major
15
+ custom_version :
16
+ description : ' Custom version (optional, overrides version_type)'
17
+ required : false
18
+ type : string
19
+
20
+ jobs :
21
+ version-bump :
22
+ runs-on : ubuntu-latest
23
+ steps :
24
+ - name : Checkout repository
25
+ uses : actions/checkout@v4
26
+ with :
27
+ token : ${{ secrets.GITHUB_TOKEN }}
28
+
29
+ - name : Setup Node.js
30
+ uses : actions/setup-node@v4
31
+ with :
32
+ node-version : ' 24'
33
+ cache : ' npm'
34
+
35
+ - name : Install dependencies
36
+ run : npm ci
37
+
38
+ - name : Configure git
39
+ run : |
40
+ git config --local user.email "action@github.com"
41
+ git config --local user.name "GitHub Action"
42
+
43
+ - name : Get current version
44
+ id : current_version
45
+ run : |
46
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
47
+ echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
48
+
49
+ - name : Bump version
50
+ id : bump_version
51
+ run : |
52
+ if [ -n "${{ github.event.inputs.custom_version }}" ]; then
53
+ # Use custom version
54
+ CUSTOM_VERSION="${{ github.event.inputs.custom_version }}"
55
+ # Remove 'v' prefix if present
56
+ CUSTOM_VERSION=${CUSTOM_VERSION#v}
57
+
58
+ # Basic version validation (semver format)
59
+ if ! echo "$CUSTOM_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*)?(\+[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*)?$'; then
60
+ echo "Error: Custom version '$CUSTOM_VERSION' is not a valid semver format"
61
+ exit 1
62
+ fi
63
+
64
+ NEW_VERSION="$CUSTOM_VERSION"
65
+ npm version $NEW_VERSION --no-git-tag-version
66
+ echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT
67
+ else
68
+ # Use version type bump
69
+ NEW_VERSION=$(npm version ${{ github.event.inputs.version_type }} --no-git-tag-version)
70
+ # Remove 'v' prefix if present
71
+ NEW_VERSION=${NEW_VERSION#v}
72
+ echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT
73
+ fi
74
+
75
+ - name : Create pull request branch
76
+ run : |
77
+ BRANCH_NAME="version-bump/v${{ steps.bump_version.outputs.new }}"
78
+ git checkout -b $BRANCH_NAME
79
+ echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
80
+
81
+ - name : Commit changes
82
+ run : |
83
+ git add package.json package-lock.json
84
+ git commit -m "chore: bump version to v${{ steps.bump_version.outputs.new }}"
85
+
86
+ - name : Push branch
87
+ run : |
88
+ git push origin $BRANCH_NAME
89
+
90
+ - name : Create Pull Request
91
+ uses : actions/github-script@v7
92
+ with :
93
+ script : |
94
+ const { data: pullRequest } = await github.rest.pulls.create({
95
+ owner: context.repo.owner,
96
+ repo: context.repo.repo,
97
+ title: `chore: bump version to v${{ steps.bump_version.outputs.new }}`,
98
+ head: process.env.BRANCH_NAME,
99
+ base: 'main',
100
+ body: `
101
+ ## Version Bump
102
+
103
+ This PR updates the package version from \`${{ steps.current_version.outputs.current }}\` to \`${{ steps.bump_version.outputs.new }}\`.
104
+
105
+ ### Changes
106
+ - 📦 Updated \`package.json\` version
107
+ - 🔒 Updated \`package-lock.json\` (if applicable)
108
+
109
+ ### Next Steps
110
+ 1. Review and merge this PR
111
+ 2. Create a GitHub release with tag \`v${{ steps.bump_version.outputs.new }}\`
112
+ 3. The publish workflow will automatically run and deploy to npm
113
+
114
+ ---
115
+
116
+ *This PR was created automatically by the Version Bump workflow.*
117
+ `
118
+ });
119
+
120
+ console.log(`Pull request created: ${pullRequest.html_url}`);
121
+
122
+ // Add labels if they exist
123
+ try {
124
+ await github.rest.issues.addLabels({
125
+ owner: context.repo.owner,
126
+ repo: context.repo.repo,
127
+ issue_number: pullRequest.number,
128
+ labels: ['version-bump', 'chore']
129
+ });
130
+ } catch (error) {
131
+ console.log('Could not add labels (they may not exist):', error.message);
132
+ }
133
+
134
+ - name : Summary
135
+ run : |
136
+ echo "## Version Bump Summary" >> $GITHUB_STEP_SUMMARY
137
+ echo "- **Previous version:** ${{ steps.current_version.outputs.current }}" >> $GITHUB_STEP_SUMMARY
138
+ echo "- **New version:** ${{ steps.bump_version.outputs.new }}" >> $GITHUB_STEP_SUMMARY
139
+ echo "- **Branch:** $BRANCH_NAME" >> $GITHUB_STEP_SUMMARY
140
+ echo "- **Type:** ${{ github.event.inputs.version_type }}" >> $GITHUB_STEP_SUMMARY
141
+ if [ -n "${{ github.event.inputs.custom_version }}" ]; then
142
+ echo "- **Custom version used:** Yes" >> $GITHUB_STEP_SUMMARY
143
+ fi
0 commit comments