diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2b65a6f6c..3bcfd9d42 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,7 +29,7 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: yarn - cache-dependency-path: ui/yarn.lock + cache-dependency-path: "**/yarn.lock" - name: set env vars run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH @@ -47,7 +47,7 @@ jobs: - name: integration tests run: | (cd ./integration/clusters/${{matrix.deployment}}-${{matrix.authenticate-flow}} && docker compose logs -f &) - go test -v ./integration/... + go test -tags integration -v ./integration/... build: strategy: diff --git a/Makefile b/Makefile index 0c44281b0..21c1598a4 100644 --- a/Makefile +++ b/Makefile @@ -6,34 +6,36 @@ PKG := github.com/pomerium/pomerium BUILDDIR := ${PREFIX}/dist BINDIR := ${PREFIX}/bin -GO111MODULE=on -CGO_ENABLED := 0 export GOEXPERIMENT=synctest # Set any default go build tags BUILDTAGS := # Populate version variables # Add to compile time flags -VERSION?= $(shell git describe --tags) +VERSION ?= $(shell git describe --tags) GITCOMMIT := $(shell git rev-parse --short HEAD) -BUILDMETA:= +BUILDMETA := GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no) ifneq ($(GITUNTRACKEDCHANGES),) BUILDMETA := dirty endif -CTIMEVAR=-X $(PKG)/internal/version.GitCommit=$(GITCOMMIT) \ +CTIMEVAR = \ + -X $(PKG)/internal/version.GitCommit=$(GITCOMMIT) \ -X $(PKG)/internal/version.Version=$(VERSION) \ -X $(PKG)/internal/version.BuildMeta=$(BUILDMETA) \ -X $(PKG)/internal/version.ProjectName=$(NAME) \ -X $(PKG)/internal/version.ProjectURL=$(PKG) GO ?= "go" -GO_LDFLAGS=-ldflags "-s -w $(CTIMEVAR)" -GOOSARCHES = linux/amd64 darwin/amd64 windows/amd64 +GO_LDFLAGS = -ldflags "-s -w $(CTIMEVAR)" GOOS = $(shell $(GO) env GOOS) -GOARCH= $(shell $(GO) env GOARCH) -GETENVOY_VERSION = v0.2.0 +GOARCH = $(shell $(GO) env GOARCH) GORELEASER_VERSION = v0.174.2 +GO_TESTFLAGS := -race +# disable the race detector in macos +ifeq ($(shell env -u GOOS $(GO) env GOOS), darwin) + GO_TESTFLAGS := +endif .PHONY: all all: clean build-deps test lint build ## Runs a clean, build, fmt, lint, test, and vet. @@ -41,7 +43,7 @@ all: clean build-deps test lint build ## Runs a clean, build, fmt, lint, test, a .PHONY: get-envoy get-envoy: ## Fetch envoy binaries @echo "==> $@" - @cd pkg/envoy/files && env -u GOOS go run ../get-envoy + @cd pkg/envoy/files && env -u GOOS $(GO) run ../get-envoy .PHONY: deps-build deps-build: get-envoy ## Install build dependencies @@ -50,17 +52,12 @@ deps-build: get-envoy ## Install build dependencies .PHONY: deps-release deps-release: get-envoy ## Install release dependencies @echo "==> $@" - @cd /tmp; GO111MODULE=on $(GO) install github.com/goreleaser/goreleaser@${GORELEASER_VERSION} + @cd /tmp; $(GO) install github.com/goreleaser/goreleaser@${GORELEASER_VERSION} .PHONY: build-deps build-deps: deps-build deps-release @echo "==> $@" -.PHONY: tag -tag: ## Create a new git tag to prepare to build a release - git tag -sa $(VERSION) -m "$(VERSION)" - @echo "Run git push origin $(VERSION) to push your new tag to GitHub." - .PHONY: proto proto: @echo "==> $@" @@ -78,12 +75,12 @@ build: build-ui build-go .PHONY: build-debug build-debug: build-deps ## Builds binaries appropriate for debugging @echo "==> $@" - @CGO_ENABLED=0 GO111MODULE=on $(GO) build -gcflags="all=-N -l" -o $(BINDIR)/$(NAME) ./cmd/"$(NAME)" + @CGO_ENABLED=0 $(GO) build -gcflags="all=-N -l" -o $(BINDIR)/$(NAME) ./cmd/"$(NAME)" .PHONY: build-go build-go: build-deps @echo "==> $@" - @CGO_ENABLED=0 GO111MODULE=on $(GO) build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(BINDIR)/$(NAME) ./cmd/"$(NAME)" + @CGO_ENABLED=0 $(GO) build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(BINDIR)/$(NAME) ./cmd/"$(NAME)" .PHONY: build-ui build-ui: yarn @@ -94,17 +91,17 @@ build-ui: yarn lint: @echo "@==> $@" @VERSION=$$(go run github.com/mikefarah/yq/v4@v4.34.1 '.jobs.lint.steps[] | select(.uses == "golangci/golangci-lint-action*") | .with.version' .github/workflows/lint.yaml) && \ - go run github.com/golangci/golangci-lint/cmd/golangci-lint@$$VERSION run ./... --fix + $(GO) run github.com/golangci/golangci-lint/cmd/golangci-lint@$$VERSION run ./... --fix .PHONY: test test: get-envoy ## Runs the go tests. @echo "==> $@" - @$(GO) test -race -tags "$(BUILDTAGS)" $(shell $(GO) list ./... | grep -v vendor | grep -v github.com/pomerium/pomerium/integration) + $(GO) test $(GO_TESTFLAGS) -tags "$(BUILDTAGS)" ./... .PHONY: cover cover: get-envoy ## Runs go test with coverage @echo "==> $@" - $(GO) test -race -coverprofile=coverage.txt -tags "$(BUILDTAGS)" $(shell $(GO) list ./... | grep -v vendor | grep -v github.com/pomerium/pomerium/integration) + $(GO) test $(GO_TESTFLAGS) -tags "$(BUILDTAGS)" -coverprofile=coverage.txt ./... @sed -i.bak '/\.pb\.go\:/d' coverage.txt @sed -i.bak '/\/mock\.go\:/d' coverage.txt @sort -o coverage.txt coverage.txt @@ -127,7 +124,7 @@ snapshot: build-deps ## Builds the cross-compiled binaries, naming them in such .PHONY: yarn yarn: @echo "==> $@" - cd ui ; yarn install --network-timeout 120000 + cd ui ; yarn install --network-timeout 120000 --frozen-lockfile .PHONY: help help: diff --git a/integration/authentication_test.go b/integration/authentication_test.go index e9863549c..44ae7afff 100644 --- a/integration/authentication_test.go +++ b/integration/authentication_test.go @@ -1,3 +1,5 @@ +//go:build integration + package main import ( diff --git a/integration/authorization_test.go b/integration/authorization_test.go index 67c1dc0b8..1e64e151c 100644 --- a/integration/authorization_test.go +++ b/integration/authorization_test.go @@ -1,3 +1,5 @@ +//go:build integration + package main import ( diff --git a/integration/benchmark_test.go b/integration/benchmark_test.go index 517a8122a..f32941621 100644 --- a/integration/benchmark_test.go +++ b/integration/benchmark_test.go @@ -1,3 +1,5 @@ +//go:build integration + package main import ( diff --git a/integration/control_plane_test.go b/integration/control_plane_test.go index fb55a4910..f581d07fe 100644 --- a/integration/control_plane_test.go +++ b/integration/control_plane_test.go @@ -1,3 +1,5 @@ +//go:build integration + package main import ( diff --git a/integration/main_test.go b/integration/main_test.go index 3a3624b4b..09cf2ffef 100644 --- a/integration/main_test.go +++ b/integration/main_test.go @@ -1,3 +1,5 @@ +//go:build integration + // Package main contains the pomerium integration tests package main diff --git a/integration/policy_test.go b/integration/policy_test.go index cdbb40943..7f8416fbe 100644 --- a/integration/policy_test.go +++ b/integration/policy_test.go @@ -1,3 +1,5 @@ +//go:build integration + package main import ( diff --git a/internal/testenv/environment.go b/internal/testenv/environment.go index e59abd640..3a9d70a9d 100644 --- a/internal/testenv/environment.go +++ b/internal/testenv/environment.go @@ -366,7 +366,7 @@ func New(t testing.TB, opts ...EnvironmentOption) Environment { workspaceFolder, err := os.Getwd() require.NoError(t, err) for { - if _, err := os.Stat(filepath.Join(workspaceFolder, ".git")); err == nil { + if _, err := os.Stat(filepath.Join(workspaceFolder, "go.mod")); err == nil { break } workspaceFolder = filepath.Dir(workspaceFolder) diff --git a/pkg/storage/postgres/backend_test.go b/pkg/storage/postgres/backend_test.go index a05ce43f5..70a12b89d 100644 --- a/pkg/storage/postgres/backend_test.go +++ b/pkg/storage/postgres/backend_test.go @@ -48,9 +48,6 @@ func TestBackend(t *testing.T) { stream.Close() } }) - - assert.Equal(t, int32(0), backend.pool.Stat().AcquiredConns(), - "acquired connections should be released") }) }