-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
141 lines (129 loc) · 5.57 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: "Schedule regression tests on Testing Farm"
description: |
A github action will issue a request to the Testing Farm Service to run tmt tests from a certain
repository, with certain copr-build(s) and a certain compose.
inputs:
tft_server:
description: 'A Testing farm server url'
required: true
tft_token:
description: 'A testing farm user token'
required: true
compose:
description: 'A compose for tests'
required: true
tests_repository:
description: 'A git repository containing tmt tests'
default: 'https://gitlab.cee.redhat.com/oamg/tmt-plans'
tests_regex:
description: 'Limit to running specific tests only with regex'
default: '^(?!.*c2r)(?!.*sap)'
tests_ref:
desription: 'Specify a git ref for tests'
default: 'master'
arch:
description: 'Specify an architecture for test env'
default: 'x86_64'
copr:
description: 'Name of copr to use for the artifacts'
default: 'epel-7-x86_64'
artifacts:
description: 'Comma-separated copr-builds to install in test env'
required: true
env_vars:
description: 'Environment variables for test env, separated by ; or ,'
default: ''
tmt_context:
description: 'Value of tmt.context, variables separated by ; or ,'
default: ''
debug:
description: 'Print debug logs when preparing/issuing request'
default: 'true'
test_name:
description: 'A name for the launched test set. Something human-readable to be shown in github comment together with the results.'
default: ''
outputs:
request_id:
description: "An id of a scheduled testing farm request"
value: ${{ steps.sched_test.outputs.req_id }}
runs:
using: "composite"
steps:
- name: Generate artifacts list
id: gen_artifacts_list
run: |
python -c 'import json;print(json.dumps(([{"type": "fedora-copr-build", "id": "{}:${{ inputs.copr }}".format(copr_id)} for copr_id in "${{ inputs.artifacts }}".split(",")])))' > artifacts
echo "::set-output name=artifacts_list::$(cat artifacts)"
shell: bash
- name: Generate env_vars
id: gen_env_vars
run: |
python -c 'import json; sep=";" if ";" in "${{ inputs.env_vars }}" else ","; print({} if not "${{ inputs.env_vars }}".strip() else json.dumps({key: value for key, value in [s.split("=", 1) for s in "${{ inputs.env_vars }}".split(sep)]}))' > env_vars
echo "::set-output name=env_vars::$(cat env_vars)"
shell: bash
- name: Generate tmt context
id: gen_tmt_context
run: |
python -c 'import json; sep=";" if ";" in "${{ inputs.tmt_context }}" else ","; print({} if not "${{ inputs.tmt_context }}".strip() else json.dumps({key: value for key, value in [s.split("=", 1) for s in "${{ inputs.tmt_context }}".split(sep)]}))' > tmt_context
echo "::set-output name=tmt_context::$(cat tmt_context)"
shell: bash
- name: Generate a tmt test request
id: gen_tmt_request
run: |
cat << EOF > request.json
{
"api_key": "${{ inputs.tft_token }}",
"test": {"fmf": {
"url": "${{ inputs.tests_repository }}",
"ref": "${{ inputs.tests_ref }}",
"name": "${{ inputs.tests_regex }}"
}},
"environments": [{
"arch": "${{ inputs.arch }}",
"os": {"compose": "${{ inputs.compose }}"},
"variables": ${{ steps.gen_env_vars.outputs.env_vars }},
"artifacts": ${{ steps.gen_artifacts_list.outputs.artifacts_list }},
"tmt": {"context": ${{ steps.gen_tmt_context.outputs.tmt_context }}}
}]
}
EOF
if [ "${{ inputs.debug }}" = "true" ]; then
echo request.json
jq < request.json
fi
shell: bash
- name: Send request to testing farm service
# This step schedules a tmt test. The test id is stored in `req_id` variable for a later use.
# All the discovered test plans matching the regex `tests.fmf.name` from the repository specified in
# `tests.fmf.url` are run.
#
# At this moment repo/sha that triggered the action is used, i.e. all tests plans specified in THIS repository
# are run.
id: sched_test
run: |
curl ${{ inputs.tft_server }}/requests \
--data @request.json \
--header "Content-Type: application/json" \
--output response.json
if [ "${{ inputs.debug }}" = "true" ]; then
echo response.json
jq < response.json
fi
echo "::set-output name=req_id::$(jq -r .id response.json)"
shell: bash
- name: Add comment with Testing Farm request/result
# This step adds a new comment to the pull request with a link to the test.
# TODO: This is a temporary workaround until a proper way to set a commit status is implemented.
id: comment
uses: actions/github-script@v4
with:
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Testing Farm [request](${{ inputs.tft_server }}/requests/${{ steps.sched_test.outputs.req_id }})' +
' for ${{ inputs.test_name }}/${{ inputs.artifacts }} regression testing has been created. Once finished, results should be available' +
' [here](http://artifacts.osci.redhat.com/testing-farm/${{ steps.sched_test.outputs.req_id }}/).' +
'\n[Full pipeline log](http://artifacts.osci.redhat.com/testing-farm/${{ steps.sched_test.outputs.req_id }}/pipeline.log).'
})