diff --git a/.github/workflows/build-lint-test.yaml b/.github/workflows/build-lint-test.yaml new file mode 100644 index 0000000..1c7c024 --- /dev/null +++ b/.github/workflows/build-lint-test.yaml @@ -0,0 +1,86 @@ +name: Build, Lint, and Test + +on: + push: + +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@v8 + 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: go test -v ./cmd/... ./pkg/... \ 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