Skip to content

Commit

Permalink
Add golangci-lint cache (#4433)
Browse files Browse the repository at this point in the history
* Add golangci-lint cache in CI and locally

* Use year and week number for cache key
  • Loading branch information
carles-grafana authored Dec 11, 2024
1 parent 5d9e8a0 commit 7117de4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,20 @@ jobs:
- name: check-jsonnetfmt
run: make check-jsonnetfmt

- name: Get year and week number
id: get-year-week-number
run: echo "date=$(date +"%Yweek%U")" >> $GITHUB_OUTPUT

- name: cache golangci
uses: actions/cache@v4
with:
path: .cache/golangci-lint
key: golangci-lint-${{ runner.os }}-${{ steps.get-year-week-number.outputs.date }}-${{ hashFiles('go.mod', '.golangci.yml') }}

- name: lint
run: make lint base=origin/${{github.base_ref}}
run: |
make lint base=origin/${{github.base_ref}}
sudo chown -R $(id -u):$(id -g) .cache/golangci-lint # needed to archive cache
unit-tests:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ integration/e2e/deployments/e2e_integration_test[0-9]*
.tempo.yaml
/tmp
gh-token.txt
.cache
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ check-jsonnetfmt: jsonnetfmt
.PHONY: lint
lint: # linting
ifneq ($(base),)
$(TOOLS_CMD) $(LINT) run --config .golangci.yml --new-from-rev=$(base)
$(LINT_CMD) $(LINT) run --config .golangci.yml --new-from-rev=$(base)
else
$(TOOLS_CMD) $(LINT) run --config .golangci.yml
$(LINT_CMD) $(LINT) run --config .golangci.yml
endif

##@ Docker Images
Expand Down
1 change: 1 addition & 0 deletions build/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TOOLS_IMAGE_TAG ?= main-e87b8d4
GOTOOLS ?= $(shell cd $(TOOL_DIR) && go list -e -f '{{ .Imports }}' -tags tools |tr -d '[]')

TOOLS_CMD = docker run --rm -t -v ${PWD}:/tools $(TOOLS_IMAGE):$(TOOLS_IMAGE_TAG)
LINT_CMD = docker run --rm -t -v ${PWD}:/tools -v ${PWD}/.cache/golangci-lint:/root/.cache/golangci-lint $(TOOLS_IMAGE):$(TOOLS_IMAGE_TAG)

.PHONY: tools-image-build
tools-image-build:
Expand Down

0 comments on commit 7117de4

Please sign in to comment.