Skip to content

Commit

Permalink
Consolidate steps
Browse files Browse the repository at this point in the history
  • Loading branch information
danielle-casella-adams committed Mar 22, 2024
1 parent 48dcd52 commit a409cd3
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions .github/workflows/build-and-review-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}',
Expand Down

0 comments on commit a409cd3

Please sign in to comment.