Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' }}
Expand Down
1 change: 1 addition & 0 deletions responses/ar/HassTurnOff.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: ar
responses:
intents:
Expand Down Expand Up @@ -37,3 +37,4 @@
cover_device_class: "تم اغلاق {{ slots.device_class }}"
unlock: "تم الفتح"
valve: "تم الفتح"
unused: new unused response
46 changes: 45 additions & 1 deletion script/intentfest/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading