From 3d41b486caac0b177ac251ff5a4e3e7970646d72 Mon Sep 17 00:00:00 2001 From: Di Xu Date: Fri, 10 May 2024 15:12:18 +0800 Subject: [PATCH] add github action for linter Signed-off-by: Di Xu --- .github/workflows/ci.yml | 50 ++++++++++++++++++++++++++++++++++++++++ Makefile | 20 +++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..3a247531 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: CI +on: + merge_group: + pull_request: +jobs: + golangci: + name: pull-nauti-golang-ci + env: + GOPATH: ${{ github.workspace }} + GO111MODULE: on + defaults: + run: + working-directory: ${{ env.GOPATH }}/src/github.com/${{ github.repository }} + strategy: + max-parallel: 3 + ## this will contain a matrix of all of the combinations + ## we wish to test again: + matrix: + go-version: [ 1.21.x, 1.22.x ] + os: [ ubuntu-latest ] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 1 + path: ${{ env.GOPATH }}/src/github.com/${{ github.repository }} + - name: Cache go modules and build cache + uses: actions/cache@v4.0.1 + with: + # In order: + # * Module download cache + # * Build cache (Linux) + # * Build cache (Mac) + # * Build cache (Windows) + path: | + ${{ env.GOPATH }}/pkg/mod + ${{ env.GOPATH }}/pkg/sumdb + ~/.cache/go-build + ~/Library/Caches/go-build + # %LocalAppData%\go-build + key: ${{ matrix.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ matrix.os }}-go- + - name: Golang Lint + run: make lint diff --git a/Makefile b/Makefile index 699c26f7..743ea3ee 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ else GOBIN=$(shell go env GOBIN) endif -lint: +lint: golangci-lint golangci-lint run -c .golangci.yaml --timeout=10m ovnmaster: @@ -55,3 +55,21 @@ images: docker build -f ./build/ep-controller.Dockerfile ./ -t docker.io/airren/ep-controller:latest docker push docker.io/airren/dedinic:v1.13.0-debug docker push docker.io/airren/ep-controller:latest + +# find or download golangci-lint +# download golangci-lint if necessary +golangci-lint: +ifeq (, $(shell which golangci-lint)) + @{ \ + set -e ;\ + export GO111MODULE=on; \ + GOLANG_LINT_TMP_DIR=$$(mktemp -d) ;\ + cd $$GOLANG_LINT_TMP_DIR ;\ + go mod init tmp ;\ + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.2 ;\ + rm -rf $$GOLANG_LINT_TMP_DIR ;\ + } +GOLANG_LINT=$(shell go env GOPATH)/bin/golangci-lint +else +GOLANG_LINT=$(shell which golangci-lint) +endif