From 9ab26a6e8c8eb0660bf14432cc35976005f42798 Mon Sep 17 00:00:00 2001 From: staticdev Date: Wed, 24 Sep 2025 16:20:25 +0000 Subject: [PATCH 1/2] ci: Add intentfest validate with errors for changed files --- .github/workflows/ci.yaml | 17 ++++++++++++- script/intentfest/validate.py | 46 ++++++++++++++++++++++++++++++++++- script/lint | 2 -- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a53086fa19..a9c013dfb3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,7 +32,8 @@ jobs: - name: Register intentfest problem matcher run: | echo "::add-matcher::.github/workflows/matchers/intentfest.json" - - run: script/lint + - name: Run lint + run: script/lint - name: Get changed files if: github.event_name == 'pull_request' id: changed-files @@ -65,6 +66,20 @@ jobs: echo "languages=$LANGUAGES" | tee -a $GITHUB_OUTPUT fi + - name: Run intentfest validate + env: + LANGUAGES: ${{ steps.extract-languages.outputs.languages }} + CHANGED_FILES_JSON: ${{ steps.changed-files.outputs.all_changed_files }} + IS_PR: ${{ github.event_name == 'pull_request' }} + run: | + if [ "$IS_PR" = "true" ] && [ -n "${LANGUAGES}" ] && [ -n "${CHANGED_FILES_JSON}" ]; then + echo "Running intentfest validate for languages=${{ steps.extract-languages.outputs.languages }} with error-on-warn-pr" + python3 -m script.intentfest validate --language "${LANGUAGES}" --changed-files-json "${CHANGED_FILES_JSON}" --error-on-warn-pr + else + echo "Running full intentfest validate" + python3 -m script.intentfest validate + fi + - name: Run tests env: is_pr: ${{ github.event_name == 'pull_request' }} diff --git a/script/intentfest/validate.py b/script/intentfest/validate.py index cd48f80f30..f28e4576dd 100644 --- a/script/intentfest/validate.py +++ b/script/intentfest/validate.py @@ -4,6 +4,7 @@ import argparse import itertools +import json from collections import Counter, defaultdict from collections.abc import Callable, Collection from datetime import datetime @@ -527,6 +528,16 @@ def get_arguments() -> argparse.Namespace: parser.add_argument( "--language", type=str, choices=LANGUAGES, help="The language to validate." ) + parser.add_argument( + "--error-on-warn-pr", + action="store_true", + help="Treat warnings in PR-changed files as errors.", + ) + parser.add_argument( + "--changed-files-json", + type=str, + help="JSON array of changed file paths (used by CI to pass changed files)", + ) return parser.parse_args() @@ -667,10 +678,43 @@ def run() -> int: # Remove language if no errors if not errors[language]: errors.pop(language) - if not warnings[language]: warnings.pop(language) + if args.error_on_warn_pr and warnings: + # Require changed files to be provided when running in PR error-on-warn mode + if not args.changed_files_json: + print("error: --error-on-warn-pr requires --changed-files-json in CI") + return 2 + + try: + changed_files = json.loads(args.changed_files_json) + except Exception as err: + print(f"Failed to parse changed files JSON: {err}") + return 2 + + # Check if any warning is for a changed file + warn_files = set() + for language, language_warnings in warnings.items(): + for warning in language_warnings: + # Try to extract file path from warning string + import re + + m = re.match(r"([^:]+):", warning) + if m: + warn_files.add(m.group(1)) + matched_files = [ + f for f in changed_files if any(f.endswith(wf) for wf in warn_files) + ] + if matched_files: + print("Validation warnings in changed PR files:") + for language, language_warnings in warnings.items(): + for warning in language_warnings: + for f in matched_files: + if f in warning: + print(f"[ERROR] {warning}") + return 1 + if errors: print("Validation failed") print() diff --git a/script/lint b/script/lint index bf29f021f7..a20a788b18 100755 --- a/script/lint +++ b/script/lint @@ -27,7 +27,5 @@ flake8 "${python_files[@]}" pylint "${python_files[@]}" mypy "${python_files[@]}" -python3 -m script.intentfest validate - # prettier pre-commit run prettier --all-files --verbose From 272535419fa7bb2907ee602ec506e60f4ea2943b Mon Sep 17 00:00:00 2001 From: staticdev Date: Wed, 24 Sep 2025 16:54:40 +0000 Subject: [PATCH 2/2] Make sure it will fail with a change in a language --- responses/ar/HassTurnOff.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/responses/ar/HassTurnOff.yaml b/responses/ar/HassTurnOff.yaml index 62e609fce7..e0e0a53b29 100644 --- a/responses/ar/HassTurnOff.yaml +++ b/responses/ar/HassTurnOff.yaml @@ -37,3 +37,4 @@ responses: cover_device_class: "تم اغلاق {{ slots.device_class }}" unlock: "تم الفتح" valve: "تم الفتح" + unused: new unused response