forked from vitali87/code-graph-rag
-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (95 loc) · 3.47 KB
/
version-bump.yml
File metadata and controls
106 lines (95 loc) · 3.47 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: Version Bump
on:
push:
branches:
- main
workflow_dispatch:
inputs:
bump_type:
description: "Version bump type"
required: true
default: "patch"
type: choice
options:
- patch
- minor
- major
jobs:
bump-version:
name: Auto Version Bump
if: "!contains(github.event.head_commit.message, 'chore: bump version')"
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check if version was manually changed
id: check_manual
run: |
OLD_VERSION=$(git show HEAD^:pyproject.toml | grep -E '^version\s*=' | sed 's/version = "\(.*\)"/\1/')
NEW_VERSION=$(grep -E '^version\s*=' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "Version was manually changed from $OLD_VERSION to $NEW_VERSION, skipping auto-bump"
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Get current version
if: steps.check_manual.outputs.skip == 'false'
id: get_version
run: |
CURRENT_VERSION=$(grep -E '^version\s*=' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Determine bump type
if: steps.check_manual.outputs.skip == 'false'
id: bump_type
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "type=${{ github.event.inputs.bump_type }}" >> $GITHUB_OUTPUT
else
echo "type=patch" >> $GITHUB_OUTPUT
fi
- name: Bump version
if: steps.check_manual.outputs.skip == 'false'
id: bump_version
run: |
CURRENT="${{ steps.get_version.outputs.current }}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
case "${{ steps.bump_type.outputs.type }}" in
major)
NEW_MAJOR=$((MAJOR + 1))
NEW_VERSION="$NEW_MAJOR.0.0"
;;
minor)
NEW_MINOR=$((MINOR + 1))
NEW_VERSION="$MAJOR.$NEW_MINOR.0"
;;
patch)
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
;;
esac
echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Bumping version from $CURRENT to $NEW_VERSION (type: ${{ steps.bump_type.outputs.type }})"
- name: Update pyproject.toml
if: steps.check_manual.outputs.skip == 'false'
run: |
sed -i 's/^version = ".*"/version = "${{ steps.bump_version.outputs.new }}"/' pyproject.toml
- name: Commit version bump
if: steps.check_manual.outputs.skip == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore: bump version to ${{ steps.bump_version.outputs.new }}"
git push
- name: Create git tag
if: steps.check_manual.outputs.skip == 'false'
run: |
git tag "v${{ steps.bump_version.outputs.new }}"
git push origin "v${{ steps.bump_version.outputs.new }}"