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
66 changes: 66 additions & 0 deletions .github/workflows/json-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: JSON Validator Bot

on:
pull_request_target:
paths:
- "cardDetails.json"

permissions:
contents: read
pull-requests: write

jobs:
validate-json:
runs-on: ubuntu-latest
steps:
- name: Checkout PR HEAD
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Run JSON validator
id: validator
run: |
set +e
python validator.py cardDetails.json > result.log 2>&1
echo "exit_code=$?" >> $GITHUB_OUTPUT
set -e

- name: Post validation comment (Fail)
if: steps.validator.outputs.exit_code != '0'
uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const errors = fs.readFileSync("result.log", "utf8");
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: "🚨 **JSON Validation Failed**\n\n```\n" + errors + "\n```"
});

- name: Post validation comment (Pass)
if: steps.validator.outputs.exit_code == '0'
uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const success = fs.readFileSync("result.log", "utf8");
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: "✅ **JSON Validation Passed!** 🎉\n\n```\n" + success + "\n```"
});

- name: Fail job if validation failed
if: steps.validator.outputs.exit_code != '0'
run: exit 1
Empty file added .gitignor
Empty file.
Loading