Skip to content

Commit 2dec2e1

Browse files
committed
publish to pypi
Signed-off-by: Vincent Koppen <[email protected]>
1 parent 6fae7ec commit 2dec2e1

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
6+
name: Build, Test, Sonar and Publish
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
# run pipeline on pull request
13+
pull_request:
14+
# run pipeline on merge queue
15+
merge_group:
16+
# run pipeline from another workflow
17+
workflow_call:
18+
inputs:
19+
create_release:
20+
type: boolean
21+
description: Create a (pre-)release when CI passes
22+
default: false
23+
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
32+
33+
concurrency:
34+
group: ${{ github.workflow }}-${{ github.ref }}-main
35+
cancel-in-progress: true
36+
37+
jobs:
38+
39+
build-python:
40+
runs-on: ubuntu-latest
41+
outputs:
42+
version: ${{ steps.version.outputs.version }}
43+
steps:
44+
45+
- name: Checkout source code
46+
uses: actions/checkout@v4
47+
48+
- name: Setup Python 3.11
49+
uses: actions/setup-python@v5
50+
with:
51+
python-version: "3.11"
52+
53+
- name: Build
54+
run: |
55+
pip install requests build
56+
python set_pypi_version.py
57+
python -m build --outdir wheelhouse .
58+
59+
- name: Save version
60+
id: version
61+
run: echo "version=$(cat PYPI_VERSION)" >> $GITHUB_OUTPUT
62+
63+
- name: Store built wheel file
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: power-grid-model-ds
67+
path: wheelhouse/
68+
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@v4
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
101+
102+
tests:
103+
needs: build-python
104+
strategy:
105+
matrix:
106+
os: [ubuntu-latest, macos-latest, windows-latest]
107+
python: ["3.10", "3.11", "3.12", "3.13"]
108+
fail-fast: false
109+
runs-on: ${{ matrix.os }}
110+
111+
steps:
112+
- name: Checkout source code
113+
uses: actions/checkout@v4
114+
115+
- name: Setup Python ${{ matrix.python }}
116+
uses: actions/setup-python@v5
117+
with:
118+
python-version: ${{ matrix.python }}
119+
120+
- name: Load built wheel file
121+
uses: actions/download-artifact@v4
122+
with:
123+
name: power-grid-model-ds
124+
path: wheelhouse/
125+
126+
- name: Install built wheel file
127+
run: pip install power-grid-model-ds[dev]==${{ needs.build-python.outputs.version }} --find-links=wheelhouse
128+
129+
- name: Unit test and coverage
130+
run: pytest --verbose
131+
132+
publish:
133+
needs:
134+
- build-python
135+
- tests
136+
- sonar-cloud
137+
permissions:
138+
contents: write
139+
env:
140+
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
141+
TWINE_PASSWORD: ${{ secrets.PYPI_PASS }}
142+
runs-on: ubuntu-latest
143+
steps:
144+
- name: Setup Python 3.11
145+
uses: actions/setup-python@v5
146+
with:
147+
python-version: "3.11"
148+
149+
- name: Load built wheel file
150+
uses: actions/download-artifact@v4
151+
with:
152+
name: power-grid-model-ds
153+
path: wheelhouse/
154+
155+
- name: Upload wheels
156+
if: (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event.inputs.create_release == 'true'))
157+
run: |
158+
pip install twine
159+
echo "Publish to PyPI..."
160+
twine upload --verbose wheelhouse/*
161+
162+
- name: Release
163+
if: (github.event_name == 'push') || ((github.event_name == 'workflow_dispatch') && (github.event.inputs.create_release == 'true'))
164+
uses: softprops/action-gh-release@v2
165+
with:
166+
files: |
167+
./wheelhouse/*
168+
tag_name: v${{ needs.build-python.outputs.version }}
169+
prerelease: ${{github.ref != 'refs/heads/main'}}
170+
generate_release_notes: true
171+
target_commitish: ${{ github.sha }}

0 commit comments

Comments
 (0)