From 37f4a841a664beb41cab8b4df27b1f346e6832f3 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:47:37 +0100 Subject: [PATCH] Update validate-scripts.yml --- .github/workflows/validate-scripts.yml | 38 ++++++++++++++------------ 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/validate-scripts.yml b/.github/workflows/validate-scripts.yml index d0e12923..84b69706 100644 --- a/.github/workflows/validate-scripts.yml +++ b/.github/workflows/validate-scripts.yml @@ -16,6 +16,11 @@ jobs: pull-requests: write steps: + - name: Debug event payload + run: | + echo "Event name: ${{ github.event_name }}" + echo "Payload: $(cat $GITHUB_EVENT_PATH)" + - name: Get pull request information if: github.event_name == 'pull_request_target' uses: actions/github-script@v7 @@ -31,16 +36,16 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 0 # Ensure the full history is fetched for accurate diffing + fetch-depth: 0 ref: ${{ github.event_name == 'pull_request_target' && fromJSON(steps.pr.outputs.result).merge_commit_sha || '' }} - name: Get changed files id: changed-files run: | - if ${{ github.event_name == 'pull_request_target' }}; then - echo "files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ steps.pr.outputs.result && fromJSON(steps.pr.outputs.result).merge_commit_sha }} | grep -E '\.(sh|func)$' | xargs)" >> $GITHUB_OUTPUT + if [ "${{ github.event_name }}" == "pull_request_target" ]; then + echo "files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ steps.pr.outputs.result && fromJSON(steps.pr.outputs.result).merge_commit_sha }} | grep -E '\.(sh|func)$' | xargs)" >> $GITHUB_OUTPUT else - echo "files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep -E '\.(sh|func)$' | xargs)" >> $GITHUB_OUTPUT + echo "files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep -E '\.(sh|func)$' | xargs)" >> $GITHUB_OUTPUT fi - name: Check build.func line @@ -170,12 +175,12 @@ jobs: script: | const result = '${{ job.status }}' === 'success' ? 'success' : 'failure'; const nonCompliantFiles = { - 'Invalid build.func source': "${{ steps.build-func.outputs.files }}", - 'Not executable': "${{ steps.check-executable.outputs.files }}", - 'Copyright header line missing or invalid': "${{ steps.check-copyright.outputs.files }}", - 'Author header line missing or invalid': "${{ steps.check-author.outputs.files }}", - 'License header line missing or invalid': "${{ steps.check-license.outputs.files }}", - 'Source header line missing or invalid': "${{ steps.check-source.outputs.files }}" + 'Invalid build.func source': "${{ steps.build-func.outputs.files || '' }}", + 'Not executable': "${{ steps.check-executable.outputs.files || '' }}", + 'Copyright header line missing or invalid': "${{ steps.check-copyright.outputs.files || '' }}", + 'Author header line missing or invalid': "${{ steps.check-author.outputs.files || '' }}", + 'License header line missing or invalid': "${{ steps.check-license.outputs.files || '' }}", + 'Source header line missing or invalid': "${{ steps.check-source.outputs.files || '' }}" }; const issueNumber = context.payload.pull_request ? context.payload.pull_request.number : null; @@ -205,15 +210,14 @@ jobs: issue_number: issueNumber }); - const existingComment = comments.find(comment => comment.user.login === 'github-actions[bot]'); + const existingComment = comments.find(comment => + comment.body.includes(``) && + comment.user.login === 'github-actions[bot]' + ); if (existingComment) { - if (existingComment.body.includes(commentIdentifier)) { - const re = new RegExp(String.raw`[\\s\\S]*?`, ""); - newCommentBody = existingComment.body.replace(re, newCommentBody); - } else { - newCommentBody = existingComment.body + '\n\n---\n\n' + newCommentBody; - } + const re = new RegExp(String.raw`[\\s\\S]*?`, "m"); + newCommentBody = existingComment.body.replace(re, newCommentBody); await github.rest.issues.updateComment({ ...context.repo,