From c63f2c8e6228fdf6ba0e7103edb5f0d9e0423f05 Mon Sep 17 00:00:00 2001 From: Joab <89288499+Joabutt@users.noreply.github.com> Date: Sat, 30 Dec 2023 00:56:58 +0800 Subject: [PATCH] Update check_pr.yml --- .github/workflows/check_pr.yml | 43 +++++++--------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/.github/workflows/check_pr.yml b/.github/workflows/check_pr.yml index 0476f23..2a91bbc 100644 --- a/.github/workflows/check_pr.yml +++ b/.github/workflows/check_pr.yml @@ -17,31 +17,16 @@ jobs: - name: Checkout source code uses: actions/checkout@v2 with: - ref: ${{ github.event.pull_request.head.sha }} - - - name: Install Dependencies - run: npm install ajv-cli - - - name: Get list of changed domain files - id: file_changes - run: | - set -ex - git fetch origin ${{ github.event.pull_request.base.ref }} - git diff --name-only FETCH_HEAD..${{ github.sha }} | { grep '^domains/.*\.json$' || true; } > changed_files.txt - cat changed_files.txt - - - name: JSON Schema Validate - run: | - set -ex - while read file; do - echo "Validating file: ${file}" - npx ajv-cli validate -s .github/workflows/domain-schema.json -d $file - done < changed_files.txt + ref: ${{ github.event.pull_request.head.sha }} + - name: json-yaml-validate + id: json-yaml-validate + uses: GrantBirki/json-yaml-validate@v2.4.0 + with: + base_dir: './domains' + json_schema: '.github/workflows/domain-schema.json' continue-on-error: true - - - name: Comment on PR if Invalid - if: ${{ failure() }} + if: ${{ steps.json-yaml-validate.outcome == 'failure' }} uses: actions/github-script@v5 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -52,20 +37,10 @@ jobs: repo: context.repo.repo, body: "❌ Your JSON file is invalid, please check the template again!" }); - - name: Comment on PR if Valid - if: ${{ success() }} + if: ${{ steps.json-yaml-validate.outcome == 'success' }} uses: actions/github-script@v5 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: "✅ Your JSON file is valid!" - }); - - - name: Fail Job - if: ${{ failure() }} - run: exit 1