forked from wildfly/wildfly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wildfly#18329 from kabir/cloud-tests
[WFLY-19889] Split cloud tests trigger
- Loading branch information
Showing
3 changed files
with
188 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# This will be invoked by the cloud-test-pr-trigger.yml workflow | ||
# The other job runs handles the 'pull_request' event and thus its GITHUB_SHA will have the value | ||
# of the merge commit from the PR into the main branch of WildFly. However, it can not access the secrets needed | ||
# to perform the remote dispatch. | ||
# So it stores that sha in an environment variable, along with the pull request head sha, and delegates to this job | ||
# which can read secrets and do the dispatch. | ||
name: Cloud Tests Workflow Run | ||
on: | ||
workflow_run: | ||
workflows: | ||
- 'Cloud Tests Trigger' | ||
types: | ||
- completed | ||
|
||
# Only run the latest job | ||
concurrency: | ||
group: '${{ github.workflow }} - ${{ github.event.workflow_run.event }}: ${{ github.event.workflow_run.head_repository.full_name }}@${{ github.event.workflow_run.head_branch }}' | ||
cancel-in-progress: true | ||
env: | ||
# This must be set to a PAT with 'repo' permission for the target repository | ||
REMOTE_DISPATCH_TOKEN: ${{ secrets.CLOUD_TESTS_REMOTE_DISPATCH_TOKEN }} | ||
# Just an identifier for the event - this one triggers the cloud tests | ||
EVENT_TYPE: trigger-cloud-tests-pr | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Dump GitHub context | ||
env: | ||
GITHUB_CONTEXT: ${{ toJson(github) }} | ||
run: echo "$GITHUB_CONTEXT" | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: .job-env | ||
github-token: ${{ github.token }} | ||
run-id: ${{ github.event.workflow_run.id }} | ||
- name: Read environment variables from the previous job | ||
run: | | ||
text="$(cat .job-env)" | ||
echo "${text}" | ||
echo "${text}" >> "$GITHUB_ENV" | ||
- name: Report Progress | ||
# This workflow_run job is invisible on the pull requests, so we need to report back whether we work | ||
# or fail. | ||
# We do that by reporting back via the same mechanism as the remote cloud test does. | ||
env: | ||
REPORTER_EVENT_TYPE: report-cloud-tests-workflow-run-pending | ||
run: | | ||
STATUS="pending" | ||
RUN_URL="https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" | ||
DESC="Invoking remote job" | ||
CLIENT_PAYLOAD=$( jq -n \ | ||
--arg prHeadSha "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" \ | ||
--arg state "$STATUS" \ | ||
--arg runUrl "$RUN_URL" \ | ||
--arg desc "$DESC" \ | ||
'{prHeadSha: $prHeadSha, state: $state, runUrl: $runUrl, desc: $desc}' ) | ||
echo "CLIENT_PAYLOAD: $CLIENT_PAYLOAD" | ||
set -x | ||
resp=$(curl -X POST -s "https://api.github.com/repos/$GITHUB_REPOSITORY/dispatches" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer ${REMOTE_DISPATCH_TOKEN}" \ | ||
-d "{\"event_type\": \"${REPORTER_EVENT_TYPE}\", \"client_payload\": ${CLIENT_PAYLOAD} }") | ||
set +x | ||
if [ -z "$resp" ] | ||
then | ||
sleep 2 | ||
else | ||
echo "Workflow failed to trigger" | ||
echo "$resp" | ||
exit 1 | ||
fi | ||
- name: Remote Dispatch | ||
env: | ||
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
if: ${{ env.REMOTE_DISPATCH_TOKEN }} | ||
run: | | ||
# If we are in the wildfly/wildfly repository, we should invoke the cloud tests in wildfly-extras | ||
# Otherwise invoke in the user's organisation | ||
if [ "${GITHUB_REPOSITORY_OWNER}" = "wildfly" ]; then | ||
CLOUD_TESTS_REPOSITORY="wildfly-extras/wildfly-cloud-tests" | ||
else | ||
CLOUD_TESTS_REPOSITORY="${GITHUB_REPOSITORY_OWNER}/wildfly-cloud-tests" | ||
fi | ||
echo "Remote repository: ${CLOUD_TESTS_REPOSITORY}" | ||
CLIENT_PAYLOAD=$( jq -n \ | ||
--arg tr "$GITHUB_REPOSITORY" \ | ||
--arg githubSha "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" \ | ||
--arg prHeadSha "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" \ | ||
--arg pr "$PR_NUMBER" \ | ||
'{triggerRepo: $tr, githubSha: $githubSha, prHeadSha: $prHeadSha, pr: $pr}' ) | ||
echo "CLIENT_PAYLOAD: $CLIENT_PAYLOAD" | ||
set -x | ||
resp=$(curl -X POST -s "https://api.github.com/repos/${CLOUD_TESTS_REPOSITORY}/dispatches" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer ${REMOTE_DISPATCH_TOKEN}" \ | ||
-d "{\"event_type\": \"${EVENT_TYPE}\", \"client_payload\": ${CLIENT_PAYLOAD} }") | ||
set +x | ||
if [ -z "$resp" ] | ||
then | ||
sleep 2 | ||
else | ||
echo "Workflow failed to trigger" | ||
echo "$resp" | ||
exit 1 | ||
fi | ||
- name: Report failure | ||
if: ${{ failure() }} | ||
env: | ||
REPORTER_EVENT_TYPE: report-cloud-tests-workflow-run-failed | ||
run: | | ||
# There is no 'cancelled' status, just error, failure, pending and success | ||
STATUS="failure" | ||
TEXT="The attempt to start the remote job failed, or was cancelled" | ||
RUN_URL="https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" | ||
CLIENT_PAYLOAD=$( jq -n \ | ||
--arg prHeadSha "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" \ | ||
--arg state "$STATUS" \ | ||
--arg runUrl "$RUN_URL" \ | ||
--arg desc "$TEXT" \ | ||
'{prHeadSha: $prHeadSha, state: $state, runUrl: $runUrl, desc: $desc}' ) | ||
echo "CLIENT_PAYLOAD: $CLIENT_PAYLOAD" | ||
resp=$(curl -X POST -s "https://api.github.com/repos/$GITHUB_REPOSITORY/dispatches" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer ${REMOTE_DISPATCH_TOKEN}" \ | ||
-d "{\"event_type\": \"${REPORTER_EVENT_TYPE}\", \"client_payload\": ${CLIENT_PAYLOAD} }") | ||
if [ -z "$resp" ] | ||
then | ||
sleep 2 | ||
else | ||
echo "Workflow failed to trigger" | ||
echo "$resp" | ||
exit 1 | ||
fi |