Skip to content

Commit b20ba65

Browse files
committed
feat: Add robust release workflow with manual version control
1 parent 799e257 commit b20ba65

File tree

2 files changed

+95
-5
lines changed

2 files changed

+95
-5
lines changed

.github/workflows/release.yaml

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ name: Create Release
33
on:
44
push:
55
branches: ["master"]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to release (e.g. 1.7.0)'
10+
required: false
11+
type: string
612

713
jobs:
814
release:
@@ -25,27 +31,79 @@ jobs:
2531

2632
- name: Install Poetry and dependencies
2733
run: |
28-
pip install poetry
34+
pip install poetry toml
2935
poetry install
36+
37+
- name: Update Version (if specified)
38+
if: "${{ github.event.inputs.version != '' }}"
39+
id: update_version
40+
run: |
41+
# Update version in pyproject.toml
42+
python -c "
43+
import toml
44+
with open('pyproject.toml', 'r') as f:
45+
config = toml.load(f)
46+
config['tool']['poetry']['version'] = '${{ github.event.inputs.version }}'
47+
with open('pyproject.toml', 'w') as f:
48+
toml.dump(config, f)
49+
"
50+
51+
# Update version in __init__.py
52+
sed -i 's/__version__ = ".*"/__version__ = "${{ github.event.inputs.version }}"/' runlike/__init__.py
53+
54+
# Commit the changes
55+
git config --local user.email "[email protected]"
56+
git config --local user.name "GitHub Action"
57+
git add pyproject.toml runlike/__init__.py
58+
git commit -m "chore(release): bump version to ${{ github.event.inputs.version }}"
59+
git push
60+
61+
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
3062
3163
- name: Get Version
3264
id: get_version
65+
if: "${{ github.event.inputs.version == '' }}"
3366
run: |
3467
VERSION=$(poetry run ./current_version.py)
3568
echo "version=$VERSION" >> $GITHUB_OUTPUT
69+
70+
- name: Set Final Version
71+
id: final_version
72+
run: |
73+
if [ "${{ github.event.inputs.version }}" != "" ]; then
74+
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
75+
else
76+
echo "version=${{ steps.get_version.outputs.version }}" >> $GITHUB_OUTPUT
77+
fi
78+
79+
- name: Check if tag exists
80+
id: check_tag
81+
run: |
82+
if git rev-parse "v${{ steps.final_version.outputs.version }}" >/dev/null 2>&1; then
83+
echo "tag_exists=true" >> $GITHUB_OUTPUT
84+
else
85+
echo "tag_exists=false" >> $GITHUB_OUTPUT
86+
fi
3687
3788
- name: Create Tag
89+
if: steps.check_tag.outputs.tag_exists == 'false'
3890
run: |
39-
git tag v${{ steps.get_version.outputs.version }}
40-
git push origin v${{ steps.get_version.outputs.version }}
91+
git tag v${{ steps.final_version.outputs.version }}
92+
git push origin v${{ steps.final_version.outputs.version }}
4193
4294
- name: Create Release
95+
if: steps.check_tag.outputs.tag_exists == 'false'
4396
uses: softprops/action-gh-release@v1
4497
with:
45-
tag_name: v${{ steps.get_version.outputs.version }}
46-
name: Release v${{ steps.get_version.outputs.version }}
98+
tag_name: v${{ steps.final_version.outputs.version }}
99+
name: Release v${{ steps.final_version.outputs.version }}
47100
draft: false
48101
prerelease: false
49102
generate_release_notes: true
50103
env:
51104
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
106+
- name: Skip Release (Tag Exists)
107+
if: steps.check_tag.outputs.tag_exists == 'true'
108+
run: |
109+
echo "Tag v${{ steps.final_version.outputs.version }} already exists. Skipping release creation."

bin/update_version.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import toml
5+
6+
if len(sys.argv) != 2:
7+
print("Usage: update_version.py NEW_VERSION")
8+
sys.exit(1)
9+
10+
new_version = sys.argv[1]
11+
12+
# Update pyproject.toml
13+
with open('pyproject.toml', 'r') as f:
14+
config = toml.load(f)
15+
16+
config['tool']['poetry']['version'] = new_version
17+
18+
with open('pyproject.toml', 'w') as f:
19+
toml.dump(config, f)
20+
21+
# Update __init__.py
22+
with open('runlike/__init__.py', 'r') as f:
23+
lines = f.readlines()
24+
25+
with open('runlike/__init__.py', 'w') as f:
26+
for line in lines:
27+
if line.startswith('__version__'):
28+
f.write(f'__version__ = "{new_version}"\n')
29+
else:
30+
f.write(line)
31+
32+
print(f"Version updated to {new_version} in pyproject.toml and runlike/__init__.py")

0 commit comments

Comments
 (0)