Skip to content

Commit 426eb0f

Browse files
authored
ci: add job to bump version (#73)
1 parent 577c797 commit 426eb0f

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

.github/workflows/version-bump.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Version Bump and Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: 'Version bump type'
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
- custom
15+
default: 'patch'
16+
custom_version:
17+
description: 'Custom version (only used if version_type is "custom")'
18+
required: false
19+
type: string
20+
21+
jobs:
22+
bump-version:
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: write
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
with:
30+
token: ${{ secrets.GITHUB_TOKEN }}
31+
fetch-depth: 0
32+
33+
- name: Setup pnpm
34+
uses: pnpm/action-setup@v4
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: '20'
40+
cache: 'pnpm'
41+
42+
- name: Configure Git
43+
run: |
44+
git config --global user.name "github-actions[bot]"
45+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
46+
47+
- name: Install dependencies
48+
run: pnpm install --frozen-lockfile
49+
50+
- name: Bump version
51+
id: version_bump
52+
run: |
53+
if [ "${{ inputs.version_type }}" = "custom" ]; then
54+
if [ -z "${{ inputs.custom_version }}" ]; then
55+
echo "Error: Custom version is required when version_type is 'custom'"
56+
exit 1
57+
fi
58+
pnpm version ${{ inputs.custom_version }} --no-git-tag-version
59+
NEW_VERSION="${{ inputs.custom_version }}"
60+
else
61+
pnpm version ${{ inputs.version_type }} --no-git-tag-version
62+
NEW_VERSION=$(node -p "require('./package.json').version")
63+
fi
64+
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
65+
echo "New version: ${NEW_VERSION}"
66+
67+
- name: Commit and push changes
68+
run: |
69+
git add package.json
70+
git commit -m "chore: bump version to ${{ steps.version_bump.outputs.new_version }}"
71+
git tag -a "v${{ steps.version_bump.outputs.new_version }}" -m "Release v${{ steps.version_bump.outputs.new_version }}"
72+
git push origin ${{ github.ref_name }}
73+
git push origin "v${{ steps.version_bump.outputs.new_version }}"
74+
75+
- name: Create GitHub Release
76+
uses: actions/create-release@v1
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
with:
80+
tag_name: v${{ steps.version_bump.outputs.new_version }}
81+
release_name: Release v${{ steps.version_bump.outputs.new_version }}
82+
draft: false
83+
prerelease: false

0 commit comments

Comments
 (0)