Skip to content
Merged
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
24 changes: 17 additions & 7 deletions .github/scripts/validate_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def main():
parser.add_argument('--directory', '-d', default='.', help='Directory to scan for files')
parser.add_argument('--check-json', action='store_true', help='Check JSON files')
parser.add_argument('--check-yaml', action='store_true', help='Check YAML files')
parser.add_argument('--changed-files', nargs='*', help='List of changed files to validate')

args = parser.parse_args()

Expand All @@ -62,17 +63,26 @@ def main():

all_valid = True

if args.check_json:
json_files = find_files(args.directory, '.json')
print(f"Found {len(json_files)} JSON files")
# If changed files are provided, filter them by extension
if args.changed_files:
json_files = [f for f in args.changed_files if f.endswith('.json')]
yaml_files = [f for f in args.changed_files if f.endswith('.yaml') or f.endswith('.yml')]
else:
# Otherwise, find all files in directory
json_files = find_files(args.directory, '.json') if args.check_json else []
yaml_files = []
if args.check_yaml:
yaml_files = find_files(args.directory, '.yaml')
yaml_files += find_files(args.directory, '.yml')

if args.check_json and json_files:
print(f"Found {len(json_files)} JSON files to validate")
for file_path in json_files:
if not validate_json(file_path):
all_valid = False

if args.check_yaml:
yaml_files = find_files(args.directory, '.yaml')
yaml_files += find_files(args.directory, '.yml')
print(f"Found {len(yaml_files)} YAML files")
if args.check_yaml and yaml_files:
print(f"Found {len(yaml_files)} YAML files to validate")
for file_path in yaml_files:
if not validate_yaml(file_path):
all_valid = False
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
files: |
**/*.json
**/*.yaml
**/*.yml

- name: Set up Python
uses: actions/setup-python@v4
with:
Expand All @@ -25,4 +34,9 @@ jobs:

- name: Validate JSON and YAML files
run: |
python .github/scripts/validate_files.py --directory . --check-json --check-yaml
if [ "${{ steps.changed-files.outputs.any_changed }}" = "true" ]; then
echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
python .github/scripts/validate_files.py --changed-files ${{ steps.changed-files.outputs.all_changed_files }} --check-json --check-yaml
else
echo "No JSON or YAML files changed"
fi