Skip to content

Commit 9075877

Browse files
committed
Merge branch 'main' of https://github.com/PowerGridModel/power-grid-model-ds into enable-publish
2 parents 2dec2e1 + 7e5d6b8 commit 9075877

File tree

12 files changed

+281
-4
lines changed

12 files changed

+281
-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: 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
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

set_pypi_version.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
# script to set version dynamically
6+
# read VERSION and PyPI, set PYPI_VERSION
7+
8+
9+
import os
10+
from pathlib import Path
11+
12+
import requests
13+
14+
15+
def set_version(pkg_dir: Path):
16+
with open(pkg_dir / "VERSION") as f:
17+
version = f.read().strip().strip("\n")
18+
major, minor = (int(x) for x in version.split("."))
19+
latest_major, latest_minor, latest_patch = get_pypi_latest()
20+
# get version
21+
version = get_new_version(major, minor, latest_major, latest_minor, latest_patch)
22+
# mutate version in GitHub Actions
23+
if ("GITHUB_SHA" in os.environ) and ("GITHUB_REF" in os.environ) and ("GITHUB_RUN_NUMBER" in os.environ):
24+
sha = os.environ["GITHUB_SHA"]
25+
ref = os.environ["GITHUB_REF"]
26+
build_number = os.environ["GITHUB_RUN_NUMBER"]
27+
# short hash number in numeric
28+
short_hash = f"{int(f'0x{sha[0:6]}', base=16):08}"
29+
30+
if "main" in ref:
31+
# main branch
32+
# major.minor.patch
33+
# do nothing
34+
pass
35+
else:
36+
# feature branch
37+
# major.minor.patch a 1 build_number short_hash
38+
version += f"a1{build_number}{short_hash}"
39+
with open(pkg_dir / "PYPI_VERSION", "w") as f:
40+
f.write(version)
41+
42+
43+
def get_pypi_latest():
44+
response = requests.get("https://pypi.org/pypi/power-grid-model-ds/json")
45+
if response.status_code == 404:
46+
return 0, 0, 0
47+
data = response.json()
48+
version = str(data["info"]["version"])
49+
return (int(x) for x in version.split("."))
50+
51+
52+
def get_new_version(major, minor, latest_major, latest_minor, latest_patch):
53+
if (major > latest_major) or ((major == latest_major) and minor > latest_minor):
54+
# brand-new version with patch zero
55+
return f"{major}.{minor}.0"
56+
57+
if major == latest_major and minor == latest_minor:
58+
# current version, increment path
59+
return f"{major}.{minor}.{latest_patch + 1}"
60+
61+
# does not allow building older version
62+
raise ValueError(
63+
"Invalid version number!\n"
64+
f"latest version: {latest_major}.{latest_minor}.{latest_patch}\n"
65+
f"to be built version: {major}.{minor}\n"
66+
)
67+
68+
69+
if __name__ == "__main__":
70+
set_version(Path(__file__).parent)

0 commit comments

Comments
 (0)