From 43b9b338de2ba6aecf3cc95e830fa218a5fbfe71 Mon Sep 17 00:00:00 2001 From: Loong Dai Date: Tue, 28 Jun 2022 09:05:04 +0800 Subject: [PATCH 1/3] Optimize make Signed-off-by: Loong Dai --- .github/workflows/build_and_test.yaml | 2 +- .gitignore | 1 + Makefile.targets.mk | 24 +++++++++++++----------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index e05331829f..1b78aa5239 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -42,7 +42,7 @@ jobs: version: v1.46.2 args: --build-tags=e2e - name: Build - run: make build-all + run: make build - name: Test and report coverage run: go test ./... -race -coverprofile=coverage.xml -covermode=atomic - name: Upload coverage to Codecov diff --git a/.gitignore b/.gitignore index 5ed1a0c03d..80441fb447 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ **/.DS_Store bin/ +coverage.xml diff --git a/Makefile.targets.mk b/Makefile.targets.mk index 8328ecbfcf..7785bef62c 100644 --- a/Makefile.targets.mk +++ b/Makefile.targets.mk @@ -48,24 +48,26 @@ help: ## Display this help ##@ Build -.PHONY: build -build: ## Build the envoy-gateway binary - @CGO_ENABLED=0 go build -a -o ./bin/${GOOS}/${GOARCH}/ github.com/envoyproxy/gateway/cmd/envoy-gateway +SUPPORT_ARCHS ?= amd64 arm64 +# Generate three targets: build-amd64, build-arm64 +# Run make build -n to see the result with dry run. +BUILD_BINARY_ARCHS = $(addprefix build-,$(SUPPORT_ARCHS)) -build-linux-amd64: - @GOOS=linux GOARCH=amd64 $(MAKE) build +.PHONY: build $(BUILD_BINARY_ARCHS) +build: $(BUILD_BINARY_ARCHS) ## Build the envoy-gateway binary. +$(BUILD_BINARY_ARCHS): build-%: + @CGO_ENABLED=0 GOOS=linux GOARCH="$*" go build -a -o ./bin/${GOOS}/${GOARCH}/ github.com/envoyproxy/gateway/cmd/envoy-gateway -build-linux-arm64: - @GOOS=linux GOARCH=arm64 $(MAKE) build - -build-all: build-linux-amd64 build-linux-arm64 +.PHONY: clean +clean: + @rm -rf bin .PHONY: test test: - @go test ./... + @go test ./... -race -coverprofile=coverage.xml -covermode=atomic .PHONY: docker-build -docker-build: build-all ## Build the envoy-gateway docker image. +docker-build: build ## Build the envoy-gateway docker image. @DOCKER_BUILDKIT=1 docker build -t $(IMAGE):$(TAG) -f Dockerfile bin .PHONY: docker-push From fda42946098f85f999390fb886d3e8a732123e53 Mon Sep 17 00:00:00 2001 From: Loong Dai Date: Tue, 28 Jun 2022 10:41:51 +0800 Subject: [PATCH 2/3] sync with make Signed-off-by: Loong Dai --- .github/workflows/build_and_test.yaml | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 1b78aa5239..a8d3cc3ea7 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -25,26 +25,19 @@ jobs: run: | MAKE_IN_DOCKER=1 make lint-yamllint - name: Run Codespell - uses: codespell-project/actions-codespell@master - with: - # can't reuse tools/codespell/.codespell.skip, shell is not supported - skip: .git,*.png,*.woff,*.woff2,*.eot,*.ttf,*.jpg,*.ico,*.svg,go.mod,go.sum - ignore_words_file: 'tools/codespell/.codespell.ignorewords' - check_filenames: true - check_hidden: true + run: | + MAKE_IN_DOCKER=1 make lint-codespell + - name: Run Golangci-lint + run: | + MAKE_IN_DOCKER=1 make lint-golint - uses: actions/setup-go@v3 with: go-version: ${{ env.GO_VERSION }} cache: true - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: v1.46.2 - args: --build-tags=e2e - name: Build run: make build - name: Test and report coverage - run: go test ./... -race -coverprofile=coverage.xml -covermode=atomic + run: make test - name: Upload coverage to Codecov uses: codecov/codecov-action@v2 with: From 251e5681105e0825dfe191d620dda03384b01327 Mon Sep 17 00:00:00 2001 From: Loong Dai Date: Wed, 29 Jun 2022 08:28:27 +0800 Subject: [PATCH 3/3] feedback Signed-off-by: Loong Dai --- Makefile.targets.mk | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile.targets.mk b/Makefile.targets.mk index 7785bef62c..4af22a8c7c 100644 --- a/Makefile.targets.mk +++ b/Makefile.targets.mk @@ -49,17 +49,21 @@ help: ## Display this help ##@ Build SUPPORT_ARCHS ?= amd64 arm64 -# Generate three targets: build-amd64, build-arm64 +SUPPORT_PLATFORM ?= linux darwin +# Generate three targets: build-${PLATFORM}-${ARCH} # Run make build -n to see the result with dry run. -BUILD_BINARY_ARCHS = $(addprefix build-,$(SUPPORT_ARCHS)) +BUILD_BINARY_ARCHS = $(foreach TMP, $(SUPPORT_PLATFORM),$(addprefix build-$(TMP)-, $(SUPPORT_ARCHS))) + +# split by dash, $1 means index which starts from 1, $2 means the whole word +word-dash = $(word $2,$(subst -, ,$1)) .PHONY: build $(BUILD_BINARY_ARCHS) build: $(BUILD_BINARY_ARCHS) ## Build the envoy-gateway binary. $(BUILD_BINARY_ARCHS): build-%: - @CGO_ENABLED=0 GOOS=linux GOARCH="$*" go build -a -o ./bin/${GOOS}/${GOARCH}/ github.com/envoyproxy/gateway/cmd/envoy-gateway + @CGO_ENABLED=0 GOOS="$(call word-dash,$*,1)" GOARCH="$(call word-dash,$*,2)" go build -a -o ./bin/${GOOS}/${GOARCH}/ github.com/envoyproxy/gateway/cmd/envoy-gateway .PHONY: clean -clean: +clean: ## Clean the build output directory. @rm -rf bin .PHONY: test