From 50b09d4f885af5a2d7f936f8cae09bc758299139 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Wed, 26 Jan 2022 15:34:59 +0100 Subject: [PATCH] Re-enable code coverage upload --- .github/workflows/coverage.yaml | 28 +++++++++++++++++++++++++ README.md | 2 +- test.sh | 2 +- tests/framework/e2e/etcd_spawn.go | 24 +++++++++++++++++++++ tests/framework/e2e/etcd_spawn_cov.go | 10 +++------ tests/framework/e2e/etcd_spawn_nocov.go | 25 ---------------------- tests/framework/e2e/util.go | 21 +++++++++++++++++++ 7 files changed, 78 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/coverage.yaml create mode 100644 tests/framework/e2e/etcd_spawn.go diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml new file mode 100644 index 000000000..0bab51853 --- /dev/null +++ b/.github/workflows/coverage.yaml @@ -0,0 +1,28 @@ +name: Coverage +on: [push, pull_request] +jobs: + coverage: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: + - linux-amd64-coverage + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: "1.17.6" + - env: + TARGET: ${{ matrix.target }} + run: | + mkdir "${TARGET}" + case "${TARGET}" in + linux-amd64-coverage) + GOARCH=amd64 ./scripts/codecov_upload.sh + ;; + *) + echo "Failed to find target" + exit 1 + ;; + esac diff --git a/README.md b/README.md index 27c8555bd..ee813ed9f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # etcd [![Go Report Card](https://goreportcard.com/badge/github.com/etcd-io/etcd?style=flat-square)](https://goreportcard.com/report/github.com/etcd-io/etcd) -[![Coverage](https://codecov.io/gh/etcd-io/etcd/branch/master/graph/badge.svg)](https://codecov.io/gh/etcd-io/etcd) +[![Coverage](https://codecov.io/gh/etcd-io/etcd/branch/main/graph/badge.svg)](https://codecov.io/gh/etcd-io/etcd) [![Tests](https://github.com/etcd-io/etcd/actions/workflows/tests.yaml/badge.svg)](https://github.com/etcd-io/etcd/actions/workflows/tests.yaml) [![asset-transparency](https://github.com/etcd-io/etcd/actions/workflows/asset-transparency.yaml/badge.svg)](https://github.com/etcd-io/etcd/actions/workflows/asset-transparency.yaml) [![codeql-analysis](https://github.com/etcd-io/etcd/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/etcd-io/etcd/actions/workflows/codeql-analysis.yml) diff --git a/test.sh b/test.sh index 586fa3292..808e4d902 100755 --- a/test.sh +++ b/test.sh @@ -320,7 +320,7 @@ function cov_pass { -timeout=5m "${gocov_build_flags[@]}" "$@" || failed="$failed integration_v2" # integration_cluster_proxy run_for_module "tests" go_test "./integration/..." "parallel" "pkg_to_coverprofileflag integration_cluster_proxy" \ - -tags cluster_proxy -timeout=5m "${gocov_build_flags[@]}" || failed="$failed integration_cluster_proxy" + -tags cluster_proxy -timeout=30m "${gocov_build_flags[@]}" || failed="$failed integration_cluster_proxy" log_callout "[$(date)] Collecting coverage from e2e tests ..." # We don't pass 'gocov_build_flags' nor 'pkg_to_coverprofileflag' here, diff --git a/tests/framework/e2e/etcd_spawn.go b/tests/framework/e2e/etcd_spawn.go new file mode 100644 index 000000000..f8d1e472b --- /dev/null +++ b/tests/framework/e2e/etcd_spawn.go @@ -0,0 +1,24 @@ +// Copyright 2022 The etcd Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package e2e + +import ( + "go.etcd.io/etcd/pkg/v3/expect" + "go.uber.org/zap" +) + +func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, error) { + return SpawnCmdWithLogger(zap.NewNop(), args, envVars) +} diff --git a/tests/framework/e2e/etcd_spawn_cov.go b/tests/framework/e2e/etcd_spawn_cov.go index 7c4ff8c0f..9f27d9f83 100644 --- a/tests/framework/e2e/etcd_spawn_cov.go +++ b/tests/framework/e2e/etcd_spawn_cov.go @@ -36,13 +36,9 @@ var ( coverDir = integration.MustAbsPath(os.Getenv("COVERDIR")) ) -func SpawnCmd(args []string) (*expect.ExpectProcess, error) { - return SpawnCmdWithLogger(zap.NewNop(), args) -} - -func SpawnCmdWithLogger(lg *zap.Logger, args []string) (*expect.ExpectProcess, error) { +func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string) (*expect.ExpectProcess, error) { cmd := args[0] - env := make([]string, 0) + env := mergeEnvVariables(envVars) switch { case strings.HasSuffix(cmd, "/etcd"): cmd = cmd + "_test" @@ -66,7 +62,7 @@ func SpawnCmdWithLogger(lg *zap.Logger, args []string) (*expect.ExpectProcess, e } // when withFlagByEnv() is used in testCtl(), env variables for ctl is set to os.env. // they must be included in ctl_cov_env. - env = append(env, os.Environ()...) + all_args := append(args[1:], covArgs...) lg.Info("spawning process", zap.Strings("args", all_args), zap.String("working-dir", wd)) ep, err := expect.NewExpectWithEnv(cmd, all_args, env) diff --git a/tests/framework/e2e/etcd_spawn_nocov.go b/tests/framework/e2e/etcd_spawn_nocov.go index a9343ccea..6df08539d 100644 --- a/tests/framework/e2e/etcd_spawn_nocov.go +++ b/tests/framework/e2e/etcd_spawn_nocov.go @@ -18,7 +18,6 @@ package e2e import ( - "fmt" "os" "strings" @@ -28,10 +27,6 @@ import ( const noOutputLineCount = 0 // regular binaries emit no extra lines -func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, error) { - return SpawnCmdWithLogger(zap.NewNop(), args, envVars) -} - func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string) (*expect.ExpectProcess, error) { wd, err := os.Getwd() if err != nil { @@ -46,23 +41,3 @@ func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string lg.Info("spawning process", zap.Strings("args", args), zap.String("working-dir", wd), zap.Strings("environment-variables", env)) return expect.NewExpectWithEnv(args[0], args[1:], env) } - -func mergeEnvVariables(envVars map[string]string) []string { - var env []string - // Environment variables are passed as parameter have higher priority - // than os environment variables. - for k, v := range envVars { - env = append(env, fmt.Sprintf("%s=%s", k, v)) - } - - // Now, we can set os environment variables not passed as parameter. - currVars := os.Environ() - for _, v := range currVars { - p := strings.Split(v, "=") - if _, ok := envVars[p[0]]; !ok { - env = append(env, fmt.Sprintf("%s=%s", p[0], p[1])) - } - } - - return env -} diff --git a/tests/framework/e2e/util.go b/tests/framework/e2e/util.go index 5d66ba4cb..8ea76ee40 100644 --- a/tests/framework/e2e/util.go +++ b/tests/framework/e2e/util.go @@ -18,6 +18,7 @@ import ( "encoding/json" "fmt" "math/rand" + "os" "strings" "testing" "time" @@ -131,3 +132,23 @@ func ExecuteWithTimeout(t *testing.T, timeout time.Duration, f func()) { case <-donec: } } + +func mergeEnvVariables(envVars map[string]string) []string { + var env []string + // Environment variables are passed as parameter have higher priority + // than os environment variables. + for k, v := range envVars { + env = append(env, fmt.Sprintf("%s=%s", k, v)) + } + + // Now, we can set os environment variables not passed as parameter. + currVars := os.Environ() + for _, v := range currVars { + p := strings.Split(v, "=") + if _, ok := envVars[p[0]]; !ok { + env = append(env, fmt.Sprintf("%s=%s", p[0], p[1])) + } + } + + return env +}