1- name : CentOS7 -tests@TF
1+ name : container -tests at Testing Farm
22
33on :
44 issue_comment :
77jobs :
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
10+ name : Container tests on Testing Farm service
1111 runs-on : ubuntu-20.04
12+ strategy :
13+ fail-fast : false
14+ matrix :
15+ include :
16+ - tmt_plan : " fedora"
17+ os_test : " fedora"
18+ context : " Fedora"
19+ compose : " CentOS-7"
20+ tmt_url : " http://artifacts.dev.testing-farm.io/"
21+ tmt_repo : " https://github.com/sclorg/sclorg-testing-farm"
22+ - tmt_plan : " centos7"
23+ os_test : " centos7"
24+ context : " CentOS7"
25+ compose : " CentOS-7"
26+ tmt_url : " http://artifacts.dev.testing-farm.io/"
27+ tmt_repo : " https://github.com/sclorg/sclorg-testing-farm"
28+ - tmt_plan : " rhel7-docker"
29+ os_test : " rhel7"
30+ context : " RHEL7"
31+ compose : " RHEL-7.9-Released"
32+ tmt_url : " http://artifacts.osci.redhat.com/testing-farm/"
33+ tmt_repo : " https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
34+ - tmt_plan : " rhel8-docker"
35+ os_test : " rhel8"
36+ context : " RHEL8"
37+ compose : " RHEL-8.3.1-Released"
38+ tmt_url : " http://artifacts.osci.redhat.com/testing-farm/"
39+ tmt_repo : " https://gitlab.cee.redhat.com/platform-eng-core-services/sclorg-tmt-plans"
1240 if : |
1341 github.event.issue.pull_request
1442 && (contains(github.event.comment.body, '[test]') || contains(github.event.comment.body, '[test-all]'))
1543 && 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}}
1944 steps :
2045 - name : Get pull request number
2146 id : pr_nr
@@ -28,106 +53,97 @@ jobs:
2853 with :
2954 ref : " refs/pull/${{ steps.pr_nr.outputs.PR_NR }}/head"
3055
31- - name : Get sha
32- id : sha
56+ - name : SHA value
57+ id : sha_value
3358 run : |
34- # Store SHA into outputs
3559 echo "::set-output name=SHA::$(git rev-parse HEAD)"
3660
3761 - name : Create status check to pending
3862 id : pending
3963 env :
4064 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4165 run : |
42- # Create a JSON file for Testing Farm in order to schedule a CI testing job
66+ # Create a JSON data structure for GitHub API to display the test status in the PR
4367 cat << EOF > pending.json
4468 {
45- "sha": "${{steps.sha .outputs.SHA}}",
69+ "sha": "${{ steps.sha_value .outputs.SHA }}",
4670 "state": "pending",
47- "context": "Testing Farm - CentOS7 ",
48- "target_url": "http://artifacts.dev.testing-farm.io/ ${{ steps.sched_test.outputs.req_id }}/pipeline.log "
71+ "context": "Testing Farm - ${{ matrix.context }} ",
72+ "target_url": "${{ matrix.tmt_url }}"
4973 }
5074 EOF
51- echo "https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{steps.sha .outputs.SHA}}"
75+ echo "https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ steps.sha_value .outputs.SHA }}"
5276 # GITHUB_TOKEN is used for updating pull request status.
5377 # It is provided by GitHub https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret
5478 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}} \
79+ https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ steps.sha_value .outputs.SHA }} \
5680 --data @pending.json
5781 echo "::set-output name=GITHUB_REPOSITORY::$GITHUB_REPOSITORY"
5882
59- - name : Schedule a test on Testing Farm forn CentOS7
83+ - name : Schedule a test on Testing Farm
6084 id : sched_test
6185 run : |
6286 # Update ubuntu-20.04 in order to install curl and jq
63- apt update && apt -y install curl jq
87+ sudo apt update && sudo apt -y install curl jq
88+ if [ "${{ matrix.tmt_plan }}" == "fedora" ] || [ "${{ matrix.tmt_plan }}" == "centos7" ]; then
89+ api_key="${{ secrets.TF_PUBLIC_API_KEY }}"
90+ branch_name="main"
91+ else
92+ api_key="${{ secrets.TF_INTERNAL_API_KEY }}"
93+ branch_name="master"
94+ fi
6495 cat << EOF > request.json
6596 {
66- "api_key": "${{ secrets.TF_PUBLIC_API_KEY }} ",
97+ "api_key": "$api_key ",
6798 "test": {"fmf": {
68- "url": "https://github.com/sclorg/sclorg-testing-farm ",
69- "ref": "main ",
70- "name": "fedora "
99+ "url": "${{ matrix.tmt_repo }} ",
100+ "ref": "$branch_name ",
101+ "name": "${{ matrix.tmt_plan }} "
71102 }},
72103 "environments": [{
73104 "arch": "x86_64",
74- "os": {"compose": "CentOS-7 "},
105+ "os": {"compose": "${{ matrix.compose }} "},
75106 "variables": {
76107 "REPO_URL": "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY",
77108 "REPO_NAME": "$GITHUB_REPOSITORY",
78109 "PR_NUMBER": "${{ steps.pr_nr.outputs.PR_NR }}",
79- "OS": "centos7 ",
110+ "OS": "${{ matrix.os_test }} ",
80111 "TEST_NAME": "test"
81112 }
82113 }]
83114 }
84115 EOF
85116 curl ${{ secrets.TF_ENDPOINT }}/requests --data @request.json --header "Content-Type: application/json" --output response.json
117+ cat response.json
118+
86119 # Store REQ_ID into outputs for later on usage
87- echo "::set-output name=REQ_ID::$(jq -r .id response.json)"
88-
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}}"
120+ req_id=$(jq -r .id response.json)
121+ echo "REQ_ID=$req_id" >> $GITHUB_ENV
107122
108123 - name : Switch to running state of Testing Farm request
109124 id : running
110125 run : |
111126 # Create running.json file for query, whether job is finished or not.
112127 cat << EOF > running.json
113128 {
114- "sha": "${{needs.build .outputs.SHA}}",
129+ "sha": "${{ steps.sha_value .outputs.SHA }}",
115130 "state": "pending",
116- "context": "Testing Farm - CentOS7 ",
131+ "context": "Testing Farm - ${{ matrix.context }} ",
117132 "description": "Build started",
118- "target_url": "http://artifacts.dev.testing-farm.io /${{ needs.build.outputs. REQ_ID }}/ "
133+ "target_url": "${{ matrix.tmt_url }} /${{ env. REQ_ID }}"
119134 }
120135 EOF
121136 # 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}} \
137+ curl -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" \
138+ https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ steps.sha_value .outputs.SHA }} \
124139 --data @running.json
125140
126141 - name : Check test is still running
127142 id : still_running
128143 run : |
129- CMD=${{ secrets.TF_ENDPOINT }}/requests/${{needs.build.outputs. REQ_ID}}
144+ CMD=${{ secrets.TF_ENDPOINT }}/requests/${{ env. REQ_ID }}
130145 curl $CMD > job.json
146+ cat job.json
131147 state=$(jq -r .state job.json)
132148 # Wait till job is not finished. As soon as state is complete or failure then go to the finish action
133149 while [ "$state" == "running" ] || [ "$state" == "new" ] || [ "$state" == "pending" ] || [ "$state" == "queued" ]; do
@@ -137,24 +153,10 @@ jobs:
137153 state=$(jq -r .state job.json)
138154 done
139155
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-
151156 - name : Get final state of Testing Farm request
152157 id : final_state
153158 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
159+ curl ${{ secrets.TF_ENDPOINT }}/requests/${{ env.REQ_ID }} > job.json
158160 cat job.json
159161 state=$(jq -r .state job.json)
160162 result=$(jq -r .result.overall job.json)
@@ -179,15 +181,15 @@ jobs:
179181 run : |
180182 cat << EOF > final.json
181183 {
182- "sha": "${{needs.running .outputs.SHA}}",
183- "state": "${{steps.final_state.outputs.FINAL_STATE}}",
184- "context": "Testing Farm - CentOS7 ",
185- "description": "Build finished${{steps.final_state.outputs.INFRA_STATE}}",
186- "target_url": "http://artifacts.dev.testing-farm.io /${{ needs.running.outputs. REQ_ID }}/ "
184+ "sha": "${{ steps.sha_value .outputs.SHA }}",
185+ "state": "${{ steps.final_state.outputs.FINAL_STATE }}",
186+ "context": "Testing Farm - ${{ matrix.context }} ",
187+ "description": "Build finished${{ steps.final_state.outputs.INFRA_STATE }}",
188+ "target_url": "${{ matrix.tmt_url }} /${{ env. REQ_ID }}"
187189 }
188190 EOF
189191 cat final.json
190192 # 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}} \
193+ curl -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" \
194+ https://api.github.com/repos/$GITHUB_REPOSITORY/statuses/${{ steps.sha_value .outputs.SHA }} \
193195 --data @final.json
0 commit comments