Skip to content

Commit

Permalink
Replace flag with kingpin
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed May 24, 2023
1 parent 2667e4c commit 416827e
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 346 deletions.
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
change:
- head-branch: ['^change/']

enhancement:
- head-branch: ['^feature/', '^feat/', '^enhancement/', '^enh/']

Expand Down
24 changes: 8 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,16 @@ on:
push:
branches:
- main
paths-ignore:
- '**.md'
- 'LICENSE'
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- "v[0-9]+.[0-9]+.[0-9]+"
pull_request:
branches:
- main
paths-ignore:
- '**.md'
- 'LICENSE'
types:
- opened
- reopened
- synchronize

env:
DOCKER_PLATFORMS: "linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386"

jobs:

unit-tests:
name: Unit Tests
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -65,7 +54,6 @@ jobs:
run: |
echo "go_path=$(go env GOPATH)" >> $GITHUB_OUTPUT
- name: Setup QEMU

uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0
with:
platforms: arm,arm64,ppc64le,s390x,mips64le,386
Expand Down Expand Up @@ -130,7 +118,7 @@ jobs:
- name: Publish Release Notes
uses: release-drafter/release-drafter@569eb7ee3a85817ab916c8f8ff03a5bd96c9c83e # v5.23.0
with:
publish: true
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ startsWith(github.ref, 'refs/tags/') }}
Expand All @@ -142,18 +130,22 @@ jobs:
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0
with:
version: latest
args: ${{ !startsWith(github.ref, 'refs/tags/') && 'build --snapshot' || 'release' }} ${{ github.event_name == 'pull_request' && '--single-target' || '' }} --rm-dist
args: ${{ !startsWith(github.ref, 'refs/tags/') && 'build --snapshot' || 'release' }} ${{ github.event_name == 'pull_request' && '--single-target' || '' }} --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOPATH: ${{ steps.go.outputs.go_path }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.NGINX_PAT }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_COMMUNITY }}

- name: Print NGINX Prometheus Exporter info
run: ./dist/nginx-prometheus-exporter_linux_amd64_v1/nginx-prometheus-exporter --version
continue-on-error: true

- name: Build and Push Docker Image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0
with:
file: build/Dockerfile
context: '.'
context: "."
target: goreleaser
platforms: ${{ github.event_name != 'pull_request' && env.DOCKER_PLATFORMS || '' }}
tags: ${{ steps.meta.outputs.tags }}
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ linters-settings:
- name: unused-parameter
- name: var-declaration
- name: var-naming
errcheck:
exclude-functions:
- (github.com/go-kit/log.Logger).Log

linters:
enable:
Expand Down
15 changes: 6 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
before:
hooks:
- go mod tidy
- go mod verify

builds:
- env:
- CGO_ENABLED=0
Expand Down Expand Up @@ -33,14 +28,16 @@ builds:
- all=-trimpath={{.Env.GOPATH}}
asmflags:
- all=-trimpath={{.Env.GOPATH}}
ldflags:
- 's -w -X github.com/prometheus/common/version.Version={{.Version}} -X github.com/prometheus/common/version.BuildDate={{.Date}} -X github.com/prometheus/common/version.Branch={{.Branch}} -X github.com/prometheus/common/version.BuildUser=goreleaser'

sboms:
- artifacts: archive

archives:
- format_overrides:
- goos: windows
format: zip
- format_overrides:
- goos: windows
format: zip

checksum:
name_template: 'sha256sums.txt'
Expand All @@ -52,7 +49,7 @@ brews:
- tap:
owner: nginxinc
name: homebrew-tap
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
token: '{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}'
folder: Formula
homepage: https://www.nginx.com/
description: NGINX Prometheus Exporter for NGINX and NGINX Plus
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ PREFIX = nginx/nginx-prometheus-exporter

.PHONY: nginx-prometheus-exporter
nginx-prometheus-exporter:
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$(VERSION)" -o nginx-prometheus-exporter
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X github.com/prometheus/common/version.Version=$(VERSION)" -o nginx-prometheus-exporter

.PHONY: build-goreleaser
build-goreleaser: ## Build all binaries using GoReleaser
@goreleaser -v || (code=$$?; printf "\033[0;31mError\033[0m: there was a problem with GoReleaser. Follow the docs to install it https://goreleaser.com/install\n"; exit $$code)
GOPATH=$(shell go env GOPATH) goreleaser build --rm-dist --snapshot
GOPATH=$(shell go env GOPATH) goreleaser build --clean --snapshot --debug

.PHONY: lint
lint:
Expand Down
Loading

0 comments on commit 416827e

Please sign in to comment.