Skip to content

Commit 48d1dda

Browse files
authored
Merge pull request wildfly#18329 from kabir/cloud-tests
[WFLY-19889] Split cloud tests trigger
2 parents 9a77809 + c11de8b commit 48d1dda

File tree

3 files changed

+188
-52
lines changed

3 files changed

+188
-52
lines changed

.github/workflows/cloud-test-pr-reporter.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
name: Report Cloud Test Status
22
on:
33
repository_dispatch:
4-
types: [report-cloud-tests-pr-pending, report-cloud-tests-pr-complete]
4+
types:
5+
# These two come from cloud-test-pr-workflow-run.yml which does the remote dispatch in the
6+
# wildfly-cloud-tests repository
7+
- report-cloud-tests-workflow-run-pending
8+
- report-cloud-tests-workflow-run-failed
9+
# These two come from the remote job in the wildfly-cloud-tests repository
10+
- report-cloud-tests-pr-pending
11+
- report-cloud-tests-pr-complete
512
env:
613
DESC: ${{ github.event.client_payload.desc }}
714
GH_TOKEN: ${{ github.token }}
@@ -18,10 +25,8 @@ jobs:
1825
steps:
1926
- name: Output
2027
env:
21-
#MESSAGE: ${{ github.event.client_payload.message }}
2228
MESSAGE: ${{ toJSON(github.event.client_payload) }}
2329
run: echo $MESSAGE
24-
2530
- name: Report status
2631
run: |
2732
JSON_STRING=$(jq -c -n \
+26-49
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Cloud Tests Trigger
22
on:
3-
pull_request_target:
3+
pull_request:
44
branches:
55
- main
66
paths-ignore:
@@ -27,57 +27,34 @@ on:
2727

2828
# Only run the latest job
2929
concurrency:
30-
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
30+
group: '${{ github.workflow }} @ ${{ github.ref || github.run_id }}'
3131
cancel-in-progress: true
32-
env:
33-
# Repository where the cloud tests will be run
34-
REPOSITORY: wildfly-extras/wildfly-cloud-tests
35-
# This must be set to a PAT with 'repo' permission for the target repository
36-
TOKEN: ${{ secrets.CLOUD_TESTS_REMOTE_DISPATCH_TOKEN }}
37-
# Just an identifier for the event - this one triggers the cloud tests
38-
EVENT_TYPE: trigger-cloud-tests-pr
3932

4033
permissions: {}
4134
jobs:
42-
run-tests:
35+
trigger:
4336
runs-on: ubuntu-latest
4437
steps:
45-
46-
- name: Remote Dispatch
47-
env:
48-
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
49-
if: ${{ env.TOKEN }}
50-
run: |
51-
echo $GITHUB_REPOSITORY
52-
53-
echo "FILENAME=$FILENAME" >> $GITHUB_ENV
54-
PR_NUMBER="${{github.event.number}}"
55-
56-
CLIENT_PAYLOAD=$( jq -n \
57-
--arg tr "$GITHUB_REPOSITORY" \
58-
--arg githubSha "$GITHUB_SHA" \
59-
--arg prHeadSha "$PR_HEAD_SHA" \
60-
--arg pr "$PR_NUMBER" \
61-
'{triggerRepo: $tr, githubSha: $githubSha, prHeadSha: $prHeadSha, pr: $pr}' )
62-
63-
echo "CLIENT_PAYLOAD: $CLIENT_PAYLOAD"
64-
65-
set -x
66-
67-
resp=$(curl -X POST -s "https://api.github.com/repos/${REPOSITORY}/dispatches" \
68-
-H "Accept: application/vnd.github.v3+json" \
69-
-H "Content-Type: application/json" \
70-
-H "Authorization: Bearer ${TOKEN}" \
71-
-d "{\"event_type\": \"${EVENT_TYPE}\", \"client_payload\": ${CLIENT_PAYLOAD} }")
72-
73-
set +x
74-
75-
if [ -z "$resp" ]
76-
then
77-
sleep 2
78-
else
79-
echo "Workflow failed to trigger"
80-
echo "$resp"
81-
exit 1
82-
fi
83-
38+
- name: Get pull request number
39+
run: |
40+
event_name="${{ github.event_name }}"
41+
42+
if [ "${event_name}" == "pull_request" ]; then
43+
echo "This is a pull request"
44+
echo "PR_NUMBER=${{ github.event.number }}" >> .job-env
45+
echo "GITHUB_SHA_FOR_PR=${{ github.sha }}" >> .job-env
46+
echo "GITHUB_EVENT_PULL_REQUEST_HEAD_SHA=${{ github.event.pull_request.head.sha }}" >> .job-env
47+
elif [ "${event_name}" == "push" ]; then
48+
echo "This is a push"
49+
echo "PR_NUMBER=push" >> .job-env
50+
echo "GITHUB_SHA=${{ github.sha }}" >> .job-env
51+
else
52+
echo "The ${event_name} event is not handled by this workflow"
53+
exit 1
54+
fi
55+
cat .job-env
56+
- uses: actions/upload-artifact@v4
57+
with:
58+
name: .job-env
59+
path: .job-env
60+
include-hidden-files: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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

Comments
 (0)