Skip to content

Commit 7e5d6b8

Browse files
feat(actions): add github action workflows (#3)
Signed-off-by: Vincent Koppen <[email protected]> Co-authored-by: Vincent Koppen <[email protected]> Co-authored-by: Thijs Baaijen<[email protected]> Co-authored-by: Jaap Schouten<[email protected]>
1 parent 6fae7ec commit 7e5d6b8

13 files changed

+452
-4
lines changed

.github/dco.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
allowRemediationCommits:
6+
individual: true
7+
thirdParty: true
8+

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
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 }}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
6+
name: Check Blocking Labels
7+
8+
on:
9+
# run pipeline on pull request
10+
pull_request:
11+
types:
12+
- opened
13+
- synchronize
14+
- labeled
15+
- unlabeled
16+
# run pipeline on merge queue
17+
merge_group:
18+
# run this workflow manually from the Actions tab
19+
workflow_dispatch:
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.ref }}-blocking-labels
23+
cancel-in-progress: true
24+
25+
jobs:
26+
check-blocking-labels:
27+
runs-on: ubuntu-latest
28+
steps:
29+
30+
- name: do-not-merge
31+
if: contains(github.event.pull_request.labels.*.name, 'do-not-merge')
32+
run: |
33+
echo "This pull request should not be merged (do-not-merge)"
34+
exit 1
35+
36+
- name: merge-target-first
37+
if: contains(github.event.pull_request.labels.*.name, 'merge-target-first')
38+
run: |
39+
echo "The target branch of this PR should be merged first (merge-target-first)"
40+
exit 2
41+
42+
- name: needs-unit-tests
43+
if: contains(github.event.pull_request.labels.*.name, 'needs-unit-tests')
44+
run: |
45+
echo "This pull request needs (more) unit tests before it may be merged (needs-unit-tests)"
46+
exit 3
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
6+
name: Check Code Quality
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+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}-code-quality
21+
cancel-in-progress: true
22+
23+
jobs:
24+
check-code-quality:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: 3.11
35+
36+
- name: Upgrade pip
37+
run: pip install --upgrade pip
38+
39+
- name: Install dependencies
40+
run: pip install -e .[dev]
41+
42+
- name: Run pre-commit on all files
43+
run: pre-commit run --all-files

.github/workflows/dco-merge-group.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
name: DCO for merge groups
6+
# Workaround because DCO plugin does not run on merge group. See https://github.com/dcoapp/app/issues/199
7+
8+
# Controls when the workflow will run
9+
on:
10+
# run pipeline on merge queue because DCO plugin does not
11+
merge_group:
12+
# Any other signals are handled by the actual DCO plugin
13+
14+
jobs:
15+
dco-merge-group:
16+
name: DCO
17+
runs-on: ubuntu-latest
18+
if: ${{ github.actor != 'dependabot[bot]' }}
19+
steps:
20+
- name: "Workaround for DCO on merge groups"
21+
run: |
22+
echo "Workaround: signal DCO for merge queues because DCO plugin does not run for merge queues. See https://github.com/dcoapp/app/issues/199"

.github/workflows/nightly.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
name: Nightly build
6+
7+
# Controls when the workflow will run
8+
on:
9+
workflow_dispatch:
10+
schedule:
11+
- cron: "0 2 * * *" # Based on UTC time
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}-nightly
15+
cancel-in-progress: true
16+
17+
jobs:
18+
main:
19+
uses: "./.github/workflows/build-test-and-sonar.yml"
20+
permissions:
21+
contents: write
22+
with:
23+
create_release: false
24+
25+
check-code-quality:
26+
uses: "./.github/workflows/check-code-quality.yml"
27+
28+
reuse-compliance:
29+
uses: "./.github/workflows/reuse-compliance.yml"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
6+
name: REUSE Compliance Check
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+
# run this workflow manually from the Actions tab
19+
workflow_dispatch:
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.ref }}-reuse-compliance
23+
cancel-in-progress: true
24+
25+
jobs:
26+
reuse-compliance-check:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: checkout
30+
uses: actions/checkout@v4
31+
- name: REUSE Compliance Check
32+
uses: fsfe/reuse-action@v5

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.1
1+
0.0

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,7 @@ unfixable = []
104104

105105
[tool.mypy]
106106
disable_error_code = ["assignment", "import-untyped"]
107+
108+
[tool.coverage.run]
109+
relative_files = true
110+
branch = true

0 commit comments

Comments
 (0)