Skip to content

Commit

Permalink
Updating Github workflows. Fixed some unreachable code. Updated Makef…
Browse files Browse the repository at this point in the history
…ile. Updated go deps
  • Loading branch information
samuelattwood committed Jun 10, 2023
1 parent 6cae5fd commit ca3c490
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 156 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test Coverage
on:
push:
branches:
- main
- deps-update
jobs:
test:
name: Test Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

- name: Setup Goveralls
run: go install github.com/mattn/goveralls@v0.0.12

- name: Setup Dependencies
run: go mod download

- name: Run Tests
run: make test-cov

- name: Run Coveralls
run: goveralls -coverprofile=test.out,collector.out,exporter.out -service=github
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 changes: 0 additions & 36 deletions .github/workflows/go.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.19"
go-version-file: go.mod

- name: Setup QEMU
uses: docker/setup-qemu-action@v2
Expand All @@ -40,6 +40,7 @@ jobs:
TAGS: "${{ steps.tags.outputs.tags }}"
REGISTRY: "natsio"
with:
files: docker-bake.hcl
push: true
set:
goreleaser.args.GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test
on: [push,pull_request]

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
runs-on: ${{matrix.os}}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

- name: Lint
uses: golangci/golangci-lint-action@v3

- name: Run tests
run: make test
22 changes: 22 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
issues:
exclude-use-default: false
max-same-issues: 0
linters:
enable:
- dupl
- exportloopref
- gochecknoinits
- gocritic
- gocyclo
- gofmt
- goimports
- lll
- misspell
- nakedret
- prealloc
- revive
- stylecheck
- unconvert
- unparam
disable:
- errcheck
56 changes: 12 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export GO111MODULE := on
drepo ?= natsio

prometheus-nats-exporter.docker:
Expand All @@ -8,18 +7,7 @@ prometheus-nats-exporter.docker:

.PHONY: dockerx
dockerx:
ifneq ($(ver),)
# Ensure 'docker buildx ls' shows correct platforms.
docker buildx build \
--tag $(drepo)/prometheus-nats-exporter:$(ver) --tag $(drepo)/prometheus-nats-exporter:latest \
--platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 \
--file docker/linux/Dockerfile \
--push .
else
# Missing version, try this.
# make dockerx ver=1.2.3
exit 1
endif
docker buildx bake --load

.PHONY: build
build:
Expand All @@ -31,38 +19,18 @@ test:
go test -race -count=1 -parallel=1 -v ./collector/...
go test -race -count=1 -parallel=1 -v ./exporter/...

.PHONY: test-cover
test-cover:
./scripts/cov.sh

.PHONY: test-cover-ci
test-cover-ci:
./scripts/cov.sh CI

.PHONY: install-tools
install-tools:
cd /tmp && go install github.com/wadey/gocovmerge@latest
cd /tmp && go install github.com/golangci/golangci-lint/cmd/golangci-lint@f0dbc75
.PHONY: test-cov
test-cov:
go test -v -race -count=1 -parallel=1 -coverprofile=test.out ./test/...
go test -v -race -count=1 -parallel=1 -coverprofile=collector.out ./collector/...
go test -v -race -count=1 -parallel=1 -coverprofile=exporter.out ./exporter/...

.PHONY: lint
lint:
@PATH=$(shell go env GOPATH)/bin:$(PATH)
@if ! which golangci-lint >/dev/null; then \
echo "golangci-lint is required and was not found"; \
exit 1; \
fi
go vet ./...
$(shell go env GOPATH)/bin/golangci-lint run \
--no-config --exclude-use-default=false --max-same-issues=0 \
--disable errcheck \
--enable revive \
--enable stylecheck \
--enable unconvert \
--enable dupl \
--enable gocyclo \
--enable gofmt \
--enable goimports \
--enable misspell \
--enable lll \
--enable unparam \
--enable nakedret \
--enable prealloc \
--enable exportloopref \
--enable gocritic \
--enable gochecknoinits \
./...
$(shell go env GOPATH)/bin/golangci-lint run ./...
7 changes: 5 additions & 2 deletions cicd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ ARG GO_APP
FROM alpine:3.18.0 as deps

ARG GO_APP
ARG GORELEASER_DIST_DIR=/go/src/dist

ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT

RUN mkdir -p /go/bin /go/src
RUN mkdir -p /go/bin /go/src ${GORELEASER_DIST_DIR}

COPY --from=build /go/src/dist /go/src/dist
COPY --from=build ${GORELEASER_DIST_DIR}/ ${GORELEASER_DIST_DIR}

RUN <<EOT
set -e
apk add --no-cache ca-certificates jq
cd ${GORELEASER_DIST_DIR}/..

if [[ ${TARGETARCH} == "arm" ]]; then VARIANT=$(echo ${TARGETVARIANT} | sed 's/^v//'); fi
BIN_PATH=$(jq -r ".[] |select(.type == \"Binary\" and \
.name == \"${GO_APP}\" and \
Expand Down
6 changes: 3 additions & 3 deletions exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ func TestExporterHTTPSInvalidConfig(t *testing.T) {
checkExporterStart := func() {
exp := NewExporter(opts)
if err := exp.Start(); err == nil {
t.Fatalf("Did not receive expected error.")
exp.Stop()
t.Fatalf("Did not receive expected error.")
}
}

Expand Down Expand Up @@ -443,8 +443,8 @@ func TestPortReuse(t *testing.T) {
// attempt to start another exporter on the same port
exp2 := NewExporter(opts)
if err := exp2.Start(); err == nil {
t.Fatalf("Did not receive expected error.")
exp2.Stop()
t.Fatalf("Did not receive expected error.")
}
}

Expand Down Expand Up @@ -534,8 +534,8 @@ func TestExporterStartNoMetricsSelected(t *testing.T) {
}

if err := exp.Start(); err == nil {
exp.Stop()
t.Fatalf("Did not receive expected error adding a server.")
defer exp.Stop()
}
}

Expand Down
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ go 1.20

require (
github.com/nats-io/nats-replicator v0.1.0
github.com/nats-io/nats-server/v2 v2.9.16
github.com/nats-io/nats-server/v2 v2.9.17
github.com/nats-io/nats-streaming-server v0.25.4
github.com/nats-io/nats.go v1.25.0
github.com/nats-io/nats.go v1.26.0
github.com/nats-io/stan.go v0.10.4
github.com/prometheus/client_golang v1.15.0
github.com/prometheus/client_model v0.3.0
golang.org/x/crypto v0.8.0
github.com/prometheus/client_golang v1.15.1
github.com/prometheus/client_model v0.4.0
golang.org/x/crypto v0.9.0
)

require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/go-msgpack/v2 v2.1.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/golang-lru v0.5.0 // indirect
github.com/hashicorp/raft v1.4.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/nats-io/jwt/v2 v2.4.1 // indirect
Expand All @@ -37,7 +37,7 @@ require (
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)

0 comments on commit ca3c490

Please sign in to comment.