Skip to content

Commit

Permalink
use go 1.20 -cover support
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Mar 10, 2023
1 parent 6a0398d commit 85ddfde
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ jobs:
name: Build
uses: docker/bake-action@v2
with:
targets: binary
targets: binary-with-coverage
set: |
*.cache-from=type=gha,scope=binary-linux-amd64
*.cache-from=type=gha,scope=binary-e2e-${{ matrix.mode }}
Expand All @@ -177,9 +177,6 @@ jobs:
if: ${{ matrix.mode == 'plugin' }}
run: |
make e2e-compose
-
name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
-
name: Test standalone mode
if: ${{ matrix.mode == 'standalone' }}
Expand All @@ -192,6 +189,9 @@ jobs:
if: ${{ matrix.mode == 'cucumber'}}
run: |
make test-cucumber
-
name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

release:
permissions:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bin/
/.vscode/
coverage.out
covdatafiles/
.DS_Store
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ EOT

FROM build-base AS build
ARG BUILD_TAGS
ARG BUILD_FLAGS
ARG TARGETPLATFORM
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache \
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ifneq ($(DETECTED_OS),Windows)
# https://github.com/golang/go/issues/27089
TEST_COVERAGE_FLAGS += -race
endif
BUILD_FLAGS?=
TEST_FLAGS?=
E2E_TEST?=
ifeq ($(E2E_TEST),)
Expand All @@ -53,20 +54,27 @@ all: build

.PHONY: build ## Build the compose cli-plugin
build:
GO111MODULE=on go build -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose$(BINARY_EXT)" ./cmd
GO111MODULE=on go build $(BUILD_FLAGS) -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose$(BINARY_EXT)" ./cmd

.PHONY: binary
binary:
$(BUILDX_CMD) bake binary

.PHONY: binary-with-coverage
binary-with-coverage:
$(BUILDX_CMD) bake binary-with-coverage

.PHONY: install
install: binary
mkdir -p ~/.docker/cli-plugins
install bin/build/docker-compose ~/.docker/cli-plugins/docker-compose

.PHONY: e2e-compose
e2e-compose: ## Run end to end local tests in plugin mode. Set E2E_TEST=TestName to run a single test
go test $(TEST_FLAGS) $(TEST_COVERAGE_FLAGS) -count=1 ./pkg/e2e
rm -rf covdatafiles
mkdir covdatafiles
GOCOVERDIR=covdatafiles go test $(TEST_FLAGS) -count=1 ./pkg/e2e
go tool covdata textfmt -i=covdatafiles -o=coverage.out

.PHONY: e2e-compose-standalone
e2e-compose-standalone: ## Run End to end local tests in standalone mode. Set E2E_TEST=TestName to run a single test
Expand Down
10 changes: 10 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ target "test" {
output = [bindir("coverage")]
}

target "binary-with-coverage" {
inherits = ["_common"]
target = "binary"
args = {
BUILD_FLAGS = "-cover"
}
output = [bindir("build")]
platforms = ["local"]
}

target "binary" {
inherits = ["_common"]
target = "binary"
Expand Down
9 changes: 8 additions & 1 deletion pkg/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,19 @@ func CopyFile(t testing.TB, sourceFile string, destinationFile string) {
// BaseEnvironment provides the minimal environment variables used across all
// Docker / Compose commands.
func (c *CLI) BaseEnvironment() []string {
return []string{
env := []string{
"HOME=" + c.HomeDir,
"USER=" + os.Getenv("USER"),
"DOCKER_CONFIG=" + c.ConfigDir,
"KUBECONFIG=invalid",
}
if coverdir, ok := os.LookupEnv("GOCOVERDIR"); ok {
_, filename, _, _ := runtime.Caller(0)
root := filepath.Join(filepath.Dir(filename), "..", "..")
coverdir = filepath.Join(root, coverdir)
env = append(env, fmt.Sprintf("GOCOVERDIR=%s", coverdir))
}
return env
}

// NewCmd creates a cmd object configured with the test environment set
Expand Down

0 comments on commit 85ddfde

Please sign in to comment.