-
Notifications
You must be signed in to change notification settings - Fork 1
73 lines (63 loc) · 2.31 KB
/
version-bump.yml
File metadata and controls
73 lines (63 loc) · 2.31 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
name: Bump Version
on:
workflow_dispatch:
inputs:
bump_type:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
- custom
default: 'patch'
custom_version:
description: 'Custom version (only used if bump_type is "custom")'
required: false
type: string
permissions:
contents: write
jobs:
bump-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install bump2version
run: pip install bump2version
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Bump version
run: |
if [ "${{ inputs.bump_type }}" = "custom" ]; then
if [ -z "${{ inputs.custom_version }}" ]; then
echo "Error: Custom version not provided"
exit 1
fi
current_version=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
sed -i "s/version = \"$current_version\"/version = \"${{ inputs.custom_version }}\"/" pyproject.toml
git add pyproject.toml
git commit -m "Bump version to ${{ inputs.custom_version }}"
echo "NEW_VERSION=${{ inputs.custom_version }}" >> $GITHUB_ENV
else
bump2version ${{ inputs.bump_type }} --current-version $(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') --config-file /dev/null --no-tag --no-commit pyproject.toml
new_version=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
git add pyproject.toml
git commit -m "Bump version to $new_version (${{ inputs.bump_type }})"
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
fi
- name: Push changes
run: git push
- name: Output new version
run: |
echo "Version bumped successfully!"
echo "New version: ${{ env.NEW_VERSION }}"
echo "::notice::Version updated to ${{ env.NEW_VERSION }}"