Skip to content

Commit

Permalink
Go 1.16 + GitHub Actions = golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hypnoglow committed May 25, 2022
1 parent 6539303 commit 484b321
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 37 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: main

on:
push:
branches:
- $default-branch
pull_request:
branches:
- '*'

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true

# - name: Install dependencies
# run: |
# go mod download
# go mod vendor

- name: Run linters
uses: golangci/golangci-lint-action@v3
with:
version: v1.31
args: --verbose

- name: Build
run: |
go build -o ./bin/helm-s3 ./cmd/helms3
73 changes: 64 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,67 @@
run:
concurrency: 4
timeout: 5m

linters:
enable-all: true
disable:
- dupl
- funlen
- gochecknoglobals
- godox
- lll
- wsl
disable-all: true
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
- exhaustive
- exportloopref
- gci
- gochecknoinits
# - gocognit
- goconst
- gocritic
- gocyclo
# - godot
- gofmt
- goheader
- goimports
- golint
- gomnd
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- maligned
- misspell
- nakedret
# - nestif
- noctx
- nolintlint
- prealloc
- rowserrcheck
- scopelint
- sqlclosecheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

linters-settings:
# TODO: enable dodot and uncomment this.
# godot:
# exclude:
# - "^ ?-"
goimports:
local-prefixes: github.com/hypnoglow/helm-s3

issues:
new-from-rev: master
exclude-rules:
- linters:
- golint
- stylecheck
text: "error strings should not be capitalized"
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ test-e2e:
.PHONY: test-e2e-local
test-e2e-local:
@./hack/test-e2e-local.sh

.PHONY: lint
lint:
@golangci-lint run
20 changes: 14 additions & 6 deletions cmd/helms3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ func main() {

if len(os.Args) == 5 && !isAction(os.Args[1]) {
cmd := proxyCmd{uri: os.Args[4]}

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()
if err := cmd.Run(ctx); err != nil {
err := cmd.Run(ctx)
cancel()
if err != nil {
log.Fatal(err)
}

return
}

Expand Down Expand Up @@ -147,7 +150,6 @@ func main() {
uri: *initURI,
acl: *acl,
}
defer fmt.Printf("Initialized empty repository at %s\n", *initURI)

case actionPush:
act = pushAction{
Expand All @@ -167,7 +169,6 @@ func main() {
acl: *acl,
relative: *reindexRelative,
}
defer fmt.Printf("Repository %s was successfully reindexed.\n", *reindexTargetRepository)

case actionDelete:
act = deleteAction{
Expand All @@ -181,16 +182,23 @@ func main() {
}

ctx, cancel := context.WithTimeout(context.Background(), *timeout)
defer cancel()

err := act.Run(ctx)
cancel()

switch err {
case nil:
case ErrChartExists:
log.Fatalf("The chart already exists in the repository and cannot be overwritten without an explicit intent. If you want to replace existing chart, use --force flag:\n\n\thelm s3 push --force %s %s\n\n", *pushChartPath, *pushTargetRepository)
default:
log.Fatal(err)
}

switch action {
case actionInit:
fmt.Printf("Initialized empty repository at %s\n", *initURI)
case actionReindex:
fmt.Printf("Repository %s was successfully reindexed.\n", *reindexTargetRepository)
}
}

func isAction(name string) bool {
Expand Down
2 changes: 1 addition & 1 deletion cmd/helms3/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ type pushAction struct {
force bool
dryRun bool
ignoreIfExists bool
relative bool
acl string
contentType string
relative bool
}

func (act pushAction) Run(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/hypnoglow/helm-s3

go 1.15
go 1.16

// See: https://github.com/helm/helm/issues/9354
replace (
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bshuster-repo/logrus-logstash-hook v0.4.1 h1:pgAtgj+A31JBVtEHu2uHuEx0n+2ukqUJnS2vVe5pQNA=
github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
Expand Down Expand Up @@ -206,7 +204,6 @@ github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoD
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fvbommel/sortorder v1.0.1/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7 h1:LofdAjjjqCSXMwLGgOgnE+rdPuvX9DxCqaHwKy7i/ko=
Expand Down Expand Up @@ -258,7 +255,6 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -454,7 +450,6 @@ github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS4
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f h1:2+myh5ml7lgEU/51gbeLHfKGNfgEQQIWrlbdaOsidbQ=
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
Expand Down
6 changes: 3 additions & 3 deletions internal/awss3/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

const (
// selects serverside encryption for bucket
// selects serverside encryption for bucket.
awsS3encryption = "AWS_S3_SSE"

// s3MetadataSoftLimitBytes is application-specific soft limit
Expand All @@ -41,7 +41,7 @@ func New(session *session.Session) *Storage {
return &Storage{session: session}
}

// Returns desired encryption
// Returns desired encryption.
func getSSE() *string {
sse := os.Getenv(awsS3encryption)
if sse == "" {
Expand All @@ -66,7 +66,7 @@ func (s *Storage) Traverse(ctx context.Context, repoURI string) (<-chan ChartInf
// traverse traverses all charts in the repository.
// It writes an info item about every chart to items, and errors to errs.
// It always closes both channels when returns.
func (s *Storage) traverse(ctx context.Context, repoURI string, items chan<- ChartInfo, errs chan<- error) {
func (s *Storage) traverse(ctx context.Context, repoURI string, items chan<- ChartInfo, errs chan<- error) { //nolint:unparam // TODO: fix this issue.
defer close(items)
defer close(errs)

Expand Down
2 changes: 1 addition & 1 deletion internal/awsutil/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
awsDisableSSL = "AWS_DISABLE_SSL"

// awsBucketLocation can be set to an AWS region to force the session region
// if AWS_DEFAULT_REGION and AWS_REGION cannot be trusted
// if AWS_DEFAULT_REGION and AWS_REGION cannot be trusted.
awsBucketLocation = "HELM_S3_REGION"
)

Expand Down
8 changes: 6 additions & 2 deletions internal/helmutil/index_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"github.com/pkg/errors"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/repo"
"k8s.io/helm/pkg/urlutil" // Note that this is from Helm v2 SDK because in Helm v3 this package is internal.

// Note that this is from Helm v2 SDK because in Helm v3 this package is internal.
"k8s.io/helm/pkg/urlutil"
"sigs.k8s.io/yaml"
)

Expand All @@ -26,7 +28,9 @@ func (idx *IndexV3) Add(metadata interface{}, filename, baseURL, digest string)
return errors.New("metadata is not *chart.Metadata")
}

idx.index.Add(md, filename, baseURL, digest)
if err := idx.index.MustAdd(md, filename, baseURL, digest); err != nil {
return fmt.Errorf("add file to the index: %v", err)
}
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions internal/helmutil/repo_entry_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"fmt"
"testing"

"helm.sh/helm/v3/pkg/cli"

"github.com/stretchr/testify/assert"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/repo"
)

Expand Down
15 changes: 9 additions & 6 deletions tests/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ var mc *minio.Client

func TestMain(m *testing.M) {
setup()
defer teardown()

os.Exit(m.Run())
code := m.Run()

teardown()

os.Exit(code)
}

func setup() {
Expand Down Expand Up @@ -83,7 +86,7 @@ func teardownBucket(t *testing.T, name string) {
require.NoError(t, err, "remove bucket")
}

func setupRepo(t *testing.T, name, dir string) {
func setupRepo(t *testing.T, name, dir string) { //nolint:unparam
t.Helper()

setupBucket(t, name)
Expand Down Expand Up @@ -114,15 +117,15 @@ func command(c string) (cmd *exec.Cmd, stdout, stderr *bytes.Buffer) {
stderr = &bytes.Buffer{}
args := strings.Split(c, " ")

cmd = exec.Command(args[0], args[1:]...)
cmd = exec.Command(args[0], args[1:]...) //nolint:gosec
cmd.Stdout = stdout
cmd.Stderr = stderr

return
}

// For helm v2, the command is `helm search foo/bar`
// For helm v3, the command is `helm search repo foo/bar`
// For helm v2, the command is `helm search foo/bar`.
// For helm v3, the command is `helm search repo foo/bar`.
func makeSearchCommand(repoName, chartName string) string {
c := "helm search"

Expand Down
1 change: 0 additions & 1 deletion tests/e2e/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
)

const (
// copied from main
defaultChartsContentType = "application/gzip"
)

Expand Down

0 comments on commit 484b321

Please sign in to comment.