From 42262da9239d9eb81019efffa36ee277abe82f78 Mon Sep 17 00:00:00 2001 From: pika <759349196@qq.com> Date: Tue, 31 Mar 2026 18:31:38 +0800 Subject: [PATCH] add ci and unify build entrypoints --- .github/workflows/ci.yml | 42 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 2 +- Makefile | 26 +++++++++++++++++----- scripts/all_build.sh | 5 ++--- 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d97e8fb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI + +on: + push: + branches: + - "**" + tags-ignore: + - "v*" + pull_request: + +jobs: + verify: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Run tests + run: make test + + - name: Run go vet + run: make vet + + - name: Run race tests + run: make test-race + + - name: Run coverage + run: make cover + + - name: Build CLI + run: make build + + - name: Upload coverage profile + uses: actions/upload-artifact@v4 + with: + name: coverage-profile + path: coverage.out diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 43ff82e..62a0129 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: go-version-file: go.mod - name: Run tests - run: go test ./... + run: make test - name: Build release assets run: | diff --git a/Makefile b/Makefile index b7f7dcd..825e3a0 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,29 @@ -BIN := bin/cloudcanal +GO ?= go +BIN ?= bin/cloudcanal +PKG ?= ./... +TEST_PKG ?= ./test/... +COVER_PROFILE ?= coverage.out -.PHONY: build test clean +.PHONY: build test vet test-race cover ci clean build: mkdir -p $(dir $(BIN)) - go build -o $(BIN) ./cmd/cloudcanal + $(GO) build -o $(BIN) ./cmd/cloudcanal test: - go test ./... + $(GO) test $(PKG) + +vet: + $(GO) vet $(PKG) + +test-race: + $(GO) test -race $(TEST_PKG) + +cover: + $(GO) test -coverpkg=$(PKG) -coverprofile=$(COVER_PROFILE) $(TEST_PKG) + $(GO) tool cover -func=$(COVER_PROFILE) + +ci: test vet test-race cover build clean: - rm -rf $(dir $(BIN)) + rm -rf $(dir $(BIN)) $(COVER_PROFILE) diff --git a/scripts/all_build.sh b/scripts/all_build.sh index 9eee4de..39e44c3 100755 --- a/scripts/all_build.sh +++ b/scripts/all_build.sh @@ -53,11 +53,10 @@ else fi STEP_NO="2/3" -run_step "Run tests" "test" go test ./... +run_step "Run tests" "test" make test STEP_NO="3/3" -mkdir -p "$BIN_DIR" -run_step "Build CLI" "build" go build -o "$BIN_PATH" ./cmd/cloudcanal +run_step "Build CLI" "build" make build log_success "Binary ready at $BIN_PATH" print_run_summary "Build completed"