Skip to content

Commit

Permalink
ci: delete Qase Run if job has been cancelled
Browse files Browse the repository at this point in the history
Signed-off-by: Loic Devulder <ldevulder@suse.com>
  • Loading branch information
ldevulder committed Jan 22, 2024
1 parent cc95006 commit dbd3185
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/master-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,12 @@ jobs:
echo "Channel: ${{ inputs.upgrade_os_channel }}" >> ${GITHUB_STEP_SUMMARY}
echo "Upgrade image: ${{ inputs.upgrade_image }}" >> ${GITHUB_STEP_SUMMARY}
fi
- name: Delete Qase Run if job has been cancelled
if: ${{ failure() && job.status == 'cancelled' }}
run: |
if [[ -n "${QASE_RUN_ID}" ]]; then
cd tests && make delete-qase-run
fi
- name: Send failed status to slack
if: ${{ failure() && github.event_name == 'schedule' }}
uses: slackapi/slack-github-action@v1.23.0
Expand Down
6 changes: 4 additions & 2 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ deps:
generate-readme:
@./scripts/generate-readme > README.md

# Qase deps
# Qase commands
create-qase-run: deps
@go run qase/create_qase_run.go
@go run qase/qase_cmd.go -create
delete-qase-run: deps
@go run qase/qase_cmd.go -delete ${QASE_RUN_ID}

# E2E tests
e2e-airgap-rancher: deps
Expand Down
35 changes: 32 additions & 3 deletions tests/e2e/helpers/qase/qase.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ func CreateRun() int32 {
logrus.Debugf("Run named '%s' with description '%s' created with id %d", runName, runDescription, createdID)

// Check that we can access the run
checkRun(client, createdID)
if itExists := checkRun(client, createdID); itExists == false {

Check failure on line 144 in tests/e2e/helpers/qase/qase.go

View workflow job for this annotation

GitHub Actions / golang-lint

S1002: should omit comparison to bool constant, can be simplified to `!itExists` (gosimple)
logrus.Fatalf("Run %d doesn't exist", createdID)
}

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

return runResponse.Status
}

/*
Expand Down Expand Up @@ -189,6 +193,31 @@ func deleteRun(client *qase.APIClient, id int32) {
}
}

/*
This function creates a run in a specific project.
- @param name Name of the run
- @param description Short description of the run
- @return ID of the created run
*/
func DeleteRun(id int32) {
cfg := qase.NewConfiguration()
cfg.AddDefaultHeader("Token", apiToken)
client := qase.NewAPIClient(cfg)

if checkProject(client, projectCode) {
logrus.Debugf("Project %s is validated", projectCode)

// Delete test run
deleteRun(client, id)
logrus.Debugf("Run id %d has been deleted", id)

// Check that we can't access the run
if itExists := checkRun(client, id); itExists == true {

Check failure on line 215 in tests/e2e/helpers/qase/qase.go

View workflow job for this annotation

GitHub Actions / golang-lint

S1002: should omit comparison to bool constant, can be simplified to `itExists` (gosimple)
logrus.Fatalf("Run %d still exists", id)
}
}
}

/*
This function finalises the results for a specific run.
- @return Fatal on error
Expand Down
25 changes: 24 additions & 1 deletion tests/qase/create_qase_run.go → tests/qase/qase_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,35 @@ limitations under the License.
package main

import (
"flag"
"fmt"

"github.com/rancher/elemental/tests/e2e/helpers/qase"
"github.com/sirupsen/logrus"
)

// Only use to create a run in Qase and return the corresponding created ID
func main() {
fmt.Printf("%d", qase.CreateRun())
// Define the allowed options
createRun := flag.Bool("create", false, "create a new Qase run")
deleteRun := flag.Int("delete", 0, "delete a Qase run")

// Parse the arguments
flag.Parse()

// Only one option at a time is allowed
if *createRun {
id := qase.CreateRun()
if id <= 0 {
logrus.Fatalln("Error on creating Qase run")
}
logrus.Debugf("Qase run id %d created", id)
fmt.Printf("%d", id)
} else if *deleteRun > 0 {
qase.DeleteRun(int32(*deleteRun))
logrus.Debugf("Qase run id %d deleted", *deleteRun)
} else {
logrus.Debugln("Nothing do to!")
}

}

0 comments on commit dbd3185

Please sign in to comment.