From 58e7e1dbfaf7547a47e8e53682fac340691a096b Mon Sep 17 00:00:00 2001 From: Rob Young Date: Tue, 23 Feb 2021 09:20:24 +0000 Subject: [PATCH] Fix PR test workflow for forks When the workflow is triggered from a fork the permissions for the `GITHUB_TOKEN` are read-only. This chane skips the write operations if we're running from a fork. See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-events-for-forked-repositories --- .github/workflows/pull-request-test.yml | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/pull-request-test.yml b/.github/workflows/pull-request-test.yml index edf001ccb..3bceaba15 100644 --- a/.github/workflows/pull-request-test.yml +++ b/.github/workflows/pull-request-test.yml @@ -20,22 +20,22 @@ jobs: issue_number: context.payload.number, }) - // Find any comment already made by the bot. - const botComment = comments.find(comment => comment.user.id === 41898282) - const commentBody = "Hello from actions/github-script! (${{ github.sha }})" - - if (botComment) { - await github.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: commentBody - }) + if (context.payload.pull_request.head.repo.full_name !== 'actions/github-script') { + console.log('Not attempting to write comment on PR from fork'); } else { - await github.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.number, - body: commentBody - }) + if (botComment) { + await github.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: commentBody + }) + } else { + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.number, + body: commentBody + }) + } }