Skip to content

Commit 054e7bf

Browse files
mgoversThijss
andauthored
ci: homogenize github actions workflows + use trusted publisher (#67)
* homogenize github actions workflows + use trusted publisher Signed-off-by: Martijn Govers <[email protected]> * always release for testing purposes Signed-off-by: Martijn Govers <[email protected]> * fix syntax Signed-off-by: Martijn Govers <[email protected]> * fix typo Signed-off-by: Martijn Govers <[email protected]> * revert test changes Signed-off-by: Martijn Govers <[email protected]> * Update .github/workflows/build-test-release.yml Signed-off-by: Martijn Govers <[email protected]> Co-authored-by: Thijs Baaijen <[email protected]> Signed-off-by: Martijn Govers <[email protected]> * fix ci-passed cfr. PowerGridModel/power-grid-model#1015 Signed-off-by: Martijn Govers <[email protected]> * Feat/test new pypi (#69) * move comments Signed-off-by: Thijs Baaijen <[email protected]> * enable test pypi Signed-off-by: Thijs Baaijen <[email protected]> * Fix typing issue for numpy 2.3 and python 3.11 (#70) Signed-off-by: Thijs Baaijen <[email protected]> --------- Signed-off-by: Thijs Baaijen <[email protected]> --------- Signed-off-by: Martijn Govers <[email protected]> Signed-off-by: Martijn Govers <[email protected]> Signed-off-by: Thijs Baaijen <[email protected]> Co-authored-by: Thijs Baaijen <[email protected]>
1 parent 00698d5 commit 054e7bf

File tree

8 files changed

+180
-158
lines changed

8 files changed

+180
-158
lines changed

.github/workflows/build-test-and-sonar.yml renamed to .github/workflows/build-test-release.yml

Lines changed: 23 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
33
# SPDX-License-Identifier: MPL-2.0
44

55

6-
name: Build, Test, Sonar and Publish
6+
name: Build, Test and Release
77

88
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:
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
@@ -66,39 +64,6 @@ jobs:
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 }}

.github/workflows/check-code-quality.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
name: Check Code Quality
77

88
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:
169
# run pipeline from another workflow
1710
workflow_call:
1811

.github/workflows/ci.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
6+
name: CI Build
7+
8+
on:
9+
push:
10+
branches:
11+
- main # run pipeline on pull request
12+
pull_request:
13+
merge_group: # run pipeline on merge queue
14+
workflow_dispatch: # run this workflow manually from the Actions tab
15+
inputs:
16+
create_release:
17+
type: boolean
18+
description: Create a (pre-)release when CI passes
19+
default: false
20+
required: true
21+
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}-ci-build
24+
cancel-in-progress: true
25+
26+
jobs:
27+
ci-started:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- run: echo "ci started"
31+
32+
build-test-release:
33+
name: build-test-release
34+
uses: "./.github/workflows/build-test-release.yml"
35+
permissions:
36+
contents: write
37+
with:
38+
create_release: ${{ (github.event_name == 'workflow_dispatch' && inputs.create_release) || (github.event_name == 'push') }}
39+
40+
check-code-quality:
41+
uses: "./.github/workflows/check-code-quality.yml"
42+
43+
reuse-compliance:
44+
uses: "./.github/workflows/reuse-compliance.yml"
45+
46+
ci-passed:
47+
runs-on: ubuntu-latest
48+
needs: [ci-started, build-test-release, check-code-quality, reuse-compliance]
49+
if: always()
50+
51+
steps:
52+
# this explicit check is needed cfr. https://github.com/orgs/community/discussions/75568
53+
- name: "Check whether all jobs passed"
54+
run: echo '${{ toJSON(needs) }}' | jq -e 'to_entries | all(.value.result == "success")'
55+
- run: echo "ci passed"
56+
57+
publish:
58+
name: Publish to PyPI
59+
runs-on: ubuntu-latest
60+
permissions:
61+
contents: write
62+
id-token: write # Required for Trusted Publishing
63+
needs: build-test-release
64+
if: (github.event_name == 'workflow_dispatch' && inputs.create_release) || github.event_name == 'push'
65+
66+
steps:
67+
- name: Download assets from GitHub release
68+
uses: robinraju/release-downloader@v1
69+
with:
70+
repository: ${{ github.repository }}
71+
# download the latest release
72+
latest: true
73+
# don't download pre-releases
74+
preRelease: false
75+
fileName: "*"
76+
# don't download GitHub-generated source tar and zip files
77+
tarBall: false
78+
zipBall: false
79+
# create a directory to store the downloaded assets
80+
out-file-path: assets-to-publish
81+
# don't extract downloaded files
82+
extract: false
83+
84+
- name: List downloaded assets
85+
run: ls -la assets-to-publish
86+
87+
- name: Upload assets to PyPI
88+
uses: pypa/gh-action-pypi-publish@release/v1
89+
with:
90+
# To test, use the TestPyPI:
91+
repository-url: https://test.pypi.org/legacy/
92+
# You must also create an account and project on TestPyPI,
93+
# as well as set the trusted-publisher in the project settings:
94+
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
95+
# To publish to the official PyPI repository, just keep
96+
# repository-url commented out.
97+
packages-dir: assets-to-publish
98+
skip-existing: true
99+
print-hash: true
100+
verbose: true

.github/workflows/nightly.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
jobs:
18-
main:
19-
uses: "./.github/workflows/build-test-and-sonar.yml"
18+
build-test-release:
19+
uses: "./.github/workflows/build-test-release.yml"
2020
permissions:
2121
contents: write
2222
with:

.github/workflows/reuse-compliance.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
name: REUSE Compliance Check
77

88
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:
169
# run pipeline from another workflow
1710
workflow_call:
1811
# run this workflow manually from the Actions tab

.github/workflows/sonar.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
name: Sonar Cloud
6+
7+
on:
8+
# run pipeline on push event of main branch
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+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}-sonar
19+
cancel-in-progress: true
20+
21+
jobs:
22+
sonar-cloud:
23+
permissions:
24+
contents: write
25+
runs-on: ubuntu-latest
26+
steps:
27+
28+
- name: Checkout source code
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
32+
33+
- name: Setup Python 3.11
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: "3.11"
37+
38+
- name: Install in develop mode
39+
run: |
40+
pip install -e .[dev]
41+
42+
- name: Test and Coverage
43+
run: |
44+
coverage run -m pytest
45+
coverage xml
46+
coverage report --fail-under=80
47+
48+
- name: SonarCloud Scan
49+
if: ${{ (github.event_name == 'push') || (github.event.pull_request.head.repo.owner.login == 'PowerGridModel') }}
50+
uses: SonarSource/sonarqube-scan-action@v5
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ SPDX-License-Identifier: MPL-2.0
99
[![Downloads](https://static.pepy.tech/badge/power-grid-model-ds)](https://pepy.tech/project/power-grid-model-ds)
1010
[![Downloads](https://static.pepy.tech/badge/power-grid-model-ds/month)](https://pepy.tech/project/power-grid-model-ds)
1111

12-
[![Build and Test Python](https://github.com/PowerGridModel/power-grid-model-ds/actions/workflows/build-test-and-sonar.yml/badge.svg)](https://github.com/PowerGridModel/power-grid-model-ds/actions/workflows/build-test-and-sonar.yml)
13-
[![Check Code Quality](https://github.com/PowerGridModel/power-grid-model-ds/actions/workflows/check-code-quality.yml/badge.svg)](https://github.com/PowerGridModel/power-grid-model-ds/actions/workflows/check-code-quality.yml)
14-
[![REUSE Compliance Check](https://github.com/PowerGridModel/power-grid-model-ds/actions/workflows/reuse-compliance.yml/badge.svg)](https://github.com/PowerGridModel/power-grid-model-ds/actions/workflows/reuse-compliance.yml)
12+
[![CI Build](https://github.com/PowerGridModel/power-grid-model-ds/actions/workflows/ci.yml/badge.svg)](https://github.com/PowerGridModel/power-grid-model-ds/actions/workflows/ci.yml)
1513
[![docs](https://readthedocs.org/projects/power-grid-model-ds/badge/)](https://power-grid-model-ds.readthedocs.io/en/stable/)
1614

1715
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=PowerGridModel_power-grid-model-ds&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=PowerGridModel_power-grid-model-ds)
@@ -25,7 +23,7 @@ SPDX-License-Identifier: MPL-2.0
2523

2624
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14825565.svg)](https://zenodo.org/record/14825565)
2725

28-
[![](https://github.com/PowerGridModel/.github/blob/main/artwork/svg/color.svg)](#)
26+
[![Power Grid Model logo](https://github.com/PowerGridModel/.github/blob/main/artwork/svg/color.svg)](#)
2927

3028
# Power Grid Model Data Science (DS)
3129

0 commit comments

Comments
 (0)