From 7747a96f3225d3e38262e19f0abe298f3c519c67 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 15 Apr 2026 14:01:47 +0000 Subject: [PATCH 1/2] chore(ci): update auto-versioning to use dgaida/auto-version-action - Switched the `auto-version.yml` workflow to use `dgaida/auto-version-action@main`. - Updated `scripts/bump_version.py` to synchronize version increment logic (0-9 overflow) and added a `--no-pyproject` flag. - Integrated auxiliary file updates and changelog generation into the new action's execution flow. - Changed workflow trigger to push on master to align with action recommendations. Co-authored-by: dgaida <23057824+dgaida@users.noreply.github.com> --- .github/workflows/auto-version.yml | 26 +++++++++++--------------- scripts/bump_version.py | 28 ++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/workflows/auto-version.yml b/.github/workflows/auto-version.yml index 2b8dde8..f94b12b 100644 --- a/.github/workflows/auto-version.yml +++ b/.github/workflows/auto-version.yml @@ -1,8 +1,7 @@ name: Auto Versioning on: - pull_request: - types: [closed] + push: branches: - master @@ -11,23 +10,21 @@ permissions: jobs: bump-version: - if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - ref: master - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.11' - - name: Bump version + - name: Bump auxiliary files id: bump - run: python scripts/bump_version.py + run: python scripts/bump_version.py --no-pyproject - name: Generate Changelog uses: orhun/git-cliff-action@v4 @@ -44,23 +41,22 @@ jobs: fi done - - name: Commit and Tag + - name: Stage auxiliary changes run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" # Add modified files, ignore those that don't exist - FILES="pyproject.toml pyadm1/__version__.py tests/__init__.py CHANGELOG.md docs/en/metrics.md docs/de/metrics.md docs/en/CHANGELOG.md docs/de/CHANGELOG.md" + FILES="pyadm1/__version__.py tests/__init__.py CHANGELOG.md docs/en/metrics.md docs/de/metrics.md docs/en/CHANGELOG.md docs/de/CHANGELOG.md" for f in $FILES; do if [ -f "$f" ]; then git add "$f" fi done - if ! git diff --cached --quiet; then - git commit -m "chore(release): bump version to ${{ steps.bump.outputs.new_version }} [skip ci]" - git tag -a v${{ steps.bump.outputs.new_version }} -m "Release v${{ steps.bump.outputs.new_version }}" - git push origin master --tags - else - echo "No changes to commit" - fi + - name: Auto Version and Badges + uses: dgaida/auto-version-action@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + auto-version: true + create-badge: true diff --git a/scripts/bump_version.py b/scripts/bump_version.py index 85236e3..ff8200b 100644 --- a/scripts/bump_version.py +++ b/scripts/bump_version.py @@ -1,6 +1,7 @@ import os import re import sys +import argparse from datetime import date @@ -9,7 +10,15 @@ def bump_version(current_version): if len(parts) != 3: raise ValueError(f"Invalid version format: {current_version}") major, minor, patch = map(int, parts) + patch += 1 + if patch > 9: + patch = 0 + minor += 1 + if minor > 9: + minor = 0 + major += 1 + return f"{major}.{minor}.{patch}" @@ -30,6 +39,10 @@ def update_file(filepath, pattern, replacement, flags=0): def main(): + parser = argparse.ArgumentParser(description="Bump project version.") + parser.add_argument("--no-pyproject", action="store_true", help="Skip updating pyproject.toml") + args = parser.parse_args() + pyproject_path = "pyproject.toml" if not os.path.exists(pyproject_path): print(f"Error: {pyproject_path} not found.") @@ -55,12 +68,15 @@ def main(): print(f"Bumping version: {current_version} -> {new_version}") - # pyproject.toml: only update version in [project] section - update_file( - "pyproject.toml", - r'(\[project\]\n(?:.*\n)*?version\s*=\s*)"[^"]*"', - r'\g<1>"' + new_version + '"', - ) + # pyproject.toml: only update version in [project] section if not skipped + if not args.no_pyproject: + update_file( + "pyproject.toml", + r'(\[project\]\n(?:.*\n)*?version\s*=\s*)"[^"]*"', + r'\g<1>"' + new_version + '"', + ) + else: + print("Skipping pyproject.toml update as requested.") # Other files updates = [ From 3168f1bd3ebf028376cc9790dbe1be09f03a8c1e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 15 Apr 2026 14:33:30 +0000 Subject: [PATCH 2/2] chore(ci): modernize versioning with dgaida/auto-version-action - Switched to `dgaida/auto-version-action@main` for versioning, tagging, and badges. - Implemented dynamic version resolution in `pyadm1/__init__.py` using `importlib.metadata`. - Removed redundant `pyadm1/__version__.py`, `tests/__init__.py` version string, and `scripts/bump_version.py`. - Cleaned up hardcoded version/date metrics in bilingual documentation. - Simplified `auto-version.yml` workflow to only handle changelog generation and the new action. Co-authored-by: dgaida <23057824+dgaida@users.noreply.github.com> --- .github/workflows/auto-version.yml | 16 +--- docs/de/metrics.md | 11 ++- docs/en/metrics.md | 11 ++- pyadm1/__init__.py | 12 ++- pyadm1/__version__.py | 9 -- scripts/bump_version.py | 127 ----------------------------- tests/__init__.py | 2 - 7 files changed, 23 insertions(+), 165 deletions(-) delete mode 100644 pyadm1/__version__.py delete mode 100644 scripts/bump_version.py diff --git a/.github/workflows/auto-version.yml b/.github/workflows/auto-version.yml index f94b12b..d522647 100644 --- a/.github/workflows/auto-version.yml +++ b/.github/workflows/auto-version.yml @@ -22,15 +22,10 @@ jobs: with: python-version: '3.11' - - name: Bump auxiliary files - id: bump - run: python scripts/bump_version.py --no-pyproject - - name: Generate Changelog uses: orhun/git-cliff-action@v4 with: config: cliff.toml - args: --tag v${{ steps.bump.outputs.new_version }} outputPath: CHANGELOG.md - name: Sync Changelogs @@ -41,18 +36,11 @@ jobs: fi done - - name: Stage auxiliary changes + - name: Stage changes run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - - # Add modified files, ignore those that don't exist - FILES="pyadm1/__version__.py tests/__init__.py CHANGELOG.md docs/en/metrics.md docs/de/metrics.md docs/en/CHANGELOG.md docs/de/CHANGELOG.md" - for f in $FILES; do - if [ -f "$f" ]; then - git add "$f" - fi - done + git add CHANGELOG.md docs/en/CHANGELOG.md docs/de/CHANGELOG.md - name: Auto Version and Badges uses: dgaida/auto-version-action@main diff --git a/docs/de/metrics.md b/docs/de/metrics.md index 68886f5..0c80fe0 100644 --- a/docs/de/metrics.md +++ b/docs/de/metrics.md @@ -10,10 +10,10 @@ Aktuelle Abdeckung: **98.1%** (Ziel: 95%) | Modul | Abdeckung | |-------|-----------| -| `pyadm1.core` | 98.1% | -| `pyadm1.components` | 98.5% | -| `pyadm1.simulation` | 100.0% | -| `pyadm1.configurator` | 98.2% | +| \`pyadm1.core\` | 98.1% | +| \`pyadm1.components\` | 98.5% | +| \`pyadm1.simulation\` | 100.0% | +| \`pyadm1.configurator\` | 98.2% | ## Build-Status @@ -24,5 +24,4 @@ Aktuelle Abdeckung: **98.1%** (Ziel: 95%) ## Wartung -- **Changelog**: Aktuell (v0.1.3) -- **Zuletzt aktualisiert**: 07.04.2026 +Bitte beachten Sie die [Haupt-README](../../README.md) für die aktuelle Version und den Wartungsstatus. diff --git a/docs/en/metrics.md b/docs/en/metrics.md index e62a127..63f3548 100644 --- a/docs/en/metrics.md +++ b/docs/en/metrics.md @@ -10,10 +10,10 @@ Current coverage: **98.1%** (Target: 95%) | Module | Coverage | |--------|----------| -| `pyadm1.core` | 98.1% | -| `pyadm1.components` | 98.5% | -| `pyadm1.simulation` | 100.0% | -| `pyadm1.configurator` | 98.2% | +| \`pyadm1.core\` | 98.1% | +| \`pyadm1.components\` | 98.5% | +| \`pyadm1.simulation\` | 100.0% | +| \`pyadm1.configurator\` | 98.2% | ## Build Status @@ -24,5 +24,4 @@ Current coverage: **98.1%** (Target: 95%) ## Maintenance -- **Changelog**: Up to date (v0.1.3) -- **Last Updated**: 2026-04-07 +Please see the [main README](../../README.md) for the latest version and maintenance status. diff --git a/pyadm1/__init__.py b/pyadm1/__init__.py index e8fc70a..1c3dc71 100644 --- a/pyadm1/__init__.py +++ b/pyadm1/__init__.py @@ -26,7 +26,17 @@ >>> results = plant.simulate(duration=30, dt=1/24) """ -from pyadm1.__version__ import __version__ +try: + from importlib.metadata import version, PackageNotFoundError +except ImportError: # pragma: no cover + # For Python < 3.8 + from importlib_metadata import version, PackageNotFoundError # type: ignore + +try: + __version__ = version("pyadm1") +except PackageNotFoundError: # pragma: no cover + # package is not installed + __version__ = "unknown" # Core imports from .configurator import BiogasPlant diff --git a/pyadm1/__version__.py b/pyadm1/__version__.py deleted file mode 100644 index 0ec7748..0000000 --- a/pyadm1/__version__.py +++ /dev/null @@ -1,9 +0,0 @@ -# ============================================================================ -# pyadm1/__version__.py -# ============================================================================ -"""Version information for PyADM1.""" - -__version__ = "0.1.3" -__author__ = "Daniel Gaida" -__email__ = "daniel.gaida@th-koeln.de" -__license__ = "MIT" diff --git a/scripts/bump_version.py b/scripts/bump_version.py deleted file mode 100644 index ff8200b..0000000 --- a/scripts/bump_version.py +++ /dev/null @@ -1,127 +0,0 @@ -import os -import re -import sys -import argparse -from datetime import date - - -def bump_version(current_version): - parts = current_version.split(".") - if len(parts) != 3: - raise ValueError(f"Invalid version format: {current_version}") - major, minor, patch = map(int, parts) - - patch += 1 - if patch > 9: - patch = 0 - minor += 1 - if minor > 9: - minor = 0 - major += 1 - - return f"{major}.{minor}.{patch}" - - -def update_file(filepath, pattern, replacement, flags=0): - if not os.path.exists(filepath): - print(f"Warning: {filepath} not found.") - return - with open(filepath, "r", encoding="utf-8") as f: - content = f.read() - - new_content, count = re.subn(pattern, replacement, content, flags=flags) - if count == 0: - print(f"Warning: No matches found for pattern in {filepath}") - else: - with open(filepath, "w", encoding="utf-8") as f: - f.write(new_content) - print(f"Updated {filepath} ({count} replacements)") - - -def main(): - parser = argparse.ArgumentParser(description="Bump project version.") - parser.add_argument("--no-pyproject", action="store_true", help="Skip updating pyproject.toml") - args = parser.parse_args() - - pyproject_path = "pyproject.toml" - if not os.path.exists(pyproject_path): - print(f"Error: {pyproject_path} not found.") - sys.exit(1) - - with open(pyproject_path, "r", encoding="utf-8") as f: - content = f.read() - - # Specifically look for version in [project] section - match = re.search(r'\[project\]\n(?:.*\n)*?version\s*=\s*"([^"]*)"', content) - if not match: - # Fallback to general search if section not found exactly as expected - match = re.search(r'^version\s*=\s*"([^"]*)"', content, re.MULTILINE) - - if not match: - print("Error: Could not find version in pyproject.toml") - sys.exit(1) - - current_version = match.group(1) - new_version = bump_version(current_version) - today_iso = date.today().isoformat() - today_german = date.today().strftime("%d.%m.%Y") - - print(f"Bumping version: {current_version} -> {new_version}") - - # pyproject.toml: only update version in [project] section if not skipped - if not args.no_pyproject: - update_file( - "pyproject.toml", - r'(\[project\]\n(?:.*\n)*?version\s*=\s*)"[^"]*"', - r'\g<1>"' + new_version + '"', - ) - else: - print("Skipping pyproject.toml update as requested.") - - # Other files - updates = [ - ( - "pyadm1/__version__.py", - r'(__version__\s*=\s*)"[^"]*"', - r'\g<1>"' + new_version + '"', - ), - ( - "tests/__init__.py", - r'(__version__\s*=\s*)"[^"]*"', - r'\g<1>"' + new_version + '"', - ), - ( - "docs/en/metrics.md", - r"(\*\*Changelog\*\*:\s*Up to date \(v)[^)]*(\))", - r"\g<1>" + new_version + r"\g<2>", - ), - ( - "docs/en/metrics.md", - r"(\*\*Last Updated\*\*:\s*)\d{4}-\d{2}-\d{2}", - r"\g<1>" + today_iso, - ), - ( - "docs/de/metrics.md", - r"(\*\*Changelog\*\*:\s*Aktuell \(v)[^)]*(\))", - r"\g<1>" + new_version + r"\g<2>", - ), - ( - "docs/de/metrics.md", - r"(\*\*Zuletzt aktualisiert\*\*:\s*)\d{2}\.\d{2}\.\d{4}", - r"\g<1>" + today_german, - ), - ] - - for filepath, pattern, replacement in updates: - update_file(filepath, pattern, replacement) - - github_output = os.environ.get("GITHUB_OUTPUT") - if github_output: - with open(github_output, "a") as f: - f.write(f"new_version={new_version}\n") - - print(f"Successfully bumped version to {new_version}") - - -if __name__ == "__main__": - main() diff --git a/tests/__init__.py b/tests/__init__.py index c410be7..fc387b8 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -4,5 +4,3 @@ This package contains unit tests for the PyADM1 implementation of the Anaerobic Digestion Model No. 1. """ - -__version__ = "0.1.3"