diff --git a/.buildkite/hooks/post-command b/.buildkite/hooks/post-command index 2a7fdad01..9817ef9a3 100755 --- a/.buildkite/hooks/post-command +++ b/.buildkite/hooks/post-command @@ -12,14 +12,18 @@ fi if [[ ! "${BUILDKITE_BRANCH}" =~ ^(v.*) ]] && [[ "${BUILDKITE_COMMAND_EXIT_STATUS}" == 0 ]]; then if [[ "${BUILDKITE_LABEL}" == ":hammer_and_wrench: Unit Test" ]] || [[ "${BUILDKITE_LABEL}" =~ ":selenium:" ]]; then echo "--- :codecov: Upload coverage reports" + NAME="UnitTest" if [[ "${BUILDKITE_AGENT_META_DATA_CODECOV}" == "verbose" ]]; then BUILDKITE_AGENT_META_DATA_CODECOV="-v" fi - bash <(curl -s --connect-timeout 10 --retry 10 --retry-max-time 0 https://codecov.io/bash) -Z -c -s 'coverage*.txt' -F backend "${BUILDKITE_AGENT_META_DATA_CODECOV}" + if [[ "${BUILDKITE_LABEL}" =~ ":selenium:" ]]; then + NAME=$(echo ${BUILDKITE_LABEL/:selenium: /} | awk '{ print $1 }') + fi + codecov -Z -c -f 'coverage*.txt' -n ${NAME} -F backend "${BUILDKITE_AGENT_META_DATA_CODECOV}" if [[ "${BUILDKITE_LABEL}" =~ ":selenium:" ]]; then cd web && pnpm report fi - bash <(curl -s --connect-timeout 10 --retry 10 --retry-max-time 0 https://codecov.io/bash) -Z -c -f '!*.go' -f '!*.zst' -F frontend "${BUILDKITE_AGENT_META_DATA_CODECOV}" + codecov -Z -c -f '!Dockerfile*' -f '!*.go' -f '!*.zst' -n ${NAME} -F frontend "${BUILDKITE_AGENT_META_DATA_CODECOV}" fi fi diff --git a/internal/suites/utils.go b/internal/suites/utils.go index 770030c78..6e26e87b8 100644 --- a/internal/suites/utils.go +++ b/internal/suites/utils.go @@ -1,8 +1,11 @@ package suites import ( + "io/ioutil" "os" + "path/filepath" "strconv" + "strings" ) // GetLoginBaseURL returns the URL of the login portal and the path prefix if specified. @@ -25,3 +28,37 @@ func GetWebDriverPort() int { return p } + +func fixCoveragePath(path string, file os.FileInfo, err error) error { + if err != nil { + return err + } + + if file.IsDir() { + return nil + } + + coverage, err := filepath.Match("*.json", file.Name()) + + if err != nil { + return err + } + + if coverage { + read, err := ioutil.ReadFile(path) + if err != nil { + return err + } + + wd, _ := os.Getwd() + ciPath := strings.TrimSuffix(wd, "internal/suites") + content := strings.ReplaceAll(string(read), "/node/src/app/", ciPath+"web/") + + err = ioutil.WriteFile(path, []byte(content), 0) + if err != nil { + return err + } + } + + return nil +} diff --git a/internal/suites/webdriver.go b/internal/suites/webdriver.go index 6b2b3351f..106207670 100644 --- a/internal/suites/webdriver.go +++ b/internal/suites/webdriver.go @@ -7,6 +7,7 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" "strings" "testing" "time" @@ -103,6 +104,11 @@ func (wds *WebDriverSession) Stop() error { return err } + err = filepath.Walk("../../web/.nyc_output", fixCoveragePath) + if err != nil { + return err + } + err = wds.WebDriver.Quit() if err != nil { return err