Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Evsyukov Denis <denis.evsyukov@flant.com>
  • Loading branch information
juev committed Sep 9, 2024
1 parent dd42b5f commit e0e0563
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 133 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Release a tag"
on:
push:
tags:
- v*

jobs:
release:
runs-on: ubuntu-latest
env:
# https://github.com/actions/setup-go#supported-version-syntax
# ex:
# - 1.18beta1 -> 1.18.0-beta.1
# - 1.18rc1 -> 1.18.0-rc.1
GO_VERSION: '1.23'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Create release
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean --timeout=90m
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 changes: 65 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: 2

project_name: d8-lint

builds:
- binary: d8-lint
main: .
flags:
- -trimpath
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
env:
- CGO_ENABLED=0
goos:
- darwin
- linux
goarch:
- amd64
- arm64
goarm:
- "6"
- "7"
gomips:
- hardfloat
ignore:
- goos: darwin
goarch: "386"

archives:
- format: tar.gz
wrap_in_directory: true
name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
files:
- LICENSE
- README.md

snapshot:
name_template: SNAPSHOT-{{ .Commit }}

checksum:
name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt'

changelog:
sort: asc
filters:
exclude:
- '(?i)^docs?:'
- '(?i)^docs\([^:]+\):'
- '(?i)^docs\[[^:]+\]:'
- '^tests?:'
- '(?i)^dev:'
- '(?i)^chore:'
- '^build\(deps\): bump .* in /docs \(#\d+\)'
- '^build\(deps\): bump .* in /\.github/peril \(#\d+\)'
- '^build\(deps\): bump .* in /scripts/gen_github_action_config \(#\d+\)'
- Merge pull request
- Merge branch

release:
github:
owner: deckhouse
name: d8--lint

source:
enabled: true
name_template: '{{ .ProjectName }}-{{ .Version }}-source'
88 changes: 0 additions & 88 deletions cmd/root.go

This file was deleted.

2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ go 1.23.1
require (
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.5.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
)

require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand All @@ -11,8 +10,6 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand All @@ -30,7 +27,6 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
Expand All @@ -41,8 +37,6 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
Expand Down
52 changes: 50 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,57 @@
package main

import (
"github.com/deckhouse/d8-lint/cmd"
"fmt"
"os"

"github.com/spf13/pflag"

"github.com/deckhouse/d8-lint/pkg/config"
"github.com/deckhouse/d8-lint/pkg/logger"
)

func main() {
cmd.Execute()
var (
printHelp bool
printVersion bool
cfgFile string
version = "HEAD"
)

logger.InitLogger()

flagSet := pflag.NewFlagSet("d8-lint", pflag.ContinueOnError)

flagSet.BoolVarP(&printHelp, "help", "h", false, "help message")
flagSet.BoolVarP(&printVersion, "version", "v", false, "version message")
flagSet.StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.d8lint.yaml)")

if err := flagSet.Parse(os.Args[1:]); err != nil {
Usage(flagSet)
return
}

if printHelp {
Usage(flagSet)
return
}

if printVersion {
fmt.Println("d8-lint version: ", version)
return
}

var dirs = flagSet.Args()
if len(dirs) == 0 {
dirs = []string{"."}

Check failure on line 46 in main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ineffectual assignment to dirs (ineffassign)
}

cfg := config.NewDefault()
err := config.NewLoader(cfg).Load()
logger.CheckErr(err)
}

func Usage(flagSet *pflag.FlagSet) {
fmt.Println("Usage: d8-lint [OPTIONS]")
flagSet.PrintDefaults()
}
35 changes: 2 additions & 33 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/mitchellh/go-homedir"
"github.com/mitchellh/mapstructure"
"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/deckhouse/d8-lint/pkg/fsutils"
Expand All @@ -24,19 +23,15 @@ type Loader struct {
opts LoaderOptions

viper *viper.Viper
fs *pflag.FlagSet

cfg *Config
args []string
}

func NewLoader(v *viper.Viper, fs *pflag.FlagSet, opts LoaderOptions, cfg *Config, args []string) *Loader {
func NewLoader(cfg *Config) *Loader {
return &Loader{
opts: opts,
viper: v,
fs: fs,
viper: viper.New(),
cfg: cfg,
args: args,
}
}

Expand All @@ -51,11 +46,6 @@ func (l *Loader) Load() error {
return err
}

err = l.handleEnableOnlyOption()
if err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -201,27 +191,6 @@ func (l *Loader) setConfigDir() error {
return nil
}

func (l *Loader) handleEnableOnlyOption() error {
lookup := l.fs.Lookup("enable-only")
if lookup == nil {
return nil
}

only, err := l.fs.GetStringSlice("enable-only")
if err != nil {
return err
}

if len(only) > 0 {
l.cfg.Linters = Linters{
Enable: only,
DisableAll: true,
}
}

return nil
}

func customDecoderHook() viper.DecoderConfigOption {
return viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
// Default hooks (https://github.com/spf13/viper/blob/518241257478c557633ab36e474dfcaeb9a3c623/viper.go#L135-L138).
Expand Down
19 changes: 17 additions & 2 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,29 @@ package logger
import (
"fmt"
"log/slog"
"os"
)

var logger *slog.Logger

func InitLogger() {
slog.SetLogLoggerLevel(slog.LevelInfo)
logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
}

func Infof(format string, a ...any) {
slog.Info(
logger.Info(
fmt.Sprintf(format, a...))
}

func Warnf(format string, a ...any) {
slog.Warn(
logger.Warn(
fmt.Sprintf(format, a...))
}

func CheckErr(msg any) {
if msg != nil {
logger.Error("Error:", msg)
os.Exit(1)
}
}

0 comments on commit e0e0563

Please sign in to comment.