@@ -3,6 +3,12 @@ name: Create Release
33on :
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
713jobs :
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."
0 commit comments