Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/build-lint-test.yaml
Original file line number Diff line number Diff line change
@@ -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/...
36 changes: 20 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
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
- nakedret
- 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
26 changes: 6 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
# --------------
Expand All @@ -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
# ----
Expand All @@ -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))
Expand Down
11 changes: 0 additions & 11 deletions cloudbuild.yaml

This file was deleted.

Loading