From 5f743fc68adb2163de20a74fc8c14bb7dcf1d4f0 Mon Sep 17 00:00:00 2001 From: alejandro Date: Mon, 9 Feb 2026 16:10:37 +0000 Subject: [PATCH 1/5] Added GithubActions and updated linter --- .github/workflows/build-lint-test.yaml | 96 ++++++++++++++++++++++++++ .golangci.yml | 36 +++++----- Makefile | 26 ++----- cloudbuild.yaml | 11 --- 4 files changed, 122 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/build-lint-test.yaml delete mode 100644 cloudbuild.yaml diff --git a/.github/workflows/build-lint-test.yaml b/.github/workflows/build-lint-test.yaml new file mode 100644 index 0000000..f3a7dcb --- /dev/null +++ b/.github/workflows/build-lint-test.yaml @@ -0,0 +1,96 @@ +name: Build, Lint, and Test + +on: + push: + pull_request: + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-file: go.mod + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: go mod download + + - name: Build + run: | + CGO_ENABLED=0 GOARCH=amd64 go build -v ./cmd/adapter + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-file: go.mod + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v2.8.0 + + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-file: go.mod + + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Download dependencies + run: go mod download + + - name: Run tests + run: | + CGO_ENABLED=0 go test -v -race -coverprofile=coverage.out ./cmd/... ./pkg/... + + - name: Upload coverage + uses: codecov/codecov-action@v4 + with: + files: ./coverage.out + flags: unittests + name: codecov-umbrella + continue-on-error: true \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 7c02cad..68cccb0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,21 +1,20 @@ +version: "2" + run: - deadline: 5m + timeout: 5m linters: - disable-all: true + default: none enable: - bodyclose - dogsled - dupl - errcheck - - exportloopref + - copyloopvar - gocritic - gocyclo - - gofmt - - goimports - gosec - goprintffuncname - - gosimple - govet - ineffassign - misspell @@ -23,17 +22,22 @@ linters: - nolintlint - revive - staticcheck - - stylecheck - - typecheck - unconvert - unused - whitespace -linters-settings: - goimports: - local-prefixes: github.com/thought-machine/prometheus-adapter - revive: - rules: - - name: exported - arguments: - - disableStutteringCheck + settings: + revive: + rules: + - name: exported + arguments: + - disableStutteringCheck + +formatters: + enable: + - gofmt + - goimports + settings: + goimports: + local-prefixes: + - github.com/thought-machine/prometheus-adapter diff --git a/Makefile b/Makefile index f343e6f..0976eab 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,14 @@ -REGISTRY?=gcr.io/k8s-staging-prometheus-adapter IMAGE=prometheus-adapter ARCH?=$(shell go env GOARCH) ALL_ARCH=amd64 arm arm64 ppc64le s390x -GOPATH:=$(shell go env GOPATH) +GOPATH := $(shell echo $(GOPATH) | cut -d: -f1) VERSION=$(shell cat VERSION) TAG_PREFIX=v TAG?=$(TAG_PREFIX)$(VERSION) -GO_VERSION?=1.22.5 -GOLANGCI_VERSION?=1.56.2 +GO_VERSION?=$(shell grep -E '^go [0-9.]+' go.mod | awk '{print $$2}') +GOLANGCI_VERSION?=2.8.0 .PHONY: all all: prometheus-adapter @@ -24,7 +23,7 @@ prometheus-adapter: $(SRC_DEPS) .PHONY: container container: - docker build -t $(REGISTRY)/$(IMAGE)-$(ARCH):$(TAG) --build-arg ARCH=$(ARCH) --build-arg GO_VERSION=$(GO_VERSION) . + docker build -t $(IMAGE)-$(ARCH):$(TAG) --build-arg ARCH=$(ARCH) --build-arg GO_VERSION=$(GO_VERSION) . # Container push # -------------- @@ -33,20 +32,7 @@ PUSH_ARCH_TARGETS=$(addprefix push-,$(ALL_ARCH)) .PHONY: push push: container - docker push $(REGISTRY)/$(IMAGE)-$(ARCH):$(TAG) - -push-all: $(PUSH_ARCH_TARGETS) push-multi-arch; - -.PHONY: $(PUSH_ARCH_TARGETS) -$(PUSH_ARCH_TARGETS): push-%: - ARCH=$* $(MAKE) push - -.PHONY: push-multi-arch -push-multi-arch: export DOCKER_CLI_EXPERIMENTAL = enabled -push-multi-arch: - docker manifest create --amend $(REGISTRY)/$(IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(REGISTRY)/$(IMAGE)\-&:$(TAG)~g") - @for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} $(REGISTRY)/$(IMAGE):$(TAG) $(REGISTRY)/$(IMAGE)-$${arch}:$(TAG); done - docker manifest push --purge $(REGISTRY)/$(IMAGE):$(TAG) + docker push $(IMAGE)-$(ARCH):$(TAG) # Test # ---- @@ -72,7 +58,7 @@ update: update-lint update-generated # Format and lint # --------------- -HAS_GOLANGCI_VERSION:=$(shell $(GOPATH)/bin/golangci-lint version --short) +HAS_GOLANGCI_VERSION:=$(shell $(GOPATH)/bin/golangci-lint version) .PHONY: golangci golangci: ifneq ($(HAS_GOLANGCI_VERSION), $(GOLANGCI_VERSION)) diff --git a/cloudbuild.yaml b/cloudbuild.yaml deleted file mode 100644 index 3d2c0d7..0000000 --- a/cloudbuild.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# See https://cloud.google.com/cloud-build/docs/build-config -timeout: 3600s -options: - substitution_option: ALLOW_LOOSE -steps: - - name: 'gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20211118-2f2d816b90' - entrypoint: make - env: - - TAG=$_PULL_BASE_REF - args: - - push-all From 5d4b650f110fd63ae622c28ef20280bfdf659238 Mon Sep 17 00:00:00 2001 From: alejandro Date: Tue, 10 Feb 2026 10:48:50 +0000 Subject: [PATCH 2/5] Removed codecov action --- .github/workflows/build-lint-test.yaml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/build-lint-test.yaml b/.github/workflows/build-lint-test.yaml index f3a7dcb..1b4aa13 100644 --- a/.github/workflows/build-lint-test.yaml +++ b/.github/workflows/build-lint-test.yaml @@ -85,12 +85,4 @@ jobs: - name: Run tests run: | - CGO_ENABLED=0 go test -v -race -coverprofile=coverage.out ./cmd/... ./pkg/... - - - name: Upload coverage - uses: codecov/codecov-action@v4 - with: - files: ./coverage.out - flags: unittests - name: codecov-umbrella - continue-on-error: true \ No newline at end of file + CGO_ENABLED=0 go test -v -race -coverprofile=coverage.out ./cmd/... ./pkg/... \ No newline at end of file From 6a5d7e5695ac93d8d43276874d7517692fe6dc8b Mon Sep 17 00:00:00 2001 From: alejandro Date: Tue, 10 Feb 2026 10:53:14 +0000 Subject: [PATCH 3/5] Fixed actions --- .github/workflows/build-lint-test.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-lint-test.yaml b/.github/workflows/build-lint-test.yaml index 1b4aa13..5173a0d 100644 --- a/.github/workflows/build-lint-test.yaml +++ b/.github/workflows/build-lint-test.yaml @@ -1,7 +1,6 @@ name: Build, Lint, and Test on: - push: pull_request: jobs: @@ -55,7 +54,7 @@ jobs: ${{ runner.os }}-go- - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: version: v2.8.0 @@ -84,5 +83,4 @@ jobs: run: go mod download - name: Run tests - run: | - CGO_ENABLED=0 go test -v -race -coverprofile=coverage.out ./cmd/... ./pkg/... \ No newline at end of file + run: go test -v ./cmd/... ./pkg/... \ No newline at end of file From ca2fa24ab89bcd3528752c45552c2b4c8d81a49f Mon Sep 17 00:00:00 2001 From: alejandro Date: Tue, 10 Feb 2026 10:54:29 +0000 Subject: [PATCH 4/5] Fixed actions2 --- .github/workflows/build-lint-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-lint-test.yaml b/.github/workflows/build-lint-test.yaml index 5173a0d..beffb70 100644 --- a/.github/workflows/build-lint-test.yaml +++ b/.github/workflows/build-lint-test.yaml @@ -1,7 +1,7 @@ name: Build, Lint, and Test on: - pull_request: + push: jobs: build: From 578f7a7da697c6eeec39681d7e4f16c56f393666 Mon Sep 17 00:00:00 2001 From: alejandro Date: Tue, 10 Feb 2026 10:55:38 +0000 Subject: [PATCH 5/5] Fixed actions3 --- .github/workflows/build-lint-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-lint-test.yaml b/.github/workflows/build-lint-test.yaml index beffb70..1c7c024 100644 --- a/.github/workflows/build-lint-test.yaml +++ b/.github/workflows/build-lint-test.yaml @@ -54,7 +54,7 @@ jobs: ${{ runner.os }}-go- - name: golangci-lint - uses: golangci/golangci-lint-action@v7 + uses: golangci/golangci-lint-action@v8 with: version: v2.8.0