Skip to content

Commit

Permalink
ci/lint: refactored using golangci
Browse files Browse the repository at this point in the history
  • Loading branch information
mvisonneau committed Apr 27, 2022
1 parent 14a5c9a commit 21cc6ef
Show file tree
Hide file tree
Showing 80 changed files with 1,485 additions and 1,030 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v3
Expand All @@ -67,7 +67,7 @@ jobs:
- name: Install goreleaser
uses: goreleaser/goreleaser-action@v2
with:
version: v1.4.1
version: v1.8.3
install-only: true

- name: Run goreleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18

- name: Lint
if: ${{ matrix.os == 'ubuntu-20.04' }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist
helpers
vendor
**/*.tgz
/gitlab-ci-pipelines-exporter.yml
Expand Down
45 changes: 45 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
linters:
enable-all: true
disable:
# Deprecated ones
- golint
- interfacer
- maligned
- scopelint

# We don't want these ones
- exhaustivestruct
- forcetypeassert
- gochecknoglobals
- godox
- goerr113
- ireturn
- nakedret
- testpackage
- varnamelen

# TODO
- tagliatelle
- promlinter
- paralleltest
- gocognit
- gomoddirectives
- forbidigo
- goconst
- gomnd
- lll
- dupl

linters-settings:
funlen:
lines: -1 # (disabled)
statements: 100

cyclop:
max-complexity: 20

lll:
line-length: 140

nestif:
min-complexity: 18
46 changes: 40 additions & 6 deletions .goreleaser.pre.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
before:
hooks:
- go mod download
- make man-pages
- make autocomplete-scripts

builds:
- main: ./cmd/gitlab-ci-pipelines-exporter
Expand All @@ -18,16 +19,49 @@ builds:
goarm: [6, 7]
flags:
- -trimpath
ignore:
- { goos: darwin, goarch: 386 }
- { goos: darwin, goarch: arm }
- { goos: windows, goarch: arm }

universal_binaries:
- {}

archives:
- name_template: '{{ .ProjectName }}_edge_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format_overrides:
- goos: windows
format: zip
files:
- README.md
- LICENSE
- helpers/*

nfpms:
- maintainer: &author Maxime VISONNEAU <maxime.visonneau@gmail.com>
description: &description GitLab CI pipelines exporter (prometheus/open-metrics)
license: &license Apache-2.0
homepage: &homepage https://github.com/mvisonneau/gitlab-ci-pipelines-exporter
vendor: *author
file_name_template: '{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
bindir: /usr/local/bin
formats:
- apk
- deb
- rpm
contents:
- src: ./helpers/autocomplete/bash
dst: /usr/share/bash-completion/completions/{{ .ProjectName }}
file_info:
mode: 0644
- src: ./helpers/autocomplete/zsh
dst: /usr/share/zsh/vendor-completions/_{{ .ProjectName }}
file_info:
mode: 0644
- src: ./helpers/manpages/{{ .ProjectName }}.1.gz
dst: /usr/share/man/man1/{{ .ProjectName }}.1.gz
file_info:
mode: 0644
- src: ./LICENSE
dst: /usr/share/doc/{{ .ProjectName }}/copyright
file_info:
mode: 0644

release:
disable: true
Expand All @@ -36,7 +70,7 @@ snapcrafts:
- summary: GitLab CI pipelines exporter (prometheus/open-metrics)
description: Monitor GitLab CI pipelines related metrics.
license: Apache-2.0
confinement: strict
confinement: classic
grade: devel
apps:
gitlab-ci-pipelines-exporter:
Expand Down
41 changes: 36 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
before:
hooks:
- go mod download
- make man-pages
- make autocomplete-scripts

builds:
- main: ./cmd/gitlab-ci-pipelines-exporter
Expand All @@ -18,16 +19,19 @@ builds:
goarm: [6, 7]
flags:
- -trimpath
ignore:
- { goos: darwin, goarch: 386 }
- { goos: darwin, goarch: arm }
- { goos: windows, goarch: arm }

universal_binaries:
- {}

archives:
- name_template: '{{ .ProjectName }}_edge_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format_overrides:
- goos: windows
format: zip
files:
- README.md
- LICENSE
- helpers/*

nfpms:
- maintainer: &author Maxime VISONNEAU <maxime.visonneau@gmail.com>
Expand All @@ -36,17 +40,44 @@ nfpms:
homepage: &homepage https://github.com/mvisonneau/gitlab-ci-pipelines-exporter
vendor: *author
file_name_template: '{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
bindir: /usr/local/bin
formats:
- apk
- deb
- rpm
contents:
- src: ./helpers/autocomplete/bash
dst: /usr/share/bash-completion/completions/{{ .ProjectName }}
file_info:
mode: 0644
- src: ./helpers/autocomplete/zsh
dst: /usr/share/zsh/vendor-completions/_{{ .ProjectName }}
file_info:
mode: 0644
- src: ./helpers/manpages/{{ .ProjectName }}.1.gz
dst: /usr/share/man/man1/{{ .ProjectName }}.1.gz
file_info:
mode: 0644
- src: ./LICENSE
dst: /usr/share/doc/{{ .ProjectName }}/copyright
file_info:
mode: 0644

brews:
- description: *description
homepage: *homepage
license: *license
folder: Formula
tap:
owner: mvisonneau
name: homebrew-tap
test: |
system "#{bin}/{{ .ProjectName }} -v"
install: |-
bin.install "{{ .ProjectName }}"
bash_completion.install "./helpers/autocomplete/bash" => "{{ .ProjectName }}"
zsh_completion.install "./helpers/autocomplete/zsh" => "_{{ .ProjectName }}"
man1.install "./helpers/manpages/{{ .ProjectName }}.1.gz"
scoop:
description: *description
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ and this project adheres to [0ver](https://0ver.org) (more or less).

## [Unreleased]

### Added

- Now passing a `context.Context` to most functional calls
- Aggregated already used linters and added new ones through the implementation of `golangci`
- Release `.apk` packages for Alpine linux
- Added man pages and autocompletion scripts (bash & zsh) to `.apk`, `.deb`, `.rpm` & `homebrew` packages
- Release "fat" binaries (arm64 + amd64 combined) for MacOS under `_all` suffix

### Changed

- Fixed a config issue preventing the arm deb/rpm packages to be released correctly
- Upgraded golang to **v1.18**
- Upgraded most dependencies to their lastest versions

## [v0.5.3] - 2022-02-11

Expand Down
50 changes: 18 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,16 @@ REPOSITORY := mvisonneau/$(NAME)

.PHONY: setup
setup: ## Install required libraries/tools for build tasks
@command -v gofumpt 2>&1 >/dev/null || go install mvdan.cc/gofumpt@v0.2.1
@command -v gosec 2>&1 >/dev/null || go install github.com/securego/gosec/v2/cmd/gosec@v2.9.6
@command -v ineffassign 2>&1 >/dev/null || go install github.com/gordonklaus/ineffassign@v0.0.0-20210914165742-4cc7213b9bc8
@command -v misspell 2>&1 >/dev/null || go install github.com/client9/misspell/cmd/misspell@v0.3.4
@command -v revive 2>&1 >/dev/null || go install github.com/mgechev/revive@v1.1.3
@command -v gofumpt 2>&1 >/dev/null || go install mvdan.cc/gofumpt@v0.3.1
@command -v golangci-lint 2>&1 >/dev/null || go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2

.PHONY: fmt
fmt: setup ## Format source code
gofumpt -w $(FILES)

.PHONY: lint
lint: revive vet gofumpt ineffassign misspell gosec ## Run all lint related tests against the codebase

.PHONY: revive
revive: setup ## Test code syntax with revive
revive -config .revive.toml $(FILES)

.PHONY: vet
vet: ## Test code syntax with go vet
go vet ./...

.PHONY: gofumpt
gofumpt: setup ## Test code syntax with gofumpt
gofumpt -d $(FILES) > gofumpt.out
@if [ -s gofumpt.out ]; then cat gofumpt.out; rm gofumpt.out; exit 1; else rm gofumpt.out; fi

.PHONY: ineffassign
ineffassign: setup ## Test code syntax for ineffassign
ineffassign ./...

.PHONY: misspell
misspell: setup ## Test code with misspell
misspell -error $(FILES)

.PHONY: gosec
gosec: setup ## Test code for security vulnerabilities
gosec ./...
lint: setup ## Run all lint related tests upon the codebase
golangci-lint run -v --fast

.PHONY: test
test: ## Run the tests against the codebase
Expand Down Expand Up @@ -88,14 +61,27 @@ dev-env: ## Build a local development environment using Docker
-v $(shell pwd):/go/src/github.com/mvisonneau/$(NAME) \
-w /go/src/github.com/mvisonneau/$(NAME) \
-p 8080:8080 \
golang:1.17 \
golang:1.18 \
/bin/bash -c 'make setup; make install; bash'

.PHONY: is-git-dirty
is-git-dirty: ## Tests if git is in a dirty state
@git status --porcelain
@test $(shell git status --porcelain | grep -c .) -eq 0

.PHONY: man-pages
man-pages: ## Generates man pages
rm -rf helpers/manpages
mkdir -p helpers/manpages
go run ./cmd/tools/man | gzip -c -9 >helpers/manpages/$(NAME).1.gz

.PHONY: autocomplete-scripts
autocomplete-scripts: ## Download CLI autocompletion scripts
rm -rf helpers/autocomplete
mkdir -p helpers/autocomplete
curl -sL https://raw.githubusercontent.com/urfave/cli/v2.5.0/autocomplete/bash_autocomplete > helpers/autocomplete/bash
curl -sL https://raw.githubusercontent.com/urfave/cli/v2.5.0/autocomplete/zsh_autocomplete > helpers/autocomplete/zsh

.PHONY: all
all: lint test build coverage ## Test, builds and ship package for all supported platforms

Expand Down
14 changes: 14 additions & 0 deletions cmd/tools/man/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"fmt"
"time"

"github.com/mvisonneau/gitlab-ci-pipelines-exporter/internal/cli"
)

var version = "devel"

func main() {
fmt.Println(cli.NewApp(version, time.Now()).ToMan())
}
Loading

0 comments on commit 21cc6ef

Please sign in to comment.