From 4161fbd818a45df3067484f4bfdf696a3dca62ee Mon Sep 17 00:00:00 2001 From: Amir Zarrinkafsh Date: Fri, 8 Oct 2021 11:17:08 +1100 Subject: [PATCH] ci(codecov): utilise new codecov uploader for coverage (#2467) * ci(codecov): utilise new codecov uploader for coverage The codecov bash uploader is being [deprecated](https://docs.codecov.com/docs/about-the-codecov-bash-uploader). This utilises the new uploader which is recommended. * ci(codecov): adjust file search path and name uploads * fix(suites): coverage paths for codecov --- .buildkite/hooks/post-command | 8 ++++++-- internal/suites/utils.go | 37 +++++++++++++++++++++++++++++++++++ internal/suites/webdriver.go | 6 ++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/.buildkite/hooks/post-command b/.buildkite/hooks/post-command index 2a7fdad0..9817ef9a 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 770030c7..6e26e87b 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 6b2b3351..10620767 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