Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatur committed Oct 29, 2019
1 parent 8e79d7a commit f78f5dd
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 275 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ vendor/
.idea/
cover.out
temp/
dist/
dist/
aws-mfa
46 changes: 38 additions & 8 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[run]
deadline = "5m"
timeout = "5m"
skip-files = []

[linters-settings]

[linters-settings.govet]
check-shadowing = true

[linters-settings.golint]
min-confidence = 0.0

[linters-settings.gocyclo]
min-complexity = 15.0
min-complexity = 13.0

[linters-settings.maligned]
suggest-new = true
Expand All @@ -25,12 +23,44 @@
[linters]
enable-all = true
disable = [
"maligned",
"lll",
"gas",
"dupl",
"prealloc",
"maligned",
"gochecknoinits",
"gochecknoglobals",
"scopelint",
"funlen",
"godox",
"stylecheck",
"wsl",
]

[issues]
exclude-use-default = false
max-per-linter = 0
max-same-issues = 0
exclude = []
[[issues.exclude-rules]]
path = "annotations.go"
text = "`(compatibilityMapping)` is a global variable"

[[issues.exclude-rules]]
path = ".*_test.go"
text = "`(updateExpected)` is a global variable"

[[issues.exclude-rules]]
path = "main.go"
text = "`(Version|ShortCommit|Date)` is a global variable"

[[issues.exclude-rules]]
path = "main.go"
text = "exported var `(Version|ShortCommit|Date)` should have comment or be unexported"

[[issues.exclude-rules]]
path = "ingress/annotations.go"
text = "`getBoolValue` - `defaultValue` always receives `false`"

[[issues.exclude-rules]]
path = "static/v1.go"
text = "exported type `(.+)` should have comment or be unexported"

37 changes: 22 additions & 15 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@ project_name: aws-mfa

builds:
- binary: aws-mfa
ldflags:
- -s -w -X github.com/mmatur/aws-mfa/cmd/version.version={{.Version}} -X github.com/mmatur/aws-mfa/cmd/version.commit={{.Commit}} -X github.com/mmatur/aws-mfa/cmd/version.date={{.Date}}
main: ./main.go

goos:
- windows
- darwin
- linux
- darwin
- windows
- freebsd
- openbsd
goarch:
- amd64
- 386
- arm
- arm64
- ppc64le
goarm:
- 7

- 6
- 5
ignore:
- goos: darwin
goarch: 386
- goos: openbsd
goarch: arm
- goos: freebsd
goarch: arm

changelog:
sort: asc
Expand All @@ -31,17 +35,20 @@ changelog:
- '^docs:'
- '^doc:'
- '^chore:'
- '^chore(deps):'
- '^test:'
- '^tests:'

archive:
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm}}v{{ .Arm }}{{ end }}'
format: tar.gz
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
archives:
- id: aws-mfa
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format: tar.gz
format_overrides:
- goos: windows
format: zip
files:
- docs/*.md
- LICENSE

#release:
# disable: true
checksum:
name_template: "{{ .ProjectName }}_v{{ .Version }}_checksums.txt"
21 changes: 12 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
language: go

go:
- 1.13.x
- "1.x"

sudo: false

env:
- GO111MODULE=on
cache:
directories:
- $GOPATH/pkg/mod

notifications:
email:
on_success: never
on_failure: change

env:
- GO111MODULE=on

before_install:
# Install linters and misspell
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.21.0
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin ${GOLANGCI_LINT_VERSION}
- golangci-lint --version

install:
- echo "TRAVIS_GO_VERSION=$TRAVIS_GO_VERSION"
- make dependencies
- go mod tidy
- git diff --exit-code go.mod
- git diff --exit-code go.sum
- go mod download

deploy:
- provider: script
skip_cleanup: true
script: curl -sL https://git.io/goreleaser | bash
on:
tags: true
condition: $TRAVIS_GO_VERSION =~ ^1\.x$
48 changes: 18 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
BINARY_NAME = aws-mfa
DIST_DIR = $(CURDIR)/dist
DIST_DIR_AWS_MFA = $(DIST_DIR)/$(BINARY_NAME)

TAG_NAME := $(shell git tag -l --contains HEAD)
SHA := $(shell git rev-parse --short HEAD)
VERSION := $(if $(TAG_NAME),$(TAG_NAME),$(SHA))
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%I:%M:%S%p')
.PHONY: check clean test build package package-snapshot docs

export GO111MODULE=on

GOFILES := $(shell git ls-files '*.go' | grep -v '^vendor/')

default: clean check test build
TAG_NAME := $(shell git tag -l --contains HEAD)
SHA := $(shell git rev-parse HEAD)
VERSION := $(if $(TAG_NAME),$(TAG_NAME),$(SHA))
DATE := $(shell date +'%Y-%m-%d %H:%M:%S')

$(DIST_DIR):
mkdir -p $(DIST_DIR)
default: check test build

dependencies:
go mod download
test:
go test -v -cover ./...

clean:
rm -rf dist/ cover.out

test: clean
go test -v -cover ./...
rm -rf dist/

build:
CGO_ENABLED=0 go build -o ${DIST_DIR_AWS_MFA} -ldflags="-s -w \
-X github.com/mmatur/$(BINARY_NAME)/cmd/version.version=$(VERSION) \
-X github.com/mmatur/$(BINARY_NAME)/cmd/version.commit=$(SHA) \
-X github.com/mmatur/$(BINARY_NAME)/cmd/version.date=$(BUILD_DATE)" \
$(CURDIR)/cmd/$(BINARY_NAME)/*.go
build: clean
@echo Version: $(VERSION)
go build -v -ldflags '-X "main.Version=${VERSION}" -X "main.ShortCommit=${SHA}" -X "main.Date=${DATE}"' .

check:
golangci-lint run

fmt:
@gofmt -s -l -w $(GOFILES)
doc:
go run . doc

imports:
@goimports -w $(GOFILES)
package:
goreleaser --skip-publish --skip-validate --rm-dist

.PHONY: clean check test build dependencies fmt imports
package-snapshot:
goreleaser --skip-publish --skip-validate --rm-dist --snapshot
9 changes: 0 additions & 9 deletions cmd/aws-mfa/aws-mfa.go

This file was deleted.

Loading

0 comments on commit f78f5dd

Please sign in to comment.