@@ -45,15 +45,20 @@ jobs:
4545 - name : Checkout source code
4646 uses : actions/checkout@v4
4747
48- - name : Setup Python 3.11
48+ - name : Setup Python 3.13
4949 uses : actions/setup-python@v5
5050 with :
51- python-version : " 3.11"
51+ python-version : " 3.13"
52+
53+ - name : Set PyPI version
54+ uses : PowerGridModel/pgm-version-bump@main
55+ with :
56+ token : ${{ secrets.GITHUB_TOKEN }}
5257
5358 - name : Build
5459 run : |
55- pip install requests build
56- python set_pypi_version.py
60+ cat PYPI_VERSION
61+ pip install build
5762 python -m build --outdir wheelhouse .
5863
5964 - name : Save version
@@ -163,44 +168,86 @@ jobs:
163168 - name : Validation tests
164169 run : pytest tests/validation --no-cov --verbose
165170
166- publish :
171+ github-release :
167172 needs :
168173 - build-python
169174 - unit-tests
170175 - validation-tests
171176 - sonar-cloud
172177 permissions :
173178 contents : write
174- env :
175- TWINE_USERNAME : ${{ secrets.PYPI_USER }}
176- TWINE_PASSWORD : ${{ secrets.PYPI_PASS }}
177179 runs-on : ubuntu-latest
178180 steps :
179- - name : Setup Python 3.11
181+ - name : Setup Python 3.13
180182 uses : actions/setup-python@v5
181183 with :
182- python-version : " 3.11 "
184+ python-version : " 3.13 "
183185
184186 - name : Load built wheel file
185187 uses : actions/download-artifact@v4
186188 with :
187189 name : power-grid-model-io
188190 path : wheelhouse/
189191
190- - name : Upload wheels
191- if : (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event.inputs.create_release == 'true'))
192- run : |
193- pip install twine
194- echo "Publish to PyPI..."
195- twine upload --verbose wheelhouse/*
192+ - name : Get tag
193+ id : tag
194+ run : echo "tag=v${{ needs.build-python.outputs.version }}" >> $GITHUB_OUTPUT
195+
196+ - name : Display tag
197+ run : echo "${{ steps.tag.outputs.tag }}"
196198
197- - name : Release
199+ - name : Create GitHub release
198200 if : (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event.inputs.create_release == 'true'))
199201 uses : softprops/action-gh-release@v2
200202 with :
201203 files : |
202204 ./wheelhouse/*
203- tag_name : v ${{ needs.build-python .outputs.version }}
205+ tag_name : " ${{ steps.tag .outputs.tag }}"
204206 prerelease : ${{github.ref != 'refs/heads/main'}}
205207 generate_release_notes : true
206208 target_commitish : ${{ github.sha }}
209+
210+ publish :
211+ name : Publish to PyPI
212+ runs-on : ubuntu-latest
213+ permissions :
214+ contents : write
215+ id-token : write # Required for Trusted Publishing
216+ needs : github-release
217+ if : (github.event_name == 'workflow_dispatch') || github.event_name == 'push'
218+
219+ steps :
220+ - name : Download assets from GitHub release
221+ uses : robinraju/release-downloader@v1
222+ with :
223+ repository : ${{ github.repository }}
224+ # download the latest release
225+ latest : true
226+ # don't download pre-releases
227+ preRelease : false
228+ fileName : " *"
229+ # don't download GitHub-generated source tar and zip files
230+ tarBall : false
231+ zipBall : false
232+ # create a directory to store the downloaded assets
233+ out-file-path : assets-to-publish
234+ # don't extract downloaded files
235+ extract : false
236+
237+ - name : List downloaded assets
238+ run : ls -la assets-to-publish
239+
240+ - name : Upload assets to PyPI
241+ uses : pypa/gh-action-pypi-publish@release/v1
242+ with :
243+ # To test, use the TestPyPI:
244+ # repository-url: https://test.pypi.org/legacy/
245+ # You must also create an account and project on TestPyPI,
246+ # as well as set the trusted-publisher in the project settings:
247+ # https://docs.pypi.org/trusted-publishers/adding-a-publisher/
248+ # To publish to the official PyPI repository, just keep
249+ # repository-url commented out.
250+ packages-dir : assets-to-publish
251+ skip-existing : true
252+ print-hash : true
253+ verbose : true
0 commit comments