mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
## ℹ️ Description - Link to the related issue(s): N/A - Add a CI guard that fails when generated artifacts are out of sync, motivated by preventing missing schema updates and keeping generated reference files current. - Add a committed `docs/config.default.yaml` as a user-facing default configuration reference. ## 📋 Changes Summary - Add `scripts/check_generated_artifacts.py` to regenerate schema artifacts and compare tracked outputs (`schemas/*.json` and `docs/config.default.yaml`) against generated content. - Run the new artifact consistency check in CI via `.github/workflows/build.yml`. - Add `pdm run generate-config` and `pdm run generate-artifacts` tasks, with a cross-platform-safe delete in `generate-config`. - Add generated `docs/config.default.yaml` and document it in `docs/CONFIGURATION.md`. - Update `schemas/config.schema.json` with the `diagnostics.timing_collection` property generated from the model. ### ⚙️ Type of Change Select the type(s) of change(s) included in this pull request: - [ ] 🐞 Bug fix (non-breaking change which fixes an issue) - [x] ✨ New feature (adds new functionality without breaking existing usage) - [ ] 💥 Breaking change (changes that might break existing user setups, scripts, or configurations) ## ✅ Checklist Before requesting a review, confirm the following: - [x] I have reviewed my changes to ensure they meet the project's standards. - [x] I have tested my changes and ensured that all tests pass (`pdm run test`). - [x] I have formatted the code (`pdm run format`). - [x] I have verified that linting passes (`pdm run lint`). - [x] I have updated documentation where necessary. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Added a reference link to the default configuration snapshot for easier access to baseline settings. * **Chores** * Added a CI build-time check that validates generated schemas and the default config and alerts when regeneration is needed. * Added scripts to generate the default config and to sequence artifact generation. * Added a utility to produce standardized schema content and compare generated artifacts. * Minor tweak to schema generation success messaging. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
# SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
# SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
|
|
from pathlib import Path
|
|
|
|
from pydantic import BaseModel
|
|
from schema_utils import generate_schema_content
|
|
|
|
from kleinanzeigen_bot.model.ad_model import AdPartial
|
|
from kleinanzeigen_bot.model.config_model import Config
|
|
|
|
|
|
def generate_schema(model:type[BaseModel], name:str, out_dir:Path) -> None:
|
|
"""
|
|
Generate and write JSON schema for the given model.
|
|
"""
|
|
print(f"[+] Generating schema for model [{name}]...")
|
|
|
|
schema_content = generate_schema_content(model, name)
|
|
|
|
# Write JSON
|
|
json_path = out_dir / f"{name.lower()}.schema.json"
|
|
with json_path.open("w", encoding = "utf-8") as json_file:
|
|
json_file.write(schema_content)
|
|
print(f"[OK] {json_path}")
|
|
|
|
|
|
project_root = Path(__file__).parent.parent
|
|
out_dir = project_root / "schemas"
|
|
out_dir.mkdir(parents = True, exist_ok = True)
|
|
|
|
print(f"Generating schemas in: {out_dir.resolve()}")
|
|
generate_schema(Config, "Config", out_dir)
|
|
generate_schema(AdPartial, "Ad", out_dir)
|
|
print("All schemas generated successfully.")
|