From 0cb01640496ad18ed47151eaa3fe5d58c07c186d Mon Sep 17 00:00:00 2001 From: Joab <89288499+Joabutt@users.noreply.github.com> Date: Sat, 30 Dec 2023 00:39:09 +0800 Subject: [PATCH] Update check_pr.yml --- .github/workflows/check_pr.yml | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/check_pr.yml b/.github/workflows/check_pr.yml index 1b4d970..3e16844 100644 --- a/.github/workflows/check_pr.yml +++ b/.github/workflows/check_pr.yml @@ -18,15 +18,26 @@ jobs: uses: actions/checkout@v2 with: 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' + + - name: Install Dependencies + run: npm install ajv-cli + + - name: Get list of changed domain files + id: file_changes + run: | + git fetch origin ${{ github.event.pull_request.base.ref }} + git diff --name-only FETCH_HEAD..${{ github.sha }} | grep '^domains/.*\.json$' > changed_files.txt + cat changed_files.txt + + - name: JSON Schema Validate + run: | + while read file; do + npx ajv-cli validate -s .github/workflows/domain-schema.json -d $file + done < changed_files.txt continue-on-error: true + - name: Comment on PR if Invalid - if: ${{ steps.json-yaml-validate.outcome == 'failure' }} + if: ${{ failure() }} uses: actions/github-script@v5 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -37,8 +48,9 @@ jobs: repo: context.repo.repo, body: "❌ Your JSON file is invalid, please check the template again!" }); + - name: Comment on PR if Valid - if: ${{ steps.json-yaml-validate.outcome == 'success' }} + if: ${{ success() }} uses: actions/github-script@v5 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -49,6 +61,7 @@ jobs: repo: context.repo.repo, body: "✅ Your JSON file is valid!" }); + - name: Fail Job - if: ${{ steps.json-yaml-validate.outcome == 'failure' }} + if: ${{ failure() }} run: exit 1