33# SPDX-License-Identifier: MPL-2.0
44
55
6- name : Build, Test, Sonar and Publish
6+ name : Build, Test and Release
77
88on :
9- push :
10- branches :
11- - main
12- # run pipeline on pull request
13- pull_request :
14- # run pipeline on merge queue
15- merge_group :
169 # run pipeline from another workflow
1710 workflow_call :
1811 inputs :
@@ -45,15 +38,20 @@ jobs:
4538 - name : Checkout source code
4639 uses : actions/checkout@v4
4740
48- - name : Setup Python 3.11
41+ - name : Setup Python 3.13
4942 uses : actions/setup-python@v5
5043 with :
51- python-version : " 3.11"
44+ python-version : " 3.13"
45+
46+ - name : Set PyPI version
47+ uses : PowerGridModel/pgm-version-bump@main
48+ with :
49+ token : ${{ secrets.GITHUB_TOKEN }}
5250
5351 - name : Build
5452 run : |
55- pip install requests build
56- python set_pypi_version.py
53+ cat PYPI_VERSION
54+ pip install build
5755 python -m build --outdir wheelhouse .
5856
5957 - name : Save version
6664 name : power-grid-model-ds
6765 path : wheelhouse/
6866
69- sonar-cloud :
70- permissions :
71- contents : write
72- runs-on : ubuntu-latest
73- steps :
74-
75- - name : Checkout source code
76- uses : actions/checkout@v4
77- with :
78- fetch-depth : 0 # Shallow clones should be disabled for a better relevancy of analysis
79-
80- - name : Setup Python 3.11
81- uses : actions/setup-python@v5
82- with :
83- python-version : " 3.11"
84-
85- - name : Install in develop mode
86- run : |
87- pip install -e .[dev]
88-
89- - name : Test and Coverage
90- run : |
91- coverage run -m pytest
92- coverage xml
93- coverage report --fail-under=80
94-
95- - name : SonarCloud Scan
96- if : ${{ (github.event_name == 'push') || (github.event.pull_request.head.repo.owner.login == 'PowerGridModel') }}
97- uses : SonarSource/sonarqube-scan-action@v5
98- env :
99- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
100- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
101-
10267 tests :
10368 needs : build-python
10469 strategy :
@@ -129,27 +94,22 @@ jobs:
12994 - name : Unit test and coverage
13095 run : pytest --verbose
13196
132- publish :
97+ github-release :
13398 needs :
13499 - build-python
135100 - tests
136- - sonar-cloud
137101 permissions :
138102 contents : write
139- env :
140- TWINE_USERNAME : ${{ secrets.PYPI_USER }}
141- TWINE_PASSWORD : ${{ secrets.PYPI_PASS }}
142103 runs-on : ubuntu-latest
143104 steps :
105+ - name : Setup Python 3.13
106+ uses : actions/setup-python@v5
107+ with :
108+ python-version : " 3.13"
144109
145110 - name : Checkout source code
146111 uses : actions/checkout@v4 # needed by 'Prevent automatic major/minor release'
147112
148- - name : Setup Python 3.11
149- uses : actions/setup-python@v5
150- with :
151- python-version : " 3.11"
152-
153113 - name : Load built wheel file
154114 uses : actions/download-artifact@v4
155115 with :
@@ -174,20 +134,20 @@ jobs:
174134 env :
175135 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
176136
177- - name : Upload wheels
178- if : (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event.inputs.create_release == 'true'))
179- run : |
180- pip install twine
181- echo "Publish to PyPI..."
182- twine upload --verbose wheelhouse/*
137+ - name : Get tag
138+ id : tag
139+ run : echo "tag=v${{ needs.build-python.outputs.version }}" >> $GITHUB_OUTPUT
140+
141+ - name : Display tag
142+ run : echo "${{ steps.tag.outputs.tag }}"
183143
184144 - name : Release
185- if : (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event. inputs.create_release == 'true') )
145+ if : (inputs.create_release)
186146 uses : softprops/action-gh-release@v2
187147 with :
188148 files : |
189149 ./wheelhouse/*
190- tag_name : v ${{ needs.build-python .outputs.version }}
150+ tag_name : ${{ steps.tag .outputs.tag }}
191151 prerelease : ${{github.ref != 'refs/heads/main'}}
192152 generate_release_notes : true
193153 target_commitish : ${{ github.sha }}
0 commit comments