-
Notifications
You must be signed in to change notification settings - Fork 12
48 lines (41 loc) · 1.51 KB
/
json-validator.yml
File metadata and controls
48 lines (41 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
name: JSON Validator
on:
pull_request:
branches:
- main
paths:
- '**/*.json' # Trigger for any JSON files in the repository
workflow_dispatch:
permissions:
contents: read
pull-requests: write # enable write permissions for pull request comments
jobs:
json-validate:
runs-on: ubuntu-latest
name: Validate JSON Files
steps:
# Checkout the repo
- uses: actions/checkout@v4
with:
fetch-depth: 0 # needed to checkout all branches for this Action to work
# Check the PR diff using the current branch and the base branch of the PR
- uses: GrantBirki/git-diff-action@v2.8.0
id: git-diff-action
with:
json_diff_file_output: diff.json
file_output_only: "true"
# Validate JSON files
- name: Validate JSON files
if: ${{ steps.git-diff-action.outputs.json-diff-path != '' }}
uses: GrantBirki/json-yaml-validate@v3.3.0
with:
comment: "true" # enable comment mode
base_dir: ./ # Base directory for validation
files: ${{ steps.git-diff-action.outputs.json-diff-path }} # Validate only changed files
# Explicit success message when no JSON files changed
- name: No JSON files to validate
if: ${{ steps.git-diff-action.outputs.json-diff-path == '' }}
run: echo "✅ No JSON files were modified in this PR"
# Final validation status
- name: JSON Validation Complete
run: echo "✅ All JSON files are valid"