Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARCH-2011 - Adding a job to kick off external tests #13

Merged
merged 11 commits into from
Mar 27, 2024
54 changes: 54 additions & 0 deletions .github/workflows/build-and-review-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,57 @@ jobs:
# The npm script to run to build the action. This is typically 'npm run build' if the
# action needs to be compiled. For composite-run-steps actions this is typically empty.
build-command: ''

test:
runs-on: ubuntu-latest

env:
ACTION_ORG: ${{ github.repository_owner }}
ACTION_NAME: create-app-insights-annotation

DISPATCH_TYPE: '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: 'create-app-insights-annotation-tests.yml'

steps:
- name: Fail test job if fork
if: github.event.pull_request.head.repo.fork == true
run: |
echo "
This test job kicks off external tests and requires a GitHub Secret that 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: Create a pending 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 }}',
event_type: '${{ env.DISPATCH_TYPE }}',
client_payload: {
'action-org': '${{ env.ACTION_ORG }}',
'action-name': '${{ env.ACTION_NAME }}',
'action-ref': '${{ github.event.pull_request.head.ref }}',
'action-sha': '${{ github.event.pull_request.head.sha }}',
'commit-status-context': '${{ env.COMMIT_STATUS_CONTEXT }}'
}
});