Skip to content

Commit 8dd523e

Browse files
committed
ci: delete Qase Run if job has been cancelled
Signed-off-by: Loic Devulder <ldevulder@suse.com>
1 parent cc95006 commit 8dd523e

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

.github/workflows/master-e2e.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,12 @@ jobs:
692692
echo "Channel: ${{ inputs.upgrade_os_channel }}" >> ${GITHUB_STEP_SUMMARY}
693693
echo "Upgrade image: ${{ inputs.upgrade_image }}" >> ${GITHUB_STEP_SUMMARY}
694694
fi
695+
- name: Delete Qase Run if job has been cancelled
696+
if: ${{ failure() && job.status == 'cancelled' }}
697+
run: |
698+
if [[ -n "${QASE_RUN_ID}" ]]; then
699+
cd tests && make delete-qase-run
700+
fi
695701
- name: Send failed status to slack
696702
if: ${{ failure() && github.event_name == 'schedule' }}
697703
uses: slackapi/slack-github-action@v1.23.0

tests/Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ deps:
4444
generate-readme:
4545
@./scripts/generate-readme > README.md
4646

47-
# Qase deps
47+
# Qase commands
4848
create-qase-run: deps
49-
@go run qase/create_qase_run.go
49+
@go run qase/qase_cmd.go -create
50+
delete-qase-run: deps
51+
@go run qase/qase_cmd.go -delete ${QASE_RUN_ID}
5052

5153
# E2E tests
5254
e2e-airgap-rancher: deps

tests/e2e/helpers/qase/qase.go

+32-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ func CreateRun() int32 {
141141
logrus.Debugf("Run named '%s' with description '%s' created with id %d", runName, runDescription, createdID)
142142

143143
// Check that we can access the run
144-
checkRun(client, createdID)
144+
if itExists := checkRun(client, createdID); !itExists {
145+
logrus.Fatalf("Run %d doesn't exist", createdID)
146+
}
145147

146148
// Export runID for all functions to use it
147149
os.Setenv("QASE_RUN_ID", fmt.Sprint(runID))
@@ -156,11 +158,13 @@ This function checks the availability of a specific run.
156158
- @param id ID of the run to check
157159
- @return Fatal on error
158160
*/
159-
func checkRun(client *qase.APIClient, id int32) {
161+
func checkRun(client *qase.APIClient, id int32) bool {
160162
runResponse, _, err := client.RunsApi.GetRun(context.TODO(), projectCode, id)
161-
if err != nil || !runResponse.Status {
163+
if err != nil {
162164
logrus.Fatalf("Error on checking run: %v", err)
163165
}
166+
167+
return runResponse.Status
164168
}
165169

166170
/*
@@ -189,6 +193,31 @@ func deleteRun(client *qase.APIClient, id int32) {
189193
}
190194
}
191195

196+
/*
197+
This function creates a run in a specific project.
198+
- @param name Name of the run
199+
- @param description Short description of the run
200+
- @return ID of the created run
201+
*/
202+
func DeleteRun(id int32) {
203+
cfg := qase.NewConfiguration()
204+
cfg.AddDefaultHeader("Token", apiToken)
205+
client := qase.NewAPIClient(cfg)
206+
207+
if checkProject(client, projectCode) {
208+
logrus.Debugf("Project %s is validated", projectCode)
209+
210+
// Delete test run
211+
deleteRun(client, id)
212+
logrus.Debugf("Run id %d has been deleted", id)
213+
214+
// Check that we can't access the run
215+
if itExists := checkRun(client, id); itExists {
216+
logrus.Fatalf("Run %d still exists", id)
217+
}
218+
}
219+
}
220+
192221
/*
193222
This function finalises the results for a specific run.
194223
- @return Fatal on error

tests/qase/create_qase_run.go tests/qase/qase_cmd.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,35 @@ limitations under the License.
1515
package main
1616

1717
import (
18+
"flag"
1819
"fmt"
1920

2021
"github.com/rancher/elemental/tests/e2e/helpers/qase"
22+
"github.com/sirupsen/logrus"
2123
)
2224

2325
// Only use to create a run in Qase and return the corresponding created ID
2426
func main() {
25-
fmt.Printf("%d", qase.CreateRun())
27+
// Define the allowed options
28+
createRun := flag.Bool("create", false, "create a new Qase run")
29+
deleteRun := flag.Int("delete", 0, "delete a Qase run")
30+
31+
// Parse the arguments
32+
flag.Parse()
33+
34+
// Only one option at a time is allowed
35+
if *createRun {
36+
id := qase.CreateRun()
37+
if id <= 0 {
38+
logrus.Fatalln("Error on creating Qase run")
39+
}
40+
logrus.Debugf("Qase run id %d created", id)
41+
fmt.Printf("%d", id)
42+
} else if *deleteRun > 0 {
43+
qase.DeleteRun(int32(*deleteRun))
44+
logrus.Debugf("Qase run id %d deleted", *deleteRun)
45+
} else {
46+
logrus.Debugln("Nothing do to!")
47+
}
48+
2649
}

0 commit comments

Comments
 (0)