-
Notifications
You must be signed in to change notification settings - Fork 1
105 lines (91 loc) · 2.8 KB
/
Copy pathrelease.yml
File metadata and controls
105 lines (91 loc) · 2.8 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
name: Release
on:
workflow_dispatch:
inputs:
version_type:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install bump2version
run: pip install bump2version
- name: Configure git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Bump version
run: |
# Extract current version from pyproject.toml
CURRENT_VERSION=$(grep -Po '(?<=version = ")[^"]*' pyproject.toml)
echo "Current version: $CURRENT_VERSION"
# Calculate new version based on input
case ${{ github.event.inputs.version_type }} in
"major")
NEW_VERSION=$(python -c "
import re
v = '$CURRENT_VERSION'
parts = v.split('.')
parts[0] = str(int(parts[0]) + 1)
parts[1] = '0'
parts[2] = '0'
print('.'.join(parts))
")
;;
"minor")
NEW_VERSION=$(python -c "
import re
v = '$CURRENT_VERSION'
parts = v.split('.')
parts[1] = str(int(parts[1]) + 1)
parts[2] = '0'
print('.'.join(parts))
")
;;
"patch")
NEW_VERSION=$(python -c "
import re
v = '$CURRENT_VERSION'
parts = v.split('.')
parts[2] = str(int(parts[2]) + 1)
print('.'.join(parts))
")
;;
esac
echo "New version: $NEW_VERSION"
# Update version in pyproject.toml
sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" pyproject.toml
# Commit changes
git add pyproject.toml
git commit -m "Bump version to $NEW_VERSION"
git push
# Create tag and release
git tag "v$NEW_VERSION"
git push origin "v$NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.NEW_VERSION }}
release_name: Release v${{ env.NEW_VERSION }}
draft: false
prerelease: false