-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (76 loc) 路 2.99 KB
/
Copy pathversion-bump.yml
File metadata and controls
91 lines (76 loc) 路 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Auto Version Bump
on:
push:
branches:
- main
paths-ignore:
- "**.md"
- "docs/**"
- "scripts/**"
permissions:
contents: write
jobs:
version-bump:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine version bump
id: bump
run: |
# Get the last commit message
COMMIT_MSG=$(git log -1 --pretty=%B)
# Determine bump type from commit message
if echo "$COMMIT_MSG" | grep -qiE "^(BREAKING CHANGE|major):"; then
echo "type=major" >> $GITHUB_OUTPUT
elif echo "$COMMIT_MSG" | grep -qiE "^(feat|feature|minor):"; then
echo "type=minor" >> $GITHUB_OUTPUT
elif echo "$COMMIT_MSG" | grep -qiE "^(fix|patch|bugfix):"; then
echo "type=patch" >> $GITHUB_OUTPUT
else
echo "type=none" >> $GITHUB_OUTPUT
fi
- name: Get current version
id: current
run: |
# Get the latest tag
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "tag=${LATEST_TAG}" >> $GITHUB_OUTPUT
# Remove 'v' prefix
VERSION=${LATEST_TAG#v}
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Calculate new version
id: new
if: steps.bump.outputs.type != 'none'
run: |
VERSION="${{ steps.current.outputs.version }}"
BUMP_TYPE="${{ steps.bump.outputs.type }}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
case $BUMP_TYPE in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "tag=v${NEW_VERSION}" >> $GITHUB_OUTPUT
- name: Create and push tag
if: steps.bump.outputs.type != 'none'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
NEW_TAG="${{ steps.new.outputs.tag }}"
git tag -a $NEW_TAG -m "Release $NEW_TAG"
git push origin $NEW_TAG