-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (99 loc) · 3.39 KB
/
version-bump.yml
File metadata and controls
113 lines (99 loc) · 3.39 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
107
108
109
110
111
112
113
name: Version Bump and Release
on:
workflow_dispatch:
inputs:
bump_type:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
push:
branches: [ main, master ]
paths-ignore:
- '**.md'
- '.github/**'
jobs:
version-bump:
runs-on: ubuntu-latest
timeout-minutes: 10
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.AI_GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.13"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install semver
- name: Get current version
id: current_version
run: |
CURRENT_VERSION=$(python setup.py --version)
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Calculate new version
id: new_version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
BUMP_TYPE="${{ github.event.inputs.bump_type }}"
else
BUMP_TYPE="patch"
fi
CURRENT_VERSION="${{ steps.current_version.outputs.current_version }}"
# Split version into components
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"
case $BUMP_TYPE in
major)
NEW_MAJOR=$((MAJOR + 1))
NEW_MINOR=0
NEW_PATCH=0
;;
minor)
NEW_MAJOR=$MAJOR
NEW_MINOR=$((MINOR + 1))
NEW_PATCH=0
;;
patch)
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="$NEW_MAJOR.$NEW_MINOR.$NEW_PATCH"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Update version in setup.py
run: |
sed -i "s/version=\"${{ steps.current_version.outputs.current_version }}\"/version=\"${{ steps.new_version.outputs.new_version }}\"/" setup.py
echo "Updated setup.py version to ${{ steps.new_version.outputs.new_version }}"
- name: Create and push tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add setup.py
git commit -m "Bump version to ${{ steps.new_version.outputs.new_version }}"
git tag -a "v${{ steps.new_version.outputs.new_version }}" -m "Release version ${{ steps.new_version.outputs.new_version }}"
git push origin HEAD:${{ github.ref }}
git push origin "v${{ steps.new_version.outputs.new_version }}"
- name: Trigger publish workflow
uses: actions/github-script@v7
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'publish.yml',
ref: context.ref
})