-
Notifications
You must be signed in to change notification settings - Fork 3
109 lines (92 loc) · 3.2 KB
/
version-bump.yml
File metadata and controls
109 lines (92 loc) · 3.2 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
name: Version Bump
on:
workflow_dispatch:
inputs:
bump_type:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
jobs:
version-bump:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Get current version
id: current_version
run: |
CURRENT_VERSION=$(grep -oP '(?<=version = ")[^"]+' pyproject.toml | head -1)
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Calculate new version
id: new_version
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
BUMP_TYPE="${{ github.event.inputs.bump_type }}"
IFS='.' read -r major minor patch <<< "$CURRENT_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 "New version: $NEW_VERSION"
- name: Update pyproject.toml
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
NEW_VERSION="${{ steps.new_version.outputs.version }}"
sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" pyproject.toml
- name: Update uv.lock
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
NEW_VERSION="${{ steps.new_version.outputs.version }}"
sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" uv.lock
- name: Configure Git
run: |
git config user.name "denobot"
git config user.email "denobot@users.noreply.github.com"
- name: Create branch and commit
id: commit
run: |
NEW_VERSION="${{ steps.new_version.outputs.version }}"
BRANCH_NAME="version-bump-v$NEW_VERSION"
git checkout -b "$BRANCH_NAME"
git add pyproject.toml uv.lock
git commit -m "v$NEW_VERSION"
git push origin "$BRANCH_NAME"
echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.DENOBOT_PAT }}
run: |
NEW_VERSION="${{ steps.new_version.outputs.version }}"
BRANCH_NAME="${{ steps.commit.outputs.branch }}"
BUMP_TYPE="${{ github.event.inputs.bump_type }}"
gh pr create \
--title "v$NEW_VERSION" \
--body "Automated $BUMP_TYPE version bump to v$NEW_VERSION. After merging this PR, run the 'Release' workflow." \
--base main \
--head "$BRANCH_NAME"