1
- name : openshift- tests at Testing Farm
1
+ name : OpenShift tests by GitHub Action at Testing Farm
2
2
3
3
on :
4
4
issue_comment :
5
5
types :
6
6
- created
7
7
jobs :
8
8
build :
9
- # This job only runs for '[test]' pull request comments by owner, member
10
- name : OpenShift tests on Testing Farm service
9
+ # This job only runs for '[test-all]' or '[test-openshift] pull request comments by owner, member
10
+ name : OpenShift tests by GitHub Action on Testing Farm service
11
11
runs-on : ubuntu-20.04
12
12
strategy :
13
13
fail-fast : false
@@ -16,184 +16,62 @@ jobs:
16
16
- tmt_plan : " centos7"
17
17
os_test : " centos7"
18
18
context : " CentOS7 - OpenShift 3"
19
- compose : " CentOS-7 "
20
- tmt_url : " http://artifacts.dev.testing-farm.io/ "
19
+ api_key : " TF_PUBLIC_API_KEY "
20
+ branch : " main "
21
21
tmt_repo : " https://github.com/sclorg/sclorg-testing-farm"
22
+ compose : " CentOS-7"
22
23
test_name : " test-openshift"
23
24
- tmt_plan : " rhel7-openshift-3"
24
25
os_test : " rhel7"
25
26
context : " RHEL7 - OpenShift 3"
26
27
compose : " RHEL-7.9-Released"
28
+ api_key : " TF_INTERNAL_API_KEY"
29
+ branch : " master"
27
30
tmt_url : " http://artifacts.osci.redhat.com/testing-farm/"
28
31
tmt_repo : " https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
29
32
test_name : " test-openshift"
33
+ tf_scope : " private"
30
34
- tmt_plan : " rhel7-openshift-4"
31
35
os_test : " rhel7"
32
36
context : " RHEL7 - OpenShift 4"
33
37
compose : " RHEL-7.9-Released"
34
38
tmt_url : " http://artifacts.osci.redhat.com/testing-farm/"
35
- tmt_repo : " https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
36
39
test_name : " test-openshift-4"
40
+ api_key : " TF_INTERNAL_API_KEY"
41
+ branch : " master"
42
+ tmt_repo : " https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
43
+ tf_scope : " private"
37
44
- tmt_plan : " rhel8-openshift-4"
38
45
os_test : " rhel8"
39
46
context : " RHEL8 - OpenShift 4"
40
47
compose : " RHEL-8.3.1-Released"
41
48
tmt_url : " http://artifacts.osci.redhat.com/testing-farm/"
42
- tmt_repo : " https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
43
49
test_name : " test-openshift-4"
50
+ api_key : " TF_INTERNAL_API_KEY"
51
+ branch : " master"
52
+ tmt_repo : " https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
53
+ tf_scope : " private"
54
+
44
55
if : |
45
56
github.event.issue.pull_request
46
57
&& (contains(github.event.comment.body, '[test-openshift]') || contains(github.event.comment.body, '[test-all]'))
47
58
&& contains(fromJson('["OWNER", "MEMBER"]'), github.event.comment.author_association)
48
59
steps :
49
- - name : Get pull request number
50
- id : pr_nr
51
- run : |
52
- PR_URL="${{ github.event.comment.issue_url }}"
53
- echo "::set-output name=PR_NR::${PR_URL##*/}"
54
-
55
60
- name : Checkout repo
56
61
uses : actions/checkout@v2
57
62
with :
58
- ref : " refs/pull/${{ steps.pr_nr.outputs.PR_NR }}/head"
63
+ ref : " refs/pull/${{ github.event.issue.number }}/head"
59
64
60
- - name : SHA value
61
- id : sha_value
62
- run : |
63
- echo "::set-output name=SHA::$(git rev-parse HEAD)"
64
-
65
- - name : Create status check to pending
66
- id : pending
67
- env :
68
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
69
- run : |
70
- # Create a JSON file for Testing Farm in order to schedule a CI testing job
71
- cat << EOF > pending.json
72
- {
73
- "sha": "${{ steps.sha_value.outputs.SHA }}",
74
- "state": "pending",
75
- "context": "Testing Farm - ${{ matrix.context }}",
76
- "target_url": "${{ matrix.tmt_url }}"
77
- }
78
- EOF
79
- echo "https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ steps.sha_value.outputs.SHA }}"
80
- # GITHUB_TOKEN is used for updating pull request status.
81
- # It is provided by GitHub https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret
82
- curl -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
83
- https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ steps.sha_value.outputs.SHA }} \
84
- --data @pending.json
85
- echo "::set-output name=GITHUB_REPOSITORY::$GITHUB_REPOSITORY"
86
-
87
- - name : Schedule a test on Testing Farm
88
- id : sched_test
89
- run : |
90
- # Update ubuntu-20.04 in order to install curl and jq
91
- sudo apt update && sudo apt -y install curl jq
92
- if [ "${{ matrix.tmt_plan }}" == "fedora" ] || [ "${{ matrix.tmt_plan }}" == "centos7" ]; then
93
- api_key="${{ secrets.TF_PUBLIC_API_KEY }}"
94
- branch_name="main"
95
- else
96
- api_key="${{ secrets.TF_INTERNAL_API_KEY }}"
97
- branch_name="master"
98
- fi
99
- cat << EOF > request.json
100
- {
101
- "api_key": "$api_key",
102
- "test": {"fmf": {
103
- "url": "${{ matrix.tmt_repo }}",
104
- "ref": "$branch_name",
105
- "name": "${{ matrix.tmt_plan }}"
106
- }},
107
- "environments": [{
108
- "arch": "x86_64",
109
- "os": {"compose": "${{ matrix.compose }}"},
110
- "variables": {
111
- "REPO_URL": "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY",
112
- "REPO_NAME": "$GITHUB_REPOSITORY",
113
- "PR_NUMBER": "${{ steps.pr_nr.outputs.PR_NR }}",
114
- "OS": "${{ matrix.os_test }}",
115
- "TEST_NAME": "${{ matrix.test_name }}"
116
- }
117
- }]
118
- }
119
- EOF
120
- curl ${{ secrets.TF_ENDPOINT }}/requests --data @request.json --header "Content-Type: application/json" --output response.json
121
- cat response.json
122
-
123
- # Store REQ_ID into outputs for later on usage
124
- req_id=$(jq -r .id response.json)
125
- echo "REQ_ID=$req_id" >> $GITHUB_ENV
126
-
127
- - name : Switch to running state of Testing Farm request
128
- id : running
129
- run : |
130
- # Create running.json file for query, whether job is finished or not.
131
- cat << EOF > running.json
132
- {
133
- "sha": "${{ steps.sha_value.outputs.SHA }}",
134
- "state": "pending",
135
- "context": "Testing Farm - ${{ matrix.context }}",
136
- "description": "Build started",
137
- "target_url": "${{ matrix.tmt_url }}/${{ env.REQ_ID }}"
138
- }
139
- EOF
140
- # Update GitHub status description to 'Build started'
141
- curl -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" \
142
- https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ steps.sha_value.outputs.SHA }} \
143
- --data @running.json
144
-
145
- - name : Check test is still running
146
- id : still_running
147
- run : |
148
- CMD=${{ secrets.TF_ENDPOINT }}/requests/${{ env.REQ_ID }}
149
- curl $CMD > job.json
150
- cat job.json
151
- state=$(jq -r .state job.json)
152
- # Wait till job is not finished. As soon as state is complete or failure then go to the finish action
153
- while [ "$state" == "running" ] || [ "$state" == "new" ] || [ "$state" == "pending" ] || [ "$state" == "queued" ]; do
154
- # Wait 30s. We do not need to query Testing Farm each second
155
- sleep 30
156
- curl $CMD > job.json
157
- state=$(jq -r .state job.json)
158
- done
159
-
160
- - name : Get final state of Testing Farm request
161
- id : final_state
162
- run : |
163
- curl ${{ secrets.TF_ENDPOINT }}/requests/${{ env.REQ_ID }} > job.json
164
- cat job.json
165
- state=$(jq -r .state job.json)
166
- result=$(jq -r .result.overall job.json)
167
- new_state="success"
168
- infra_error=" "
169
- echo "State is $state and result is: $result"
170
- if [ "$state" == "complete" ]; then
171
- if [ "$result" != "passed" ]; then
172
- new_state="failure"
173
- fi
174
- else
175
- # Mark job in case of infrastructure issues. Report to Testing Farm team
176
- infra_error=" - Infra problems"
177
- new_state="failure"
178
- fi
179
- echo "New State is: $new_state"
180
- echo "Infra state is: $infra_error"
181
- echo "::set-output name=FINAL_STATE::$new_state"
182
- echo "::set-output name=INFRA_STATE::$infra_error"
183
-
184
- - name : Switch to final state of Testing Farm request
185
- run : |
186
- cat << EOF > final.json
187
- {
188
- "sha": "${{ steps.sha_value.outputs.SHA }}",
189
- "state": "${{ steps.final_state.outputs.FINAL_STATE }}",
190
- "context": "Testing Farm - ${{ matrix.context }}",
191
- "description": "Build finished${{ steps.final_state.outputs.INFRA_STATE }}",
192
- "target_url": "${{ matrix.tmt_url }}/${{ env.REQ_ID }}"
193
- }
194
- EOF
195
- cat final.json
196
- # Switch Github status to proper state
197
- curl -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" \
198
- https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ steps.sha_value.outputs.SHA }} \
199
- --data @final.json
65
+ # https://github.com/sclorg/testing-farm-as-github-action
66
+ - name : Schedule tests on external Testing Farm by Testing-Farm-as-github-action
67
+ id : github_action
68
+ uses : sclorg/testing-farm-as-github-action@v1
69
+ with :
70
+ api_key : ${{ secrets[matrix.api_key] }}
71
+ git_url : ${{ matrix.tmt_repo }}
72
+ git_ref : ${{ matrix.branch }}
73
+ tf_scope : ${{ matrix.tf_scope }}
74
+ tmt_plan_regex : ${{ matrix.tmt_plan }}
75
+ pull_request_status_name : ${{ matrix.context }}
76
+ variables : " REPO_URL=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY;REPO_NAME=$GITHUB_REPOSITORY;PR_NUMBER=${{ github.event.issue.number }};OS=${{ matrix.os_test }};TEST_NAME=${{ matrix.test_name }}"
77
+ compose : ${{ matrix.compose }}
0 commit comments