Skip to content

Commit

Permalink
[to #67] clean Makefile (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason authored Mar 31, 2022
1 parent 69ddf53 commit 39029ef
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 104 deletions.
38 changes: 23 additions & 15 deletions .github/workflows/ci-br.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,51 @@ permissions:
contents: read

jobs:
br-ut:
br-check-tidy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.16.1'
- name: ut
- name: make check/tidy
shell: bash
run: |
cd br
make unit_test_in_verify_ci
br-golangci-lint:
make check/tidy
br-check-golangci-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.16.1'
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
- name: make check/golangci-lint
shell: bash
run: |
cd br
make check/golangci-lint
br-check-gosec:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
version: v1.42.0
working-directory: br
args: -v $(go list ./...| grep "github.com\/tikv\/migration\/br" | sed 's|github.com/tikv/migration/br/||') --config ../.golangci.yml --allow-parallel-runners --timeout=10m
br-gosec:
go-version: '1.16.1'
- name: make check/gosec
shell: bash
run: |
cd br
make check/gosec
br-test:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.16.1'
- name: gosec
- name: make test
shell: bash
run: |
go install github.com/securego/gosec/v2/cmd/[email protected]
cd br
gosec -fmt=junit-xml -out=results.xml -stdout -verbose=text -exclude=G103,G104,G204,G304,G307,G401,G404,G501,G505,G601 ./...
make test
133 changes: 44 additions & 89 deletions br/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,114 +12,69 @@
# See the License for the specific language governing permissions and
# limitations under the License.

PROJECT=br
GOPATH ?= $(shell go env GOPATH)
P=8
.PHONY: check test build clean
default: build
all: check test build clean

# Ensure GOPATH is set before running build process.
ifeq "$(GOPATH)" ""
$(error Please set the environment variable GOPATH before running `make`)
endif
FAIL_ON_STDOUT := awk '{ print } END { if (NR > 0) { exit 1 } }'
# golang
GO := GO111MODULE=on go
PACKAGES := go list ./...
DIRECTORIES := $(PACKAGES) | sed 's|github.com/tikv/migration/br/||'

CURDIR := $(shell pwd)
path_to_add := $(addsuffix /bin,$(subst :,/bin:,$(GOPATH))):$(PWD)/tools/bin
export PATH := $(path_to_add):$(PATH)

GO := GO111MODULE=on go
GOBUILD := $(GO) build $(BUILD_FLAG) -tags codes
GOTEST := $(GO) test -p $(P)
OVERALLS := GO111MODULE=on overalls
STATICCHECK := GO111MODULE=on staticcheck

LINUX := "Linux"
MAC := "Darwin"

FAILPOINT_ENABLE := find $$PWD/ -type d | grep -vE "(\.git|tools)" | xargs tools/bin/failpoint-ctl enable
FAILPOINT_DISABLE := find $$PWD/ -type d | grep -vE "(\.git|tools)" | xargs tools/bin/failpoint-ctl disable

TARGET = ""

RACE_FLAG =
ifeq ("$(WITH_RACE)", "1")
RACE_FLAG = -race
GOBUILD = GOPATH=$(GOPATH) $(GO) build
endif

CHECK_FLAG =
ifeq ("$(WITH_CHECK)", "1")
CHECK_FLAG = $(TEST_LDFLAGS)
endif

BR_PKG := github.com/tikv/migration/br
BR_PACKAGES := go list ./...| grep "github.com\/tikv\/migration\/br"
BR_PACKAGE_DIRECTORIES := $(BR_PACKAGES) | sed 's|github.com/tikv/migration/br/||'
BR_BIN := bin/br
TEST_DIR := /tmp/backup_restore_test

TEST_COVERAGE_DIR := "."

.PHONY: build_br clean unit_test check check-static

default: build_br

failpoint-enable: tools/bin/failpoint-ctl
# Converting gofail failpoints...
@$(FAILPOINT_ENABLE)

failpoint-disable: tools/bin/failpoint-ctl
# Restoring gofail failpoints...
@$(FAILPOINT_DISABLE)

tools/bin/failpoint-ctl: tools/check/go.mod
cd tools/check; \
$(GO) build -o ../bin/failpoint-ctl github.com/pingcap/failpoint/failpoint-ctl
# test
COVERAGE_DIR := build
TEST_PARALLEL = 8

LDFLAGS += -X "github.com/tikv/migration/br/pkg/version/build.ReleaseVersion=$(shell git describe --tags --dirty --always)"
LDFLAGS += -X "github.com/tikv/migration/br/pkg/version/build.BuildTS=$(shell date -u '+%Y-%m-%d %H:%M:%S')"
LDFLAGS += -X "github.com/tikv/migration/br/pkg/version/build.GitHash=$(shell git rev-parse HEAD)"
LDFLAGS += -X "github.com/tikv/migration/br/pkg/version/build.GitBranch=$(shell git rev-parse --abbrev-ref HEAD)"

build_br:
CGO_ENABLED=1 $(GOBUILD) $(RACE_FLAG) -ldflags '$(LDFLAGS) $(CHECK_FLAG)' -o $(BR_BIN) cmd/br/*.go
check: check/tidy check/golangci-lint check/gosec

test: unit_test
check/tidy:
cp go.sum /tmp/go.sum.origin
$(GO) mod tidy
diff -q go.sum /tmp/go.sum.origin

unit_test: export ARGS=$$($(BR_PACKAGES))
unit_test:
@make failpoint-enable
@export TZ='Asia/Shanghai';
$(GOTEST) $(RACE_FLAG) -ldflags '$(LDFLAGS)' -tags leak $(ARGS) -coverprofile=coverage.txt || ( make failpoint-disable && exit 1 )
@make failpoint-disable
unit_test_in_verify_ci: export ARGS=$$($(BR_PACKAGES))
unit_test_in_verify_ci: tools/bin/gotestsum tools/bin/gocov tools/bin/gocov-xml
@make failpoint-enable
@export TZ='Asia/Shanghai';
@mkdir -p $(TEST_COVERAGE_DIR)
CGO_ENABLED=1 tools/bin/gotestsum --junitfile "$(TEST_COVERAGE_DIR)/br-junit-report.xml" -- $(RACE_FLAG) -ldflags '$(LDFLAGS)' \
-tags leak $(ARGS) -coverprofile="$(TEST_COVERAGE_DIR)/br_cov.unit_test.plain" || ( make failpoint-disable && exit 1 )
tools/bin/gocov convert "$(TEST_COVERAGE_DIR)/br_cov.unit_test.plain" | tools/bin/gocov-xml > "$(TEST_COVERAGE_DIR)/br_cov.unit_test.out"
@make failpoint-disable
check/golangci-lint: tools/bin/golangci-lint
GO111MODULE=on CGO_ENABLED=0 tools/bin/golangci-lint run -v $$($(DIRECTORIES)) --config ../.golangci.yml --timeout 5m

check: check-static
check/gosec:
$(GO) install github.com/securego/gosec/v2/cmd/[email protected]
gosec -fmt=junit-xml -out=results.xml -stdout -verbose=text -exclude=G103,G104,G204,G304,G307,G401,G404,G501,G505,G601 ./...

check-static: tools/bin/golangci-lint
GO111MODULE=on CGO_ENABLED=0 tools/bin/golangci-lint run -v $$($(BR_PACKAGE_DIRECTORIES)) --config ../.golangci.yml --timeout 5m
test: tools/bin/gocov tools/bin/gocov-xml
make failpoint/enable
export TZ='Asia/Shanghai';
mkdir -p $(COVERAGE_DIR)
$(GO) test -p $(TEST_PARALLEL) -race -ldflags '$(LDFLAGS)' -tags leak $$($(PACKAGES)) -coverprofile=$(COVERAGE_DIR)/coverage.raw || ( make failpoint/disable && exit 1 )
tools/bin/gocov convert $(COVERAGE_DIR)/coverage.raw | tools/bin/gocov-xml > $(COVERAGE_DIR)/coverage.xml
make failpoint/disable

tools/bin/golangci-lint:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b ./tools/bin v1.41.1
failpoint/enable: tools/bin/failpoint-ctl
find `pwd` -type d | grep -vE "(\.git|tools)" | xargs tools/bin/failpoint-ctl enable

tools/bin/gotestsum: tools/check/go.mod
cd tools/check && $(GO) build -o ../bin/gotestsum gotest.tools/gotestsum
failpoint/disable: tools/bin/failpoint-ctl
find `pwd` -type d | grep -vE "(\.git|tools)" | xargs tools/bin/failpoint-ctl disable

tools/bin/golangci-lint:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./tools/bin v1.41.1

tools/bin/gocov: tools/check/go.mod
cd tools/check && $(GO) build -mod=mod -o ../bin/gocov github.com/axw/gocov/gocov
cd tools/check && $(GO) build -mod=mod -o ../bin/gocov github.com/axw/gocov/gocov

tools/bin/gocov-xml: tools/check/go.mod
cd tools/check && $(GO) build -mod=mod -o ../bin/gocov-xml github.com/AlekSi/gocov-xml

tools/bin/failpoint-ctl: tools/check/go.mod
cd tools/check && $(GO) build -o ../bin/failpoint-ctl github.com/pingcap/failpoint/failpoint-ctl

build:
CGO_ENABLED=1 $(GO) build -tags codes -ldflags '$(LDFLAGS)' -o bin/br cmd/br/*.go

clean:
go clean -i ./...
rm -rf *.out
rm -rf bin
rm -rf tools/bin
rm -rf *.out bin tools/bin
rm -rf results.xml
rm -rf br-junit-report.xml $(COVERAGE_DIR)/coverage.raw $(COVERAGE_DIR)/coverage.xml

0 comments on commit 39029ef

Please sign in to comment.