diff --git a/.circleci/config.yml b/.circleci/config.yml index 87dc8959..a1db5ddf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -101,7 +101,7 @@ commands: jobs: dep: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.16 environment: GO111MODULE: "on" working_directory: /go/src/github.com/hypnoglow/helm-s3 @@ -114,7 +114,7 @@ jobs: - helm-s3 test-unit: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.16 environment: GO111MODULE: "on" GOFLAGS: "-mod=vendor" @@ -126,7 +126,7 @@ jobs: - run: bash <(curl -s https://codecov.io/bash) test-integration-helm-2_17: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.16 environment: GO111MODULE: "on" GOFLAGS: "-mod=vendor" @@ -149,7 +149,7 @@ jobs: helm_version: 2.17.0 test-integration-helm-3_4: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.16 environment: GO111MODULE: "on" GOFLAGS: "-mod=vendor" @@ -172,7 +172,7 @@ jobs: helm_version: 3.4.2 test-integration-helm-3_5: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.16 environment: GO111MODULE: "on" GOFLAGS: "-mod=vendor" @@ -225,7 +225,7 @@ jobs: helm plugin install https://github.com/hypnoglow/helm-s3.git --version ${version} release: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.16 environment: GO111MODULE: "on" GOFLAGS: "-mod=vendor" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..e58b675a --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,41 @@ +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' + + - name: Download dependencies + run: | + go mod download + + - name: Run tests + run: | + go test -v $(go list ./... | grep -v e2e) + + - name: Run linters + uses: golangci/golangci-lint-action@v3 + with: + version: v1.31 + args: --verbose + + - name: Build + run: | + go build -v -o ./bin/helm-s3 ./cmd/helms3 diff --git a/.golangci.yml b/.golangci.yml index b045e5ac..2e9e5db9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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" diff --git a/Makefile b/Makefile index 7d681412..ac2b5861 100644 --- a/Makefile +++ b/Makefile @@ -35,3 +35,7 @@ test-e2e: .PHONY: test-e2e-local test-e2e-local: @./hack/test-e2e-local.sh + +.PHONY: lint +lint: + @golangci-lint run diff --git a/cmd/helms3/main.go b/cmd/helms3/main.go index b0abd765..eb56d6d6 100644 --- a/cmd/helms3/main.go +++ b/cmd/helms3/main.go @@ -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 } @@ -147,7 +150,6 @@ func main() { uri: *initURI, acl: *acl, } - defer fmt.Printf("Initialized empty repository at %s\n", *initURI) case actionPush: act = pushAction{ @@ -167,7 +169,6 @@ func main() { acl: *acl, relative: *reindexRelative, } - defer fmt.Printf("Repository %s was successfully reindexed.\n", *reindexTargetRepository) case actionDelete: act = deleteAction{ @@ -181,9 +182,9 @@ func main() { } ctx, cancel := context.WithTimeout(context.Background(), *timeout) - defer cancel() - err := act.Run(ctx) + cancel() + switch err { case nil: case ErrChartExists: @@ -191,6 +192,13 @@ func main() { 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 { diff --git a/cmd/helms3/push.go b/cmd/helms3/push.go index 1dcb6db7..9719a356 100644 --- a/cmd/helms3/push.go +++ b/cmd/helms3/push.go @@ -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 { diff --git a/go.mod b/go.mod index 1c75726a..dedada7e 100644 --- a/go.mod +++ b/go.mod @@ -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 ( diff --git a/go.sum b/go.sum index 4fcff16f..1eb71233 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= @@ -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= diff --git a/internal/awss3/storage.go b/internal/awss3/storage.go index 1ad588a0..9e01df70 100644 --- a/internal/awss3/storage.go +++ b/internal/awss3/storage.go @@ -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 @@ -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 == "" { @@ -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) diff --git a/internal/awsutil/session.go b/internal/awsutil/session.go index b3f2a086..bc197796 100644 --- a/internal/awsutil/session.go +++ b/internal/awsutil/session.go @@ -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" ) diff --git a/internal/helmutil/index_v3.go b/internal/helmutil/index_v3.go index d95a6ea4..eb171bf0 100644 --- a/internal/helmutil/index_v3.go +++ b/internal/helmutil/index_v3.go @@ -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" ) @@ -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 } diff --git a/internal/helmutil/repo_entry_v3_test.go b/internal/helmutil/repo_entry_v3_test.go index 7e4f902a..4a530073 100644 --- a/internal/helmutil/repo_entry_v3_test.go +++ b/internal/helmutil/repo_entry_v3_test.go @@ -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" ) diff --git a/tests/e2e/main_test.go b/tests/e2e/main_test.go index 62db76d9..b18e2035 100644 --- a/tests/e2e/main_test.go +++ b/tests/e2e/main_test.go @@ -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() { @@ -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) @@ -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" diff --git a/tests/e2e/push_test.go b/tests/e2e/push_test.go index c7ef9acf..ff222b23 100644 --- a/tests/e2e/push_test.go +++ b/tests/e2e/push_test.go @@ -18,7 +18,6 @@ import ( ) const ( - // copied from main defaultChartsContentType = "application/gzip" )