Skip to content

Commit 108d9df

Browse files
committed
Use GitHub action matrix for OpenShift tests.
It contains all openshift tests like CentOS7-OpenSHift 3, RHEL7-OpenShift 3 and RHEL7-OpenShift 4 and newly RHEL8-OpenShift 4 Signed-off-by: Petr "Stone" Hracek <[email protected]>
1 parent 9f83d42 commit 108d9df

File tree

3 files changed

+76
-456
lines changed

3 files changed

+76
-456
lines changed
Lines changed: 76 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CentOS7-openshift-tests@TF
1+
name: openshift-tests at Testing Farm
22

33
on:
44
issue_comment:
@@ -7,15 +7,44 @@ on:
77
jobs:
88
build:
99
# This job only runs for '[test]' pull request comments by owner, member
10-
name: Schedule test on Testing Farm service for CentOS7 - OpenShift 3
10+
name: OpenShift tests on Testing Farm service
1111
runs-on: ubuntu-20.04
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- tmt_plan: "centos7"
17+
os_test: "centos7"
18+
context: "CentOS7 - OpenShift3"
19+
compose: "CentOS-7"
20+
tmt_url: "http://artifacts.dev.testing-farm.io/"
21+
tmt_repo: "https://github.com/sclorg/sclorg-testing-farm"
22+
test_name: "test-openshift"
23+
- tmt_plan: "rhel7-openshift-3"
24+
os_test: "rhel7"
25+
context: "RHEL7 - OpenShift 3"
26+
compose: "RHEL-7.9-Released"
27+
tmt_url: "http://artifacts.osci.redhat.com/testing-farm/"
28+
tmt_repo: "https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
29+
test_name: "test-openshift"
30+
- tmt_plan: "rhel7-openshift-4"
31+
os_test: "rhel7"
32+
context: "RHEL7 - OpenShift 4"
33+
compose: "RHEL-7.9-Released"
34+
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+
test_name: "test-openshift-4"
37+
- tmt_plan: "rhel8-openshift-4"
38+
os_test: "rhel8"
39+
context: "RHEL8 - OpenShift 4"
40+
compose: "RHEL-8.3.1-Released"
41+
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+
test_name: "test-openshift-4"
1244
if: |
1345
github.event.issue.pull_request
1446
&& (contains(github.event.comment.body, '[test-openshift]') || contains(github.event.comment.body, '[test-all]'))
1547
&& contains(fromJson('["OWNER", "MEMBER"]'), github.event.comment.author_association)
16-
outputs:
17-
REQ_ID: ${{steps.sched_test.outputs.REQ_ID}}
18-
SHA: ${{steps.sha.outputs.SHA}}
1948
steps:
2049
- name: Get pull request number
2150
id: pr_nr
@@ -28,10 +57,9 @@ jobs:
2857
with:
2958
ref: "refs/pull/${{ steps.pr_nr.outputs.PR_NR }}/head"
3059

31-
- name: Get sha
32-
id: sha
60+
- name: SHA value
61+
id: sha_value
3362
run: |
34-
# Store SHA into outputs
3563
echo "::set-output name=SHA::$(git rev-parse HEAD)"
3664
3765
- name: Create status check to pending
@@ -42,92 +70,84 @@ jobs:
4270
# Create a JSON file for Testing Farm in order to schedule a CI testing job
4371
cat << EOF > pending.json
4472
{
45-
"sha": "${{steps.sha.outputs.SHA}}",
73+
"sha": "${{ steps.sha_value.outputs.SHA }}",
4674
"state": "pending",
47-
"context": "Testing Farm - CentOS7 - OpenShift 3",
48-
"target_url": "http://artifacts.dev.testing-farm.io/${{ steps.sched_test.outputs.req_id }}/pipeline.log"
75+
"context": "Testing Farm - ${{ matrix.context }}",
76+
"target_url": "${{ matrix.tmt_url }}"
4977
}
5078
EOF
51-
echo "https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{steps.sha.outputs.SHA}}"
79+
echo "https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ steps.sha_value.outputs.SHA }}"
5280
# GITHUB_TOKEN is used for updating pull request status.
5381
# It is provided by GitHub https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret
5482
curl -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
55-
https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{steps.sha.outputs.SHA}} \
83+
https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ steps.sha_value.outputs.SHA }} \
5684
--data @pending.json
5785
echo "::set-output name=GITHUB_REPOSITORY::$GITHUB_REPOSITORY"
5886
59-
- name: Schedule a test on Testing Farm forn CentOS7 - OpenShift 3
87+
- name: Schedule a test on Testing Farm
6088
id: sched_test
6189
run: |
6290
# Update ubuntu-20.04 in order to install curl and jq
63-
apt update && apt -y install curl 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
6499
cat << EOF > request.json
65100
{
66-
"api_key": "${{ secrets.TF_PUBLIC_API_KEY }}",
101+
"api_key": "$api_key",
67102
"test": {"fmf": {
68-
"url": "https://github.com/sclorg/sclorg-testing-farm",
69-
"ref": "main",
70-
"name": "fedora"
103+
"url": "${{ matrix.tmt_repo }}",
104+
"ref": "$branch_name",
105+
"name": "${{ matrix.tmt_plan }}"
71106
}},
72107
"environments": [{
73108
"arch": "x86_64",
74-
"os": {"compose": "CentOS-7"},
109+
"os": {"compose": "${{ matrix.compose }}"},
75110
"variables": {
76111
"REPO_URL": "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY",
77112
"REPO_NAME": "$GITHUB_REPOSITORY",
78113
"PR_NUMBER": "${{ steps.pr_nr.outputs.PR_NR }}",
79-
"OS": "centos7",
80-
"TEST_NAME": "test-openshift"
114+
"OS": "${{ matrix.os_test }}",
115+
"TEST_NAME": "${{ matrix.test_name }}"
81116
}
82117
}]
83118
}
84119
EOF
85120
curl ${{ secrets.TF_ENDPOINT }}/requests --data @request.json --header "Content-Type: application/json" --output response.json
86-
# Store REQ_ID into outputs for later on usage
87-
echo "::set-output name=REQ_ID::$(jq -r .id response.json)"
121+
cat response.json
88122
89-
running:
90-
needs: build
91-
name: Check running tests on Testing Farm service
92-
runs-on: ubuntu-20.04
93-
outputs:
94-
REQ_ID: ${{steps.req_sha.outputs.REQ_ID}}
95-
SHA: ${{steps.req_sha.outputs.SHA}}
96-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97-
steps:
98-
- name: Check if REQ_ID and SHA exists
99-
id: req_sha
100-
run: |
101-
# Update ubuntu-20.04 in order to install curl and jq
102-
# each job is separate machine
103-
apt update && apt -y install curl jq
104-
# Propagate REQ_ID and SHA into the finish section
105-
echo "::set-output name=REQ_ID::${{needs.build.outputs.REQ_ID}}"
106-
echo "::set-output name=SHA::${{needs.build.outputs.SHA}}"
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
107126
108127
- name: Switch to running state of Testing Farm request
109128
id: running
110129
run: |
111130
# Create running.json file for query, whether job is finished or not.
112131
cat << EOF > running.json
113132
{
114-
"sha": "${{needs.build.outputs.SHA}}",
133+
"sha": "${{ steps.sha_value.outputs.SHA }}",
115134
"state": "pending",
116-
"context": "Testing Farm - CentOS7 - OpenShift 3",
135+
"context": "Testing Farm - ${{ matrix.context }}",
117136
"description": "Build started",
118-
"target_url": "http://artifacts.dev.testing-farm.io/${{ needs.build.outputs.REQ_ID }}/"
137+
"target_url": "${{ matrix.tmt_url }}/${{ env.REQ_ID }}"
119138
}
120139
EOF
121140
# Update GitHub status description to 'Build started'
122-
curl -X POST -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" -H "Accept: application/vnd.github.v3+json" \
123-
https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{needs.build.outputs.SHA}} \
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 }} \
124143
--data @running.json
125144
126145
- name: Check test is still running
127146
id: still_running
128147
run: |
129-
CMD=${{ secrets.TF_ENDPOINT }}/requests/${{needs.build.outputs.REQ_ID}}
148+
CMD=${{ secrets.TF_ENDPOINT }}/requests/${{ env.REQ_ID }}
130149
curl $CMD > job.json
150+
cat job.json
131151
state=$(jq -r .state job.json)
132152
# Wait till job is not finished. As soon as state is complete or failure then go to the finish action
133153
while [ "$state" == "running" ] || [ "$state" == "new" ] || [ "$state" == "pending" ] || [ "$state" == "queued" ]; do
@@ -137,24 +157,10 @@ jobs:
137157
state=$(jq -r .state job.json)
138158
done
139159
140-
finish:
141-
needs: running
142-
name: Tests are finished - switching to proper state
143-
runs-on: ubuntu-20.04
144-
steps:
145-
- name: Check if REQ_ID exists
146-
run: echo "${{ needs.running.outputs.REQ_ID }}"
147-
148-
- name: Check if SHA exists
149-
run: echo "${{ needs.running.outputs.SHA }}"
150-
151160
- name: Get final state of Testing Farm request
152161
id: final_state
153162
run: |
154-
# Update ubuntu-20.04 in order to install curl and jq
155-
# each job is separate machine
156-
apt update && apt -y install curl jq
157-
curl ${{ secrets.TF_ENDPOINT }}/requests/${{needs.running.outputs.REQ_ID}} > job.json
163+
curl ${{ secrets.TF_ENDPOINT }}/requests/${{ env.REQ_ID }} > job.json
158164
cat job.json
159165
state=$(jq -r .state job.json)
160166
result=$(jq -r .result.overall job.json)
@@ -179,15 +185,15 @@ jobs:
179185
run: |
180186
cat << EOF > final.json
181187
{
182-
"sha": "${{needs.running.outputs.SHA}}",
183-
"state": "${{steps.final_state.outputs.FINAL_STATE}}",
184-
"context": "Testing Farm - CentOS7 - OpenShift 3",
185-
"description": "Build finished${{steps.final_state.outputs.INFRA_STATE}}",
186-
"target_url": "http://artifacts.dev.testing-farm.io/${{ needs.running.outputs.REQ_ID }}/"
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 }}"
187193
}
188194
EOF
189195
cat final.json
190196
# Switch Github status to proper state
191-
curl -X POST -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" -H "Accept: application/vnd.github.v3+json" \
192-
https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{needs.running.outputs.SHA}} \
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 }} \
193199
--data @final.json

0 commit comments

Comments
 (0)