Skip to content

Commit f459be1

Browse files
committed
update build system and lint
Signed-off-by: Markus Blaschke <[email protected]>
1 parent 5ab2aef commit f459be1

10 files changed

+152
-41
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/test
22
/vendor
33
/azure-scheduledevents-exporter
4+
/release-assets

.github/workflows/ci-docker.yml renamed to .github/workflows/ci-docker.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ jobs:
88
steps:
99
- uses: actions/checkout@v2
1010

11-
- name: Run Gosec Security Scanner
12-
uses: securego/gosec@master
11+
- name: Set Swap Space
12+
uses: pierotofy/set-swap-space@master
1313
with:
14-
args: ./...
14+
swap-size-gb: 12
1515

1616
- name: Run Golangci lint
1717
uses: golangci/golangci-lint-action@v2
1818
with:
1919
version: latest
20-
args: -E exportloopref,gofmt --timeout=30m
20+
args: --print-resources-usage
2121

2222
- name: Docker meta
2323
id: docker_meta
@@ -39,6 +39,6 @@ jobs:
3939
context: .
4040
file: ./Dockerfile
4141
push: false
42-
platforms: linux/amd64,linux/arm,linux/arm64
42+
platforms: linux/amd64,linux/arm64
4343
tags: ${{ steps.docker_meta.outputs.tags }}
4444
labels: ${{ steps.docker_meta.outputs.labels }}

.github/workflows/release-assets.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: "Release: assets"
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Set Swap Space
14+
uses: pierotofy/set-swap-space@master
15+
with:
16+
swap-size-gb: 12
17+
18+
- uses: actions/setup-go@v2
19+
with:
20+
go-version: '1.19'
21+
check-latest: true
22+
23+
- name: Build
24+
run: |
25+
make release-assets
26+
27+
- name: Upload assets to release
28+
uses: svenstaro/upload-release-action@v2
29+
with:
30+
repo_token: ${{ secrets.GITHUB_TOKEN }}
31+
file: ./release-assets/*
32+
tag: ${{ github.ref }}
33+
overwrite: true
34+
file_glob: true

.github/workflows/release-docker.yml renamed to .github/workflows/release-docker.yaml

+10-6
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@ on:
77
tags:
88
- '*.*.*'
99

10-
1110
jobs:
1211
lint:
1312
runs-on: ubuntu-latest
1413
steps:
1514
- uses: actions/checkout@v2
1615

17-
- name: Run Gosec Security Scanner
18-
uses: securego/gosec@master
16+
- name: Set Swap Space
17+
uses: pierotofy/set-swap-space@master
1918
with:
20-
args: ./...
19+
swap-size-gb: 12
2120

2221
- name: Run Golangci lint
2322
uses: golangci/golangci-lint-action@v2
2423
with:
2524
version: latest
26-
args: -E exportloopref,gofmt --timeout=30m
25+
args: --print-resources-usage
2726

2827
build:
2928
needs: lint
@@ -47,6 +46,11 @@ jobs:
4746
steps:
4847
- uses: actions/checkout@v2
4948

49+
- name: Set Swap Space
50+
uses: pierotofy/set-swap-space@master
51+
with:
52+
swap-size-gb: 12
53+
5054
- name: Docker meta
5155
id: docker_meta
5256
uses: docker/metadata-action@v4
@@ -82,7 +86,7 @@ jobs:
8286
with:
8387
context: .
8488
file: ./${{ matrix.Dockerfile }}
85-
platforms: linux/amd64,linux/arm,linux/arm64,linux/ppc64le
89+
platforms: linux/amd64,linux/arm64
8690
push: ${{ github.event_name != 'pull_request' }}
8791
tags: ${{ steps.docker_meta.outputs.tags }}
8892
labels: ${{ steps.docker_meta.outputs.labels }}

.github/workflows/scheduled-docker.yml renamed to .github/workflows/scheduled-docker.yaml

+10-5
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v2
1212

13-
- name: Run Gosec Security Scanner
14-
uses: securego/gosec@master
13+
- name: Set Swap Space
14+
uses: pierotofy/set-swap-space@master
1515
with:
16-
args: ./...
16+
swap-size-gb: 12
1717

1818
- name: Run Golangci lint
1919
uses: golangci/golangci-lint-action@v2
2020
with:
2121
version: latest
22-
args: -E exportloopref,gofmt --timeout=30m
22+
args: --print-resources-usage
2323

2424
build:
2525
needs: lint
@@ -43,6 +43,11 @@ jobs:
4343
steps:
4444
- uses: actions/checkout@v2
4545

46+
- name: Set Swap Space
47+
uses: pierotofy/set-swap-space@master
48+
with:
49+
swap-size-gb: 12
50+
4651
- name: Docker meta
4752
id: docker_meta
4853
uses: docker/metadata-action@v4
@@ -78,7 +83,7 @@ jobs:
7883
with:
7984
context: .
8085
file: ./${{ matrix.Dockerfile }}
81-
platforms: linux/amd64,linux/arm,linux/arm64,linux/ppc64le
86+
platforms: linux/amd64,linux/arm64
8287
push: ${{ github.event_name != 'pull_request' }}
8388
tags: ${{ steps.docker_meta.outputs.tags }}
8489
labels: ${{ steps.docker_meta.outputs.labels }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/vendor
22
/azure-scheduledevents-manager
3+
/release-assets

.golangci.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
run:
2+
timeout: 120m
3+
4+
linters:
5+
enable:
6+
- asciicheck
7+
- bidichk
8+
- bodyclose
9+
- errorlint
10+
- exportloopref
11+
- gofmt
12+
- goimports
13+
- gosec
14+
15+
linters-settings:
16+
gosec:
17+
excludes: []
18+
confidence: low
19+
config:
20+
global:
21+
audit: true
22+
23+
issues: {}
24+
25+
output:
26+
sort-results: true

Makefile

+57-21
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,90 @@ LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -ext
55

66
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
77
GOLANGCI_LINT_BIN := $(FIRST_GOPATH)/bin/golangci-lint
8-
GOSEC_BIN := $(FIRST_GOPATH)/bin/gosec
98

109
.PHONY: all
11-
all: build
10+
all: vendor build
1211

1312
.PHONY: clean
1413
clean:
1514
git clean -Xfd .
1615

17-
.PHONY: build
18-
build:
19-
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -a -ldflags '$(LDFLAGS)' -o $(PROJECT_NAME) .
16+
#######################################
17+
# builds
18+
#######################################
2019

2120
.PHONY: vendor
2221
vendor:
2322
go mod tidy
2423
go mod vendor
2524
go mod verify
2625

26+
.PHONY: build-all
27+
build-all:
28+
GOOS=linux GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME)' .
29+
GOOS=darwin GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).darwin' .
30+
GOOS=windows GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).exe' .
31+
32+
.PHONY: build
33+
build:
34+
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o $(PROJECT_NAME) .
35+
2736
.PHONY: image
28-
image: build
37+
image: image
2938
docker build -t $(PROJECT_NAME):$(GIT_TAG) .
3039

40+
.PHONY: build-push-development
3141
build-push-development:
3242
docker buildx create --use
3343
docker buildx build -t webdevops/$(PROJECT_NAME):development --platform linux/amd64,linux/arm,linux/arm64 --push .
3444

35-
.PHONY: test
36-
test:
37-
go test ./...
45+
#######################################
46+
# quality checks
47+
#######################################
3848

39-
.PHONY: dependencies
40-
dependencies:
41-
go mod vendor
49+
.PHONY: check
50+
check: vendor lint test
4251

43-
.PHONY: check-release
44-
check-release: vendor lint gosec test
52+
.PHONY: test
53+
test:
54+
time go test ./...
4555

4656
.PHONY: lint
4757
lint: $(GOLANGCI_LINT_BIN)
48-
$(GOLANGCI_LINT_BIN) run -E exportloopref,gofmt --timeout=30m
49-
50-
.PHONY: gosec
51-
gosec: $(GOSEC_BIN)
52-
$(GOSEC_BIN) ./...
58+
time $(GOLANGCI_LINT_BIN) run --verbose --print-resources-usage
5359

5460
$(GOLANGCI_LINT_BIN):
5561
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(FIRST_GOPATH)/bin
5662

57-
$(GOSEC_BIN):
58-
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(FIRST_GOPATH)/bin
63+
#######################################
64+
# release assets
65+
#######################################
66+
67+
RELEASE_ASSETS = \
68+
$(foreach GOARCH,amd64 arm64,\
69+
$(foreach GOOS,linux darwin windows,\
70+
release-assets/$(GOOS).$(GOARCH))) \
71+
72+
word-dot = $(word $2,$(subst ., ,$1))
73+
74+
.PHONY: release-assets
75+
release-assets: clean-release-assets vendor $(RELEASE_ASSETS)
76+
77+
.PHONY: clean-release-assets
78+
clean-release-assets:
79+
rm -rf ./release-assets
80+
mkdir -p ./release-assets
81+
82+
release-assets/windows.%: $(SOURCE)
83+
echo 'build release-assets for windows/$(call word-dot,$*,2)'
84+
GOOS=windows \
85+
GOARCH=$(call word-dot,$*,1) \
86+
CGO_ENABLED=0 \
87+
time go build -ldflags '$(LDFLAGS)' -o './release-assets/$(PROJECT_NAME).windows.$(call word-dot,$*,1).exe' .
88+
89+
release-assets/%: $(SOURCE)
90+
echo 'build release-assets for $(call word-dot,$*,1)/$(call word-dot,$*,2)'
91+
GOOS=$(call word-dot,$*,1) \
92+
GOARCH=$(call word-dot,$*,2) \
93+
CGO_ENABLED=0 \
94+
time go build -ldflags '$(LDFLAGS)' -o './release-assets/$(PROJECT_NAME).$(call word-dot,$*,1).$(call word-dot,$*,2)' .

go.mod

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/containrrr/shoutrrr v0.6.1
88
github.com/fatih/color v1.13.0 // indirect
99
github.com/fsnotify/fsnotify v1.5.4 // indirect
10-
github.com/jessevdk/go-flags v1.5.0
1110
github.com/mattn/go-colorable v0.1.13 // indirect
1211
github.com/onsi/ginkgo v1.16.5 // indirect
1312
github.com/onsi/gomega v1.19.0 // indirect
@@ -20,7 +19,10 @@ require (
2019
google.golang.org/protobuf v1.28.1 // indirect
2120
)
2221

23-
require github.com/go-resty/resty/v2 v2.7.0
22+
require (
23+
github.com/go-resty/resty/v2 v2.7.0
24+
github.com/jessevdk/go-flags v1.5.0
25+
)
2426

2527
require (
2628
github.com/beorn7/perks v1.0.1 // indirect

main.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"net/http"
67
"net/url"
@@ -10,7 +11,7 @@ import (
1011
"strings"
1112
"sync/atomic"
1213

13-
"github.com/jessevdk/go-flags"
14+
flags "github.com/jessevdk/go-flags"
1415
"github.com/prometheus/client_golang/prometheus/promhttp"
1516
log "github.com/sirupsen/logrus"
1617

@@ -116,7 +117,8 @@ func initArgparser() {
116117

117118
// check if there is an parse error
118119
if err != nil {
119-
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
120+
var flagsErr *flags.Error
121+
if ok := errors.As(err, &flagsErr); ok && flagsErr.Type == flags.ErrHelp {
120122
os.Exit(0)
121123
} else {
122124
fmt.Println()

0 commit comments

Comments
 (0)