From c7f6a6d4bb27b9cf85e19d3d65a1c06a7675a09c Mon Sep 17 00:00:00 2001 From: spacewander Date: Tue, 28 Nov 2023 21:50:08 +0800 Subject: [PATCH] ci: enable cache for tools We can't cache image as the free storage from GitHub is too small. Signed-off-by: spacewander --- .github/workflows/labeler.yml | 30 ++++++++++++++++-------------- .github/workflows/lint.yml | 11 +++++++++++ .github/workflows/test.yml | 13 +++++++++++++ .golangci.yml | 2 +- Makefile | 24 ++++++++++++++++-------- 5 files changed, 57 insertions(+), 23 deletions(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index dfde5dac8..6c2c712a9 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -1,15 +1,17 @@ -name: "pull request labeler" -on: -- pull_request_target +# Disable this workflow for now until this repo is open source and GitHub doesn't charge us for CI -jobs: - triage: - permissions: - contents: read - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/labeler@v4 - with: - dot: true +#name: "pull request labeler" +#on: +#- pull_request_target + +#jobs: + #triage: + #permissions: + #contents: read + #pull-requests: write + #runs-on: ubuntu-latest + #steps: + #- uses: actions/checkout@v4 + #- uses: actions/labeler@v4 + #with: + #dot: true diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ca7110ac4..0ac5a126b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,8 +6,13 @@ on: pull_request: branches: [ "main" ] +concurrency: + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_number || github.ref }} + cancel-in-progress: true + jobs: build: + timeout-minutes: 10 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -15,6 +20,12 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 + - name: binary-cache + uses: actions/cache@v3 + with: + path: ./bin + key: ${{ runner.os }}-${{ hashFiles('./Makefile') }} + - name: format go run: | make fmt-go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 168835c72..51f0016c3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,11 +12,16 @@ on: - "./docs" - "**/*.md" +concurrency: + group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_number || github.ref }} + cancel-in-progress: true + env: IN_CI: true jobs: unit-test: + timeout-minutes: 10 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -33,6 +38,7 @@ jobs: run: make unit-test plugins-integration-test: + timeout-minutes: 10 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -60,6 +66,7 @@ jobs: path: ./test-envoy controller-test: + timeout-minutes: 10 runs-on: ubuntu-latest defaults: run: @@ -74,5 +81,11 @@ jobs: # working-directory doesn't affect the cache path cache-dependency-path: ./controller/go.sum + - name: binary cache + uses: actions/cache@v3 + with: + path: ./controller/bin + key: ${{ runner.os }}-${{ hashFiles('./controller/Makefile') }} + - name: Test run: make test diff --git a/.golangci.yml b/.golangci.yml index cd7cc67a4..e767d7983 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,5 @@ run: - deadline: 10m + deadline: 5m linters: enable: diff --git a/Makefile b/Makefile index 27e12d888..ca2e03471 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,10 @@ ifeq ($(IN_CI), true) MOUNT_GOMOD_CACHE = endif +LOCALBIN ?= $(shell pwd)/bin +$(LOCALBIN): + @mkdir -p $(LOCALBIN) + .PHONY: gen-proto gen-proto: build-dev-tools $(GO_TARGETS) # format the generated Go code so the `fmt-go` task can pass @@ -110,19 +114,22 @@ build-dev-tools: fi .PHONY: lint-go -lint-go: - go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run --config=.golangci.yml +lint-go: $(LOCALBIN) + test -x $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 + $(LOCALBIN)/golangci-lint run --config=.golangci.yml .PHONY: fmt-go -fmt-go: +fmt-go: $(LOCALBIN) go mod tidy - go run github.com/rinchsan/gosimports/cmd/gosimports@v0.3.8 -w -local ${PROJECT_NAME} . + test -x $(LOCALBIN)/gosimports || GOBIN=$(LOCALBIN) go install github.com/rinchsan/gosimports/cmd/gosimports@v0.3.8 + $(LOCALBIN)/gosimports -w -local ${PROJECT_NAME} . # Don't use `buf format` to format the protobuf files! Buf's code style is different from Envoy. # That will break lots of things. .PHONY: lint-proto -lint-proto: - go run github.com/bufbuild/buf/cmd/buf@v1.28.1 lint +lint-proto: $(LOCALBIN) + test -x $(LOCALBIN)/buf || GOBIN=$(LOCALBIN) go install github.com/bufbuild/buf/cmd/buf@v1.28.1 + $(LOCALBIN)/buf lint .PHONY: lint-spell lint-spell: build-dev-tools @@ -135,8 +142,9 @@ lint-spell-local: codespell --skip '.git,.idea,test-envoy,go.mod,go.sum,*.svg' --check-filenames --check-hidden --ignore-words ./.ignore_words .PHONY: lint-editorconfig -lint-editorconfig: - go run github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.2 +lint-editorconfig: $(LOCALBIN) + test -x $(LOCALBIN)/editorconfig-checker || GOBIN=$(LOCALBIN) go install github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.2 + $(LOCALBIN)/editorconfig-checker .PHONY: lint lint: lint-go lint-proto lint-spell lint-editorconfig