diff --git a/.github/scripts/validate_files.py b/.github/scripts/validate_files.py index 7feb2a2..f093269 100644 --- a/.github/scripts/validate_files.py +++ b/.github/scripts/validate_files.py @@ -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() @@ -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 diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index c00eaee..70c682d 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -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: @@ -25,4 +34,9 @@ jobs: - name: Validate JSON and YAML files run: | - python .github/scripts/validate_files.py --directory . --check-json --check-yaml \ No newline at end of file + 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 \ No newline at end of file