diff --git a/.github/workflows/build-and-review-pr.yml b/.github/workflows/build-and-review-pr.yml index 8f9518e..edc8afc 100644 --- a/.github/workflows/build-and-review-pr.yml +++ b/.github/workflows/build-and-review-pr.yml @@ -69,41 +69,37 @@ jobs: ACTION_NAME: create-app-insights-annotation DISPATCH_TYPE: 'create-app-insights-annotation-tests' - COMMIT_STATUS_CONTEXT: 'External Tests / create-app-insights-annotation-tests' + COMMIT_STATUS_CONTEXT: 'External Tests for SWAT Actions' EXTERNAL_ORG: 'im-practices' EXTERNAL_REPO: 'external-tests-for-swat-actions' - EXTERNAL_WORKFLOW: 'test-repo-dispatch.yml' # 'create-app-insights-annotation-tests.yml' + EXTERNAL_WORKFLOW: 'create-app-insights-annotation-tests.yml' steps: - - name: Create ${{ github.event.pull_request.head.repo.fork && 'an error' || 'a pending' }} commit status - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.PIPELINE_BOT_PAT }} # This is an org-level secret - script: | - const isFork = ${{ github.event.pull_request.head.repo.fork }}; - github.rest.repos.createCommitStatus({ - owner: '${{ env.ACTION_ORG }}', - repo: '${{ env.ACTION_NAME }}', - sha: '${{ github.event.pull_request.head.sha }}', - context: '${{ env.COMMIT_STATUS_CONTEXT }}', - target_url: 'https://github.com/${{ env.EXTERNAL_ORG }}/${{ env.ACTION_NAME }}/actions/workflows/${{ env.EXTERNAL_WORKFLOW }}', - state: isFork ? 'error' : 'pending', - description: isFork ? 'Forks do not have permission to kick off external tests' : 'The external tests have been kicked off' - }); - - name: Fail test job if fork if: github.event.pull_request.head.repo.fork == true run: | echo "This test job kicks off external tests which requires access to GitHub Secrets which PRs from forks do not have access to. Before this PR can be merged, the tests should be run on an intermediate branch created by repository owners." exit 1 - - name: Kick off the external tests + - name: Create a commit status and kick off the external tests if: github.event.pull_request.head.repo.fork == false uses: actions/github-script@v7 with: github-token: ${{ secrets.PIPELINE_BOT_PAT }} # Not available to forks script: | + // This will add a pending status check to the PR in this repo + github.rest.repos.createCommitStatus({ + owner: '${{ env.ACTION_ORG }}', + repo: '${{ env.ACTION_NAME }}', + sha: '${{ github.event.pull_request.head.sha }}', + context: '${{ env.COMMIT_STATUS_CONTEXT }}', + target_url: 'https://github.com/${{ env.EXTERNAL_ORG }}/${{ env.EXTERNAL_REPO }}/actions/workflows/${{ env.EXTERNAL_WORKFLOW }}', + state: 'pending', + description: 'The external tests have been kicked off' + }); + + // This will kick off the tests that live in an external repository github.rest.repos.createDispatchEvent({ owner: '${{ env.EXTERNAL_ORG }}', repo: '${{ env.EXTERNAL_REPO }}',