-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (85 loc) · 3.09 KB
/
version-bump.yml
File metadata and controls
97 lines (85 loc) · 3.09 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
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
jobs:
version-bump:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- 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 setuptools
- 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: |
BUMP_TYPE="${{ github.event.inputs.bump_type }}"
CURRENT_VERSION="${{ steps.current_version.outputs.current_version }}"
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, __init__.py, and client User-Agent
run: |
OLD="${{ steps.current_version.outputs.current_version }}"
NEW="${{ steps.new_version.outputs.new_version }}"
sed -i "s/version=\"${OLD}\"/version=\"${NEW}\"/" setup.py
sed -i "s/__version__ = \"${OLD}\"/__version__ = \"${NEW}\"/" cost_katana/__init__.py
sed -i "s/cost-katana-python\/${OLD}\"/cost-katana-python\/${NEW}\"/" cost_katana/client.py
- name: Create and push commit and tag
env:
PUSH_TOKEN: ${{ secrets.RELEASE_PUSH_TOKEN || github.token }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git remote set-url origin "https://x-access-token:${PUSH_TOKEN}@github.com/${{ github.repository }}.git"
git add setup.py cost_katana/__init__.py cost_katana/client.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 }}"