|
| 1 | +# This will be invoked by the cloud-test-pr-trigger.yml workflow |
| 2 | +# The other job runs handles the 'pull_request' event and thus its GITHUB_SHA will have the value |
| 3 | +# of the merge commit from the PR into the main branch of WildFly. However, it can not access the secrets needed |
| 4 | +# to perform the remote dispatch. |
| 5 | +# So it stores that sha in an environment variable, along with the pull request head sha, and delegates to this job |
| 6 | +# which can read secrets and do the dispatch. |
| 7 | +name: Cloud Tests Workflow Run |
| 8 | +on: |
| 9 | + workflow_run: |
| 10 | + workflows: |
| 11 | + - 'Cloud Tests Trigger' |
| 12 | + types: |
| 13 | + - completed |
| 14 | + |
| 15 | +# Only run the latest job |
| 16 | +concurrency: |
| 17 | + group: '${{ github.workflow }} - ${{ github.event.workflow_run.event }}: ${{ github.event.workflow_run.head_repository.full_name }}@${{ github.event.workflow_run.head_branch }}' |
| 18 | + cancel-in-progress: true |
| 19 | +env: |
| 20 | + # This must be set to a PAT with 'repo' permission for the target repository |
| 21 | + REMOTE_DISPATCH_TOKEN: ${{ secrets.CLOUD_TESTS_REMOTE_DISPATCH_TOKEN }} |
| 22 | + # Just an identifier for the event - this one triggers the cloud tests |
| 23 | + EVENT_TYPE: trigger-cloud-tests-pr |
| 24 | + |
| 25 | +jobs: |
| 26 | + run-tests: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - name: Dump GitHub context |
| 30 | + env: |
| 31 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 32 | + run: echo "$GITHUB_CONTEXT" |
| 33 | + - uses: actions/download-artifact@v4 |
| 34 | + with: |
| 35 | + name: .job-env |
| 36 | + github-token: ${{ github.token }} |
| 37 | + run-id: ${{ github.event.workflow_run.id }} |
| 38 | + - name: Read environment variables from the previous job |
| 39 | + run: | |
| 40 | + text="$(cat .job-env)" |
| 41 | + echo "${text}" |
| 42 | + echo "${text}" >> "$GITHUB_ENV" |
| 43 | +
|
| 44 | + - name: Report Progress |
| 45 | + # This workflow_run job is invisible on the pull requests, so we need to report back whether we work |
| 46 | + # or fail. |
| 47 | + # We do that by reporting back via the same mechanism as the remote cloud test does. |
| 48 | + env: |
| 49 | + REPORTER_EVENT_TYPE: report-cloud-tests-workflow-run-pending |
| 50 | + run: | |
| 51 | + STATUS="pending" |
| 52 | + RUN_URL="https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" |
| 53 | + DESC="Invoking remote job" |
| 54 | + CLIENT_PAYLOAD=$( jq -n \ |
| 55 | + --arg prHeadSha "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" \ |
| 56 | + --arg state "$STATUS" \ |
| 57 | + --arg runUrl "$RUN_URL" \ |
| 58 | + --arg desc "$DESC" \ |
| 59 | + '{prHeadSha: $prHeadSha, state: $state, runUrl: $runUrl, desc: $desc}' ) |
| 60 | +
|
| 61 | + echo "CLIENT_PAYLOAD: $CLIENT_PAYLOAD" |
| 62 | +
|
| 63 | + set -x |
| 64 | +
|
| 65 | + resp=$(curl -X POST -s "https://api.github.com/repos/$GITHUB_REPOSITORY/dispatches" \ |
| 66 | + -H "Accept: application/vnd.github.v3+json" \ |
| 67 | + -H "Content-Type: application/json" \ |
| 68 | + -H "Authorization: Bearer ${REMOTE_DISPATCH_TOKEN}" \ |
| 69 | + -d "{\"event_type\": \"${REPORTER_EVENT_TYPE}\", \"client_payload\": ${CLIENT_PAYLOAD} }") |
| 70 | + |
| 71 | + set +x |
| 72 | + |
| 73 | + if [ -z "$resp" ] |
| 74 | + then |
| 75 | + sleep 2 |
| 76 | + else |
| 77 | + echo "Workflow failed to trigger" |
| 78 | + echo "$resp" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + - name: Remote Dispatch |
| 82 | + env: |
| 83 | + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 84 | + if: ${{ env.REMOTE_DISPATCH_TOKEN }} |
| 85 | + run: | |
| 86 | + # If we are in the wildfly/wildfly repository, we should invoke the cloud tests in wildfly-extras |
| 87 | + # Otherwise invoke in the user's organisation |
| 88 | + if [ "${GITHUB_REPOSITORY_OWNER}" = "wildfly" ]; then |
| 89 | + CLOUD_TESTS_REPOSITORY="wildfly-extras/wildfly-cloud-tests" |
| 90 | + else |
| 91 | + CLOUD_TESTS_REPOSITORY="${GITHUB_REPOSITORY_OWNER}/wildfly-cloud-tests" |
| 92 | + fi |
| 93 | + |
| 94 | + echo "Remote repository: ${CLOUD_TESTS_REPOSITORY}" |
| 95 | + |
| 96 | + CLIENT_PAYLOAD=$( jq -n \ |
| 97 | + --arg tr "$GITHUB_REPOSITORY" \ |
| 98 | + --arg githubSha "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" \ |
| 99 | + --arg prHeadSha "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" \ |
| 100 | + --arg pr "$PR_NUMBER" \ |
| 101 | + '{triggerRepo: $tr, githubSha: $githubSha, prHeadSha: $prHeadSha, pr: $pr}' ) |
| 102 | +
|
| 103 | + echo "CLIENT_PAYLOAD: $CLIENT_PAYLOAD" |
| 104 | +
|
| 105 | + set -x |
| 106 | +
|
| 107 | + resp=$(curl -X POST -s "https://api.github.com/repos/${CLOUD_TESTS_REPOSITORY}/dispatches" \ |
| 108 | + -H "Accept: application/vnd.github.v3+json" \ |
| 109 | + -H "Content-Type: application/json" \ |
| 110 | + -H "Authorization: Bearer ${REMOTE_DISPATCH_TOKEN}" \ |
| 111 | + -d "{\"event_type\": \"${EVENT_TYPE}\", \"client_payload\": ${CLIENT_PAYLOAD} }") |
| 112 | + |
| 113 | + set +x |
| 114 | + |
| 115 | + if [ -z "$resp" ] |
| 116 | + then |
| 117 | + sleep 2 |
| 118 | + else |
| 119 | + echo "Workflow failed to trigger" |
| 120 | + echo "$resp" |
| 121 | + exit 1 |
| 122 | + fi |
| 123 | +
|
| 124 | + - name: Report failure |
| 125 | + if: ${{ failure() }} |
| 126 | + env: |
| 127 | + REPORTER_EVENT_TYPE: report-cloud-tests-workflow-run-failed |
| 128 | + run: | |
| 129 | + # There is no 'cancelled' status, just error, failure, pending and success |
| 130 | + STATUS="failure" |
| 131 | + TEXT="The attempt to start the remote job failed, or was cancelled" |
| 132 | + RUN_URL="https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" |
| 133 | + CLIENT_PAYLOAD=$( jq -n \ |
| 134 | + --arg prHeadSha "$GITHUB_EVENT_PULL_REQUEST_HEAD_SHA" \ |
| 135 | + --arg state "$STATUS" \ |
| 136 | + --arg runUrl "$RUN_URL" \ |
| 137 | + --arg desc "$TEXT" \ |
| 138 | + '{prHeadSha: $prHeadSha, state: $state, runUrl: $runUrl, desc: $desc}' ) |
| 139 | + |
| 140 | + echo "CLIENT_PAYLOAD: $CLIENT_PAYLOAD" |
| 141 | + |
| 142 | + resp=$(curl -X POST -s "https://api.github.com/repos/$GITHUB_REPOSITORY/dispatches" \ |
| 143 | + -H "Accept: application/vnd.github.v3+json" \ |
| 144 | + -H "Content-Type: application/json" \ |
| 145 | + -H "Authorization: Bearer ${REMOTE_DISPATCH_TOKEN}" \ |
| 146 | + -d "{\"event_type\": \"${REPORTER_EVENT_TYPE}\", \"client_payload\": ${CLIENT_PAYLOAD} }") |
| 147 | + if [ -z "$resp" ] |
| 148 | + then |
| 149 | + sleep 2 |
| 150 | + else |
| 151 | + echo "Workflow failed to trigger" |
| 152 | + echo "$resp" |
| 153 | + exit 1 |
| 154 | + fi |
0 commit comments