Skip to content

Commit 21cc6ef

Browse files
committed
ci/lint: refactored using golangci
1 parent 14a5c9a commit 21cc6ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1485
-1030
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- name: Set up Go
5757
uses: actions/setup-go@v2
5858
with:
59-
go-version: 1.17
59+
go-version: 1.18
6060

6161
- name: Import GPG key
6262
uses: crazy-max/ghaction-import-gpg@v3
@@ -67,7 +67,7 @@ jobs:
6767
- name: Install goreleaser
6868
uses: goreleaser/goreleaser-action@v2
6969
with:
70-
version: v1.4.1
70+
version: v1.8.3
7171
install-only: true
7272

7373
- name: Run goreleaser

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install Go
3030
uses: actions/setup-go@v2
3131
with:
32-
go-version: 1.17
32+
go-version: 1.18
3333

3434
- name: Lint
3535
if: ${{ matrix.os == 'ubuntu-20.04' }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist
2+
helpers
23
vendor
34
**/*.tgz
45
/gitlab-ci-pipelines-exporter.yml

.golangci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
linters:
2+
enable-all: true
3+
disable:
4+
# Deprecated ones
5+
- golint
6+
- interfacer
7+
- maligned
8+
- scopelint
9+
10+
# We don't want these ones
11+
- exhaustivestruct
12+
- forcetypeassert
13+
- gochecknoglobals
14+
- godox
15+
- goerr113
16+
- ireturn
17+
- nakedret
18+
- testpackage
19+
- varnamelen
20+
21+
# TODO
22+
- tagliatelle
23+
- promlinter
24+
- paralleltest
25+
- gocognit
26+
- gomoddirectives
27+
- forbidigo
28+
- goconst
29+
- gomnd
30+
- lll
31+
- dupl
32+
33+
linters-settings:
34+
funlen:
35+
lines: -1 # (disabled)
36+
statements: 100
37+
38+
cyclop:
39+
max-complexity: 20
40+
41+
lll:
42+
line-length: 140
43+
44+
nestif:
45+
min-complexity: 18

.goreleaser.pre.yml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
before:
22
hooks:
3-
- go mod download
3+
- make man-pages
4+
- make autocomplete-scripts
45

56
builds:
67
- main: ./cmd/gitlab-ci-pipelines-exporter
@@ -18,16 +19,49 @@ builds:
1819
goarm: [6, 7]
1920
flags:
2021
- -trimpath
21-
ignore:
22-
- { goos: darwin, goarch: 386 }
23-
- { goos: darwin, goarch: arm }
24-
- { goos: windows, goarch: arm }
22+
23+
universal_binaries:
24+
- {}
2525

2626
archives:
2727
- name_template: '{{ .ProjectName }}_edge_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
2828
format_overrides:
2929
- goos: windows
3030
format: zip
31+
files:
32+
- README.md
33+
- LICENSE
34+
- helpers/*
35+
36+
nfpms:
37+
- maintainer: &author Maxime VISONNEAU <[email protected]>
38+
description: &description GitLab CI pipelines exporter (prometheus/open-metrics)
39+
license: &license Apache-2.0
40+
homepage: &homepage https://github.com/mvisonneau/gitlab-ci-pipelines-exporter
41+
vendor: *author
42+
file_name_template: '{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
43+
bindir: /usr/local/bin
44+
formats:
45+
- apk
46+
- deb
47+
- rpm
48+
contents:
49+
- src: ./helpers/autocomplete/bash
50+
dst: /usr/share/bash-completion/completions/{{ .ProjectName }}
51+
file_info:
52+
mode: 0644
53+
- src: ./helpers/autocomplete/zsh
54+
dst: /usr/share/zsh/vendor-completions/_{{ .ProjectName }}
55+
file_info:
56+
mode: 0644
57+
- src: ./helpers/manpages/{{ .ProjectName }}.1.gz
58+
dst: /usr/share/man/man1/{{ .ProjectName }}.1.gz
59+
file_info:
60+
mode: 0644
61+
- src: ./LICENSE
62+
dst: /usr/share/doc/{{ .ProjectName }}/copyright
63+
file_info:
64+
mode: 0644
3165

3266
release:
3367
disable: true
@@ -36,7 +70,7 @@ snapcrafts:
3670
- summary: GitLab CI pipelines exporter (prometheus/open-metrics)
3771
description: Monitor GitLab CI pipelines related metrics.
3872
license: Apache-2.0
39-
confinement: strict
73+
confinement: classic
4074
grade: devel
4175
apps:
4276
gitlab-ci-pipelines-exporter:

.goreleaser.yml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
before:
22
hooks:
3-
- go mod download
3+
- make man-pages
4+
- make autocomplete-scripts
45

56
builds:
67
- main: ./cmd/gitlab-ci-pipelines-exporter
@@ -18,16 +19,19 @@ builds:
1819
goarm: [6, 7]
1920
flags:
2021
- -trimpath
21-
ignore:
22-
- { goos: darwin, goarch: 386 }
23-
- { goos: darwin, goarch: arm }
24-
- { goos: windows, goarch: arm }
22+
23+
universal_binaries:
24+
- {}
2525

2626
archives:
2727
- name_template: '{{ .ProjectName }}_edge_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
2828
format_overrides:
2929
- goos: windows
3030
format: zip
31+
files:
32+
- README.md
33+
- LICENSE
34+
- helpers/*
3135

3236
nfpms:
3337
- maintainer: &author Maxime VISONNEAU <[email protected]>
@@ -36,17 +40,44 @@ nfpms:
3640
homepage: &homepage https://github.com/mvisonneau/gitlab-ci-pipelines-exporter
3741
vendor: *author
3842
file_name_template: '{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
43+
bindir: /usr/local/bin
3944
formats:
45+
- apk
4046
- deb
4147
- rpm
48+
contents:
49+
- src: ./helpers/autocomplete/bash
50+
dst: /usr/share/bash-completion/completions/{{ .ProjectName }}
51+
file_info:
52+
mode: 0644
53+
- src: ./helpers/autocomplete/zsh
54+
dst: /usr/share/zsh/vendor-completions/_{{ .ProjectName }}
55+
file_info:
56+
mode: 0644
57+
- src: ./helpers/manpages/{{ .ProjectName }}.1.gz
58+
dst: /usr/share/man/man1/{{ .ProjectName }}.1.gz
59+
file_info:
60+
mode: 0644
61+
- src: ./LICENSE
62+
dst: /usr/share/doc/{{ .ProjectName }}/copyright
63+
file_info:
64+
mode: 0644
4265

4366
brews:
4467
- description: *description
4568
homepage: *homepage
69+
license: *license
4670
folder: Formula
4771
tap:
4872
owner: mvisonneau
4973
name: homebrew-tap
74+
test: |
75+
system "#{bin}/{{ .ProjectName }} -v"
76+
install: |-
77+
bin.install "{{ .ProjectName }}"
78+
bash_completion.install "./helpers/autocomplete/bash" => "{{ .ProjectName }}"
79+
zsh_completion.install "./helpers/autocomplete/zsh" => "_{{ .ProjectName }}"
80+
man1.install "./helpers/manpages/{{ .ProjectName }}.1.gz"
5081
5182
scoop:
5283
description: *description

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ and this project adheres to [0ver](https://0ver.org) (more or less).
77

88
## [Unreleased]
99

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

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

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

Makefile

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,16 @@ REPOSITORY := mvisonneau/$(NAME)
55

66
.PHONY: setup
77
setup: ## Install required libraries/tools for build tasks
8-
@command -v gofumpt 2>&1 >/dev/null || go install mvdan.cc/[email protected]
9-
@command -v gosec 2>&1 >/dev/null || go install github.com/securego/gosec/v2/cmd/[email protected]
10-
@command -v ineffassign 2>&1 >/dev/null || go install github.com/gordonklaus/[email protected]
11-
@command -v misspell 2>&1 >/dev/null || go install github.com/client9/misspell/cmd/[email protected]
12-
@command -v revive 2>&1 >/dev/null || go install github.com/mgechev/[email protected]
8+
@command -v gofumpt 2>&1 >/dev/null || go install mvdan.cc/[email protected]
9+
@command -v golangci-lint 2>&1 >/dev/null || go install github.com/golangci/golangci-lint/cmd/[email protected]
1310

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

1815
.PHONY: lint
19-
lint: revive vet gofumpt ineffassign misspell gosec ## Run all lint related tests against the codebase
20-
21-
.PHONY: revive
22-
revive: setup ## Test code syntax with revive
23-
revive -config .revive.toml $(FILES)
24-
25-
.PHONY: vet
26-
vet: ## Test code syntax with go vet
27-
go vet ./...
28-
29-
.PHONY: gofumpt
30-
gofumpt: setup ## Test code syntax with gofumpt
31-
gofumpt -d $(FILES) > gofumpt.out
32-
@if [ -s gofumpt.out ]; then cat gofumpt.out; rm gofumpt.out; exit 1; else rm gofumpt.out; fi
33-
34-
.PHONY: ineffassign
35-
ineffassign: setup ## Test code syntax for ineffassign
36-
ineffassign ./...
37-
38-
.PHONY: misspell
39-
misspell: setup ## Test code with misspell
40-
misspell -error $(FILES)
41-
42-
.PHONY: gosec
43-
gosec: setup ## Test code for security vulnerabilities
44-
gosec ./...
16+
lint: setup ## Run all lint related tests upon the codebase
17+
golangci-lint run -v --fast
4518

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

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

72+
.PHONY: man-pages
73+
man-pages: ## Generates man pages
74+
rm -rf helpers/manpages
75+
mkdir -p helpers/manpages
76+
go run ./cmd/tools/man | gzip -c -9 >helpers/manpages/$(NAME).1.gz
77+
78+
.PHONY: autocomplete-scripts
79+
autocomplete-scripts: ## Download CLI autocompletion scripts
80+
rm -rf helpers/autocomplete
81+
mkdir -p helpers/autocomplete
82+
curl -sL https://raw.githubusercontent.com/urfave/cli/v2.5.0/autocomplete/bash_autocomplete > helpers/autocomplete/bash
83+
curl -sL https://raw.githubusercontent.com/urfave/cli/v2.5.0/autocomplete/zsh_autocomplete > helpers/autocomplete/zsh
84+
9985
.PHONY: all
10086
all: lint test build coverage ## Test, builds and ship package for all supported platforms
10187

cmd/tools/man/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/mvisonneau/gitlab-ci-pipelines-exporter/internal/cli"
8+
)
9+
10+
var version = "devel"
11+
12+
func main() {
13+
fmt.Println(cli.NewApp(version, time.Now()).ToMan())
14+
}

0 commit comments

Comments
 (0)