Skip to content

Commit

Permalink
feat: use viper to map env vars as flag (#520)
Browse files Browse the repository at this point in the history
* feat: use viper to map env vars as flag

* feat: prevent race condition

* chore: port viper binding to prerun

* fix: e2e tests

* fix: build step in ci

* chore: restore old structure

* chore: remove unused code
  • Loading branch information
Al-Pragliola authored Jul 18, 2024
1 parent 8706af4 commit ed7b162
Show file tree
Hide file tree
Showing 78 changed files with 723 additions and 1,020 deletions.
20 changes: 10 additions & 10 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: main

steps:
- name: prepare
image: quay.io/sighup/golang:1.22.0
image: quay.io/sighup/golang:1.22.3
pull: always
depends_on:
- clone
Expand All @@ -22,7 +22,7 @@ steps:
GOTMPDIR: /drone/src/.go/tmp

- name: license
image: quay.io/sighup/golang:1.22.0
image: quay.io/sighup/golang:1.22.3
pull: always
depends_on:
- prepare
Expand All @@ -35,7 +35,7 @@ steps:
GOTMPDIR: /drone/src/.go/tmp

- name: lint
image: quay.io/sighup/golang:1.22.0
image: quay.io/sighup/golang:1.22.3
pull: always
depends_on:
- prepare
Expand All @@ -48,7 +48,7 @@ steps:
GOTMPDIR: /drone/src/.go/tmp

- name: test-unit
image: quay.io/sighup/golang:1.22.0
image: quay.io/sighup/golang:1.22.3
pull: always
depends_on:
- prepare
Expand All @@ -61,7 +61,7 @@ steps:
GOTMPDIR: /drone/src/.go/tmp

- name: test-integration
image: quay.io/sighup/golang:1.22.0
image: quay.io/sighup/golang:1.22.3
pull: always
depends_on:
- prepare
Expand All @@ -84,8 +84,8 @@ steps:
- apt update
- apt install -y curl git make ssh unzip
# Install Golang & deps
- curl -sL https://go.dev/dl/go1.22.0.linux-amd64.tar.gz -o go1.22.0.tar.gz
- rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.0.tar.gz
- curl -sL https://go.dev/dl/go1.22.3.linux-amd64.tar.gz -o go1.22.3.tar.gz
- rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.3.tar.gz
- echo 'export PATH=$$PATH:/usr/local/go/bin:/root/go/bin' >> /etc/profile
- export PATH=$$PATH:/usr/local/go/bin:/root/go/bin
- go install github.com/onsi/ginkgo/v2/[email protected]
Expand All @@ -108,7 +108,7 @@ steps:
# Run tests
- make test-e2e
# Cleanup
- rm go1.22.0.tar.gz
- rm go1.22.3.tar.gz
- rm awscliv2.zip
environment:
CGO_ENABLED: 0
Expand All @@ -132,7 +132,7 @@ steps:
from_secret: TERRAFORM_TF_STATES_BUCKET_NAME

- name: build
image: quay.io/sighup/golang:1.22.0
image: quay.io/sighup/golang:1.22.3
pull: always
depends_on:
- lint
Expand All @@ -158,7 +158,7 @@ steps:
from_secret: GITHUB_TOKEN

- name: build-release
image: quay.io/sighup/golang:1.22.0
image: quay.io/sighup/golang:1.22.3
pull: always
depends_on:
- lint
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ brews:
owner: sighupio
name: homebrew-furyctl
skip_upload: auto
folder: Formula
directory: Formula
homepage: "https://gihub.com/sighupio/furyctl"
description: "furyctl binary"
conflicts:
Expand Down
28 changes: 8 additions & 20 deletions .rules/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
# Options for analysis running.
run:
timeout: 5m
skip-files:
- ".*\\.gen\\.go$"
- "file_getter.go"
modules-download-mode: readonly
go: "1.22"

# output configuration options
output:
Expand All @@ -30,17 +28,8 @@ linters:
- wastedassign
- ireturn # not working with generics https://github.com/butuzov/ireturn/issues/37
- varnamelen # not useful
# deprecated
- deadcode
- exhaustivestruct
- golint
- nosnakecase
- structcheck
- ifshort
- interfacer
- maligned
- scopelint
- varcheck
- gomnd
- execinquery
# unused
- exhaustruct
- forbidigo
Expand Down Expand Up @@ -88,16 +77,13 @@ linters-settings:
capital: true
period: true
gofumpt:
lang-version: "1.22"
extra-rules: true
goimports:
local-prefixes: github.com/sighupio
gosec:
excludes:
- G204
- G101
govet:
check-shadowing: false
grouper:
const-require-single-const: true
const-require-grouping: false
Expand Down Expand Up @@ -285,7 +271,7 @@ linters-settings:
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#imports-blacklist
- name: imports-blacklist
- name: imports-blocklist
severity: warning
disabled: false
arguments:
Expand Down Expand Up @@ -433,8 +419,6 @@ linters-settings:
- name: waitgroup-by-value
severity: warning
disabled: false
varcheck:
exported-fields: true
varnamelen:
check-receiver: true
check-return: true
Expand Down Expand Up @@ -468,6 +452,10 @@ issues:
# Default: []
exclude: []

exclude-files:
- ".*\\.gen\\.go$"
- "file_getter.go"

# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude some linters from running on tests files.
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bats 1.8.2
drone 1.7.0
golang 1.22.0
golangci-lint 1.55.2
golang 1.22.3
golangci-lint 1.59.1
goreleaser 1.24.0
kubectx 0.9.5
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ env:
@grep -v '^#' .env | sed 's/^/export /'

tools:
@go install github.com/daixiang0/gci@v0.12.1
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
@go install github.com/daixiang0/gci@v0.13.4
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
@go install github.com/google/[email protected]
@go install github.com/nikolaydubina/go-cover-treemap@v1.3.0
@go install github.com/onsi/ginkgo/v2/ginkgo@v2.15.0
@go install golang.org/x/tools/cmd/goimports@v0.17.0
@go install github.com/nikolaydubina/go-cover-treemap@v1.4.2
@go install github.com/onsi/ginkgo/v2/ginkgo@v2.19.0
@go install golang.org/x/tools/cmd/goimports@v0.22.0
@go install mvdan.cc/[email protected]
@go install github.com/momaek/[email protected]

Expand Down Expand Up @@ -109,12 +109,12 @@ format-go: fmt fumpt imports gci formattag
fmt:
@find . -name "*.go" -type f -not -path '*/vendor/*' \
| sed 's/^\.\///g' \
| xargs -I {} sh -c 'echo "formatting {}.." && gofmt -w -s {}'
| xargs -I {} -S 5000 sh -c 'echo "formatting {}.." && gofmt -w -s {}'

fumpt:
@find . -name "*.go" -type f -not -path '*/vendor/*' \
| sed 's/^\.\///g' \
| xargs -I {} sh -c 'echo "formatting {}.." && gofumpt -w -extra {}'
| xargs -I {} -S 5000 sh -c 'echo "formatting {}.." && gofumpt -w -extra {}'

imports:
@goimports -v -w -e -local github.com/sighupio main.go
Expand All @@ -124,20 +124,20 @@ imports:
gci:
@find . -name "*.go" -type f -not -path '*/vendor/*' \
| sed 's/^\.\///g' \
| xargs -I {} sh -c 'echo "formatting imports for {}.." && \
| xargs -I {} -S 5000 sh -c 'echo "formatting imports for {}.." && \
gci write --skip-generated -s standard -s default -s "Prefix(github.com/sighupio)" {}'

formattag:
@find . -name "*.go" -type f -not -path '*/vendor/*' \
| sed 's/^\.\///g' \
| xargs -I {} sh -c 'formattag -file {}'
| xargs -I {} -S 5000 sh -c 'formattag -file {}'

.PHONY: lint lint-go

lint: lint-go

lint-go:
@GOFLAGS=-mod=mod golangci-lint -v run --color=always --config=${_PROJECT_DIRECTORY}/.rules/.golangci.yml ./...
@GOFLAGS=-mod=mod golangci-lint -v run --color=always --max-same-issues 25 --config=${_PROJECT_DIRECTORY}/.rules/.golangci.yml ./...

.PHONY: test-unit test-integration test-e2e test-all show-coverage

Expand Down
Loading

0 comments on commit ed7b162

Please sign in to comment.