11name : Release
22
33on :
4- push :
5- tags :
6- - ' v*.*.*'
7-
84 workflow_dispatch :
5+ inputs :
6+ publish-destination :
7+ description : ' Publish destination (only main branch can be published to PyPi)'
8+ required : true
9+ default : " test.pypi"
10+ type : choice
11+ options :
12+ - pypi
13+ - test.pypi
914
1015permissions :
1116 contents : read
1217
1318jobs :
19+ publish-check :
20+ runs-on : ubuntu-latest
21+ steps :
22+ - name : Check if branch is main
23+ if : |
24+ (inputs.publish-destination == 'pypi' && github.ref != 'refs/heads/main')
25+ run : |
26+ echo "Only main branch can be published to PyPi."
27+ exit 1
28+
1429 build :
30+ needs : [publish-check]
1531 runs-on : ubuntu-latest
1632 steps :
1733 - name : Checkout repository
3753 publish-pypi :
3854 name : Publish to PyPI
3955 needs : build
56+ if : inputs.publish-destination == 'pypi'
4057 runs-on : ubuntu-latest
41- if : startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-rc')
4258 environment : pypi
4359 permissions :
4460 id-token : write
@@ -52,11 +68,35 @@ jobs:
5268 - name : Publish to PyPI
5369 uses : pypa/gh-action-pypi-publish@release/v1
5470
71+ tag :
72+ name : Create git tag
73+ needs : [publish-pypi]
74+ if : inputs.publish-destination == 'pypi'
75+ runs-on : ubuntu-latest
76+ permissions :
77+ contents : write
78+ steps :
79+ - name : Checkout repository
80+ uses : actions/checkout@v5
81+
82+ - name : Determine version
83+ id : version
84+ run : |
85+ VERSION=$(grep -oP '(?<=^__version__ = ")[^"]+' src/powersensor_local/__init__.py)
86+ echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
87+
88+ - name : Create and push tag
89+ run : |
90+ git config user.name "github-actions[bot]"
91+ git config user.email "github-actions[bot]@users.noreply.github.com"
92+ git tag "${{ steps.version.outputs.tag }}"
93+ git push origin "${{ steps.version.outputs.tag }}"
94+
5595 publish-testpypi :
5696 name : Publish to TestPyPI
5797 needs : build
98+ if : inputs.publish-destination == 'test.pypi'
5899 runs-on : ubuntu-latest
59- if : startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-rc')
60100 environment : testpypi
61101 permissions :
62102 id-token : write
0 commit comments