From ceb391c49ef2afbb264b3302e698431f5566c594 Mon Sep 17 00:00:00 2001 From: whg517 Date: Fri, 15 Nov 2024 18:59:43 +0800 Subject: [PATCH] refactor(ci): refactor gh action (#244) --- .github/workflows/ci.yml | 59 -------------------------------------- .github/workflows/lint.yml | 32 +++++++++++++++++++++ .github/workflows/test.yml | 23 +++++++++++++++ .golangci.yml | 3 ++ Makefile | 8 +----- 5 files changed, 59 insertions(+), 66 deletions(-) delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml create mode 100644 .golangci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index ff34d42..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: CI - -on: - workflow_dispatch: - push: - branches: - - main - tags: - - "*" - pull_request: - - -jobs: - markdown-lint: - name: markdown-lint - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Lint Code Base - uses: github/super-linter@v4 - env: - VALIDATE_MARKDOWN: true - VALIDATE_ALL_CODEBASE: false - DEFAULT_BRANCH: main - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - LINTER_RULES_PATH: / - MARKDOWN_CONFIG_FILE: .markdownlint.yml - - - golang-lint: - name: golang-lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - - name: golangci-lint - run: | - make lint - - - go-test: - name: Go Test - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - - name: Go Test - run: | - make test diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..3992ae1 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,32 @@ +name: Lint + +on: + push: + pull_request: + +jobs: + go-lint: + name: Go Lint + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '~1.23' + + - name: Run linter + uses: golangci/golangci-lint-action@v6 + with: + version: v1.62 + md-lint: + name: Markdown Lint + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Run markdownlint + uses: DavidAnson/markdownlint-cli2-action@v18 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f714ea7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: Tests + +on: + push: + pull_request: + +jobs: + go-test: + name: Go Test + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '~1.23' + + - name: Running Tests + run: | + go mod tidy + make test diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..f5ebd42 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,3 @@ +run: + timeout: 5m + allow-parallel-runners: true diff --git a/Makefile b/Makefile index 07022d3..80af9de 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ test: generate fmt vet envtest ## Run tests. .PHONY: lint lint: golangci-lint ## Run golangci-lint linter - $(GOLANGCI_LINT) run --timeout=5m + $(GOLANGCI_LINT) run .PHONY: lint-fix lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes @@ -102,9 +102,3 @@ $(ENVTEST): $(LOCALBIN) golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) - -.PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten. -$(CONTROLLER_GEN): $(LOCALBIN) - test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ - GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)