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 :
2114 description : Create a (pre-)release when CI passes
2215 default : false
2316 required : false
24- # run this workflow manually from the Actions tab
25- workflow_dispatch :
26- inputs :
27- create_release :
28- type : boolean
29- description : Create a (pre-)release when CI passes
30- default : false
31- required : true
17+ outputs :
18+ tag :
19+ description : " The created release tag"
20+ value : ${{ jobs.github-release.outputs.tag }}
3221
3322concurrency :
3423 group : ${{ github.workflow }}-${{ github.ref }}-main
3524 cancel-in-progress : true
3625
3726jobs :
38-
3927 build-python :
4028 runs-on : ubuntu-latest
4129 outputs :
@@ -45,15 +33,20 @@ jobs:
4533 - name : Checkout source code
4634 uses : actions/checkout@v4
4735
48- - name : Setup Python 3.11
36+ - name : Setup Python 3.13
4937 uses : actions/setup-python@v5
5038 with :
51- python-version : " 3.11"
39+ python-version : " 3.13"
40+
41+ - name : Set PyPI version
42+ uses : PowerGridModel/pgm-version-bump@main
43+ with :
44+ token : ${{ secrets.GITHUB_TOKEN }}
5245
5346 - name : Build
5447 run : |
55- pip install requests build
56- python set_pypi_version.py
48+ cat PYPI_VERSION
49+ pip install build
5750 python -m build --outdir wheelhouse .
5851
5952 - name : Save version
@@ -66,44 +59,11 @@ jobs:
6659 name : power-grid-model-ds
6760 path : wheelhouse/
6861
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-
10262 tests :
10363 needs : build-python
10464 strategy :
10565 matrix :
106- os : [ubuntu-latest, macos-latest, windows-latest]
66+ os : [ ubuntu-latest, macos-latest, windows-latest ]
10767 python : ["3.11", "3.12", "3.13"]
10868 fail-fast : false
10969 runs-on : ${{ matrix.os }}
@@ -129,27 +89,24 @@ jobs:
12989 - name : Unit test and coverage
13090 run : pytest --verbose
13191
132- publish :
92+ github-release :
13393 needs :
13494 - build-python
13595 - tests
136- - sonar-cloud
13796 permissions :
13897 contents : write
139- env :
140- TWINE_USERNAME : ${{ secrets.PYPI_USER }}
141- TWINE_PASSWORD : ${{ secrets.PYPI_PASS }}
14298 runs-on : ubuntu-latest
99+ outputs :
100+ tag : ${{ steps.tag.outputs.tag }}
143101 steps :
102+ - name : Setup Python 3.13
103+ uses : actions/setup-python@v5
104+ with :
105+ python-version : " 3.13"
144106
145107 - name : Checkout source code
146108 uses : actions/checkout@v4 # needed by 'Prevent automatic major/minor release'
147109
148- - name : Setup Python 3.11
149- uses : actions/setup-python@v5
150- with :
151- python-version : " 3.11"
152-
153110 - name : Load built wheel file
154111 uses : actions/download-artifact@v4
155112 with :
@@ -174,20 +131,20 @@ jobs:
174131 env :
175132 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
176133
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/*
134+ - name : Get tag
135+ id : tag
136+ run : echo "tag=v${{ needs.build-python.outputs.version }}" >> $GITHUB_OUTPUT
137+
138+ - name : Display tag
139+ run : echo "${{ steps.tag.outputs.tag }}"
183140
184141 - name : Release
185- if : (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event. inputs.create_release == 'true') )
142+ if : (inputs.create_release)
186143 uses : softprops/action-gh-release@v2
187144 with :
188145 files : |
189146 ./wheelhouse/*
190- tag_name : v ${{ needs.build-python .outputs.version }}
147+ tag_name : ${{ steps.tag .outputs.tag }}
191148 prerelease : ${{github.ref != 'refs/heads/main'}}
192149 generate_release_notes : true
193150 target_commitish : ${{ github.sha }}
0 commit comments