Skip to content

Commit

Permalink
Merge pull request #236 from nats-io/deps-update
Browse files Browse the repository at this point in the history
CI and Dependency Updates
  • Loading branch information
wallyqs committed Jun 27, 2023
2 parents fe8c3eb + a067171 commit 44eb8da
Show file tree
Hide file tree
Showing 26 changed files with 417 additions and 359 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test Coverage
on:
push:
branches:
- main
paths-ignore:
- '**.md'

jobs:
coverage:
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: Lint
uses: golangci/golangci-lint-action@v3
with:
skip-pkg-cache: true

- name: Run Tests
run: make test-cov

- name: Run Coveralls
run: goveralls -coverprofile=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.

62 changes: 32 additions & 30 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,45 @@ on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checkout Code
uses: actions/checkout@v3

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

- name: Setup QEMU
uses: docker/setup-qemu-action@v2
- name: Setup QEMU
uses: docker/setup-qemu-action@v2

- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Setup Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_CLI_TOKEN }}
- name: Setup Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_CLI_TOKEN }}

- name: Get Image Tags
id: tags
run: |
version=$(sed 's/^v//' <<< ${{ github.ref_name }})
echo tags="latest,${version}" >> $GITHUB_OUTPUT
- name: Get Image Tags
id: tags
run: |
version=$(sed 's/^v//' <<< ${{ github.ref_name }})
echo tags="latest,${version}" >> $GITHUB_OUTPUT
- name: Build and Push
uses: docker/bake-action@v3
env:
TAGS: "${{ steps.tags.outputs.tags }}"
REGISTRY: "natsio"
with:
push: true
set:
goreleaser.args.GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
- name: Build and Push
uses: docker/bake-action@v3
env:
TAGS: "${{ steps.tags.outputs.tags }}"
REGISTRY: "natsio"
with:
files: docker-bake.hcl
push: true
set:
goreleaser.args.GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
26 changes: 26 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test
on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'

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: 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
65 changes: 32 additions & 33 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@
project_name: prometheus-nats-exporter

release:
name_template: 'Release {{.Tag}}'
draft: true
github:
owner: nats-io
name: prometheus-nats-exporter

name_template: 'Release {{.Tag}}'

env:
- IMAGE_REPOSITORY={{ if index .Env "IMAGE_REGISTRY" }}{{ .Env.IMAGE_REGISTRY }}/{{ end }}{{ .ProjectName }}

builds:
- id: prometheus-nats-exporter
main: .
binary: prometheus-nats-exporter
main: .
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
env:
- GO111MODULE=on
- CGO_ENABLED=0
goos:
- darwin
- linux
- darwin
- windows
- freebsd
goarch:
Expand All @@ -30,6 +27,7 @@ builds:
- arm64
- 386
- mips64le
- s390x
goarm:
- 6
- 7
Expand All @@ -43,33 +41,34 @@ builds:
- goos: freebsd
goarch: 386

archives:
- name_template: '{{.ProjectName}}-{{.Tag}}-{{.Os}}-{{.Arch}}{{if .Arm}}{{.Arm}}{{end}}'
wrap_in_directory: true
format: zip
files:
- README.md
- LICENSE
- name_template: '{{.ProjectName}}-{{.Tag}}-{{.Os}}-{{.Arch}}{{if .Arm}}{{.Arm}}{{end}}'
id: targz-archives
wrap_in_directory: true
format: tar.gz
files:
- README.md
- LICENSE

checksum:
name_template: '{{ .ProjectName }}-v{{ .Version }}-checksums.txt'
name_template: 'checksums.txt'

snapshot:
name_template: SNAPSHOT-{{ .Commit }}
archives:
- format: tar.gz
name_template: >-
{{ .ProjectName }}-v{{ .Version }}-
{{- .Os }}-
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
format_overrides:
- goos: windows
format: zip

nfpms:
- file_name_template: '{{.ProjectName}}-{{.Tag}}-{{.Arch}}{{if .Arm}}{{.Arm}}{{end}}'
homepage: https://nats.io
description: A Prometheus exporter for NATS
maintainer: Colin Sullivan <colin@nats.io>
vendor: nats.io
license: Apache 2.0
formats:
- formats:
- deb
file_name_template: >-
{{ .ProjectName }}-v{{ .Version }}-
{{- .Os }}-
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
description: A Prometheus exporter for NATS
vendor: nats.io
homepage: https://nats.io
license: Apache 2.0
maintainer: Synadia <info@synadia.com>
64 changes: 15 additions & 49 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,63 +7,30 @@ 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:
go build

.PHONY: test
test:
go test -race -count=1 -parallel=1 -v ./test/...
go test -race -count=1 -parallel=1 -v ./collector/...
go test -v -race -count=1 -parallel=1 ./test/...
go test -v -race -count=1 -parallel=1 ./collector/...
go test -v -race -count=1 -parallel=1 ./exporter/...

# TODO: Fix certs use "insecure algorithm SHA1-RSA", then remove GODEBUG
GODEBUG=x509sha1=1 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 ./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 ./...
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![License][License-Image]][License-Url] [![Build][Build-Status-Image]][Build-Status-Url] [![Coverage][Coverage-Image]][Coverage-Url]
[![License][License-Image]][License-Url] ![Build][Build-Status-Image] [![Coverage][Coverage-Image]][Coverage-Url]

# The Prometheus NATS Exporter

Expand Down Expand Up @@ -196,7 +196,6 @@ used to monitor NATS Streaming as well. Refer to the

[License-Url]: https://www.apache.org/licenses/LICENSE-2.0
[License-Image]: https://img.shields.io/badge/License-Apache2-blue.svg
[Build-Status-Url]: https://github.com/nats-io/prometheus-nats-exporter/actions/workflows/go.yaml
[Build-Status-Image]: https://github.com/nats-io/prometheus-nats-exporter/actions/workflows/go.yaml/badge.svg
[Coverage-Url]: https://codecov.io/gh/nats-io/prometheus-nats-exporter
[Coverage-image]: https://codecov.io/gh/nats-io/prometheus-nats-exporter/branch/master/graph/badge.svg
[Build-Status-Image]: https://img.shields.io/github/actions/workflow/status/nats-io/prometheus-nats-exporter/coverage.yaml?branch=main
[Coverage-Url]: https://coveralls.io/github/nats-io/prometheus-nats-exporter?branch=main
[Coverage-Image]: https://coveralls.io/repos/github/nats-io/prometheus-nats-exporter/badge.svg?branch=main
Loading

0 comments on commit 44eb8da

Please sign in to comment.