Skip to content

Commit 2117ee8

Browse files
authored
Merge pull request sclorg#440 from sclorg/use_tfaga_for_openshift-tests
Use Testing Farm as GitHub Action also for OpenShift tests
2 parents 35f372c + abf8488 commit 2117ee8

File tree

1 file changed

+32
-154
lines changed

1 file changed

+32
-154
lines changed

.github/workflows/openshift-tests.yml

Lines changed: 32 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
name: openshift-tests at Testing Farm
1+
name: OpenShift tests by GitHub Action at Testing Farm
22

33
on:
44
issue_comment:
55
types:
66
- created
77
jobs:
88
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
1111
runs-on: ubuntu-20.04
1212
strategy:
1313
fail-fast: false
@@ -16,184 +16,62 @@ jobs:
1616
- tmt_plan: "centos7"
1717
os_test: "centos7"
1818
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"
2121
tmt_repo: "https://github.com/sclorg/sclorg-testing-farm"
22+
compose: "CentOS-7"
2223
test_name: "test-openshift"
2324
- tmt_plan: "rhel7-openshift-3"
2425
os_test: "rhel7"
2526
context: "RHEL7 - OpenShift 3"
2627
compose: "RHEL-7.9-Released"
28+
api_key: "TF_INTERNAL_API_KEY"
29+
branch: "master"
2730
tmt_url: "http://artifacts.osci.redhat.com/testing-farm/"
2831
tmt_repo: "https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
2932
test_name: "test-openshift"
33+
tf_scope: "private"
3034
- tmt_plan: "rhel7-openshift-4"
3135
os_test: "rhel7"
3236
context: "RHEL7 - OpenShift 4"
3337
compose: "RHEL-7.9-Released"
3438
tmt_url: "http://artifacts.osci.redhat.com/testing-farm/"
35-
tmt_repo: "https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
3639
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"
3744
- tmt_plan: "rhel8-openshift-4"
3845
os_test: "rhel8"
3946
context: "RHEL8 - OpenShift 4"
4047
compose: "RHEL-8.3.1-Released"
4148
tmt_url: "http://artifacts.osci.redhat.com/testing-farm/"
42-
tmt_repo: "https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
4349
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+
4455
if: |
4556
github.event.issue.pull_request
4657
&& (contains(github.event.comment.body, '[test-openshift]') || contains(github.event.comment.body, '[test-all]'))
4758
&& contains(fromJson('["OWNER", "MEMBER"]'), github.event.comment.author_association)
4859
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-
5560
- name: Checkout repo
5661
uses: actions/checkout@v2
5762
with:
58-
ref: "refs/pull/${{ steps.pr_nr.outputs.PR_NR }}/head"
63+
ref: "refs/pull/${{ github.event.issue.number }}/head"
5964

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

Comments
 (0)