Skip to content

Commit

Permalink
Merge pull request #95 from jenkins-x-plugins/go1-22
Browse files Browse the repository at this point in the history
chore: upgrade to go 1.22
  • Loading branch information
jenkins-x-bot authored Jul 5, 2024
2 parents 1598df0 + 9b34ccb commit a5d2541
Show file tree
Hide file tree
Showing 22 changed files with 1,336 additions and 1,842 deletions.
57 changes: 18 additions & 39 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
linters-settings:
depguard:
list-type: blacklist
packages:
- github.com/jenkins-x/jx/v2/pkg/log/
- github.com/satori/go.uuid
- github.com/pborman/uuid
packages-with-error-message:
- github.com/jenkins-x/jx/v2/pkg/log/: "use jenkins-x/jx-logging instead"
- github.com/satori/go.uuid: "use github.com/google/uuid instead"
- github.com/pborman/uuid: "use github.com/google/uuid instead"
rules:
# Name of a rule.
Main:
list-mode: lax
deny:
- pkg: github.com/jenkins-x/jx/v2/pkg/log/
desc: "use jenkins-x/jx-logging instead"
- pkg: github.com/satori/go.uuid
desc: "use github.com/google/uuid instead"
- pkg: github.com/pborman/uuid
desc: "use github.com/google/uuid instead"
dupl:
threshold: 100
exhaustive:
Expand Down Expand Up @@ -37,17 +39,14 @@ linters-settings:
gocyclo:
min-complexity: 15
goimports: {}
golint:
min-confidence: 0
revive:
confidence: 0
gofmt:
simplify: true
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: [argument, case, condition, return]
mnd:
# don't include the "operation" and "assign"
checks: [argument, case, condition, return]
govet:
check-shadowing: true
settings:
printf:
funcs:
Expand All @@ -58,11 +57,8 @@ linters-settings:
- (github.com/jenkins-x/jx-logging/v3/pkg/log/Logger()).Fatalf
lll:
line-length: 140
maligned:
suggest-new: true
misspell: {}
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
Expand Down Expand Up @@ -93,26 +89,9 @@ linters:
- gocritic
- govet
issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# - path: _test\.go
# linters:
# - gomnd
# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"
exclude:
- 'shadow: declaration of "err" shadows declaration at'
max-same-issues: 0

exclude-dirs:
- cmd/docs
run:
timeout: 30m
skip-dirs:
- cmd/docs
# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.42.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
444 changes: 252 additions & 192 deletions go.mod

Large diffs are not rendered by default.

2,345 changes: 893 additions & 1,452 deletions go.sum

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions pkg/argocd/app_version.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package argocd

import (
"fmt"

"github.com/jenkins-x-plugins/jx-updatebot/pkg/gitops"
"github.com/jenkins-x/jx-helpers/v3/pkg/kyamls"
"github.com/jenkins-x/jx-logging/v3/pkg/log"
"github.com/pkg/errors"

"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand Down Expand Up @@ -34,7 +36,7 @@ func GetRepoURL(node *yaml.RNode, path string) string {

annotation := kyamls.GetStringField(node, path, "metadata", "annotations", "gitops.jenkins-x.io/sourceRepoUrl")
repoURL := kyamls.GetStringField(node, path, "spec", "source", "repoURL")
if len(annotation) > 0 {
if annotation != "" {
return annotation
}
if repoURL != "" {
Expand All @@ -56,7 +58,7 @@ func GetAppVersion(node *yaml.RNode, path string) *AppVersion {
func SetAppSetVersion(node *yaml.RNode, path, version string) error {
err := node.PipeE(yaml.LookupCreate(yaml.ScalarNode, "spec", "template", "spec", "source", "targetRevision"), yaml.FieldSetter{StringValue: version})
if err != nil {
return errors.Wrapf(err, "failed to set spec.generators.template.source.targetRevision to %s", version)
return fmt.Errorf("failed to set spec.generators.template.source.targetRevision to %s: %w", version, err)
}
log.Logger().Debugf("modified the version in file %s to %s", path, version)
return nil
Expand All @@ -66,7 +68,7 @@ func SetAppSetVersion(node *yaml.RNode, path, version string) error {
func SetAppVersion(node *yaml.RNode, path, version string) error {
err := node.PipeE(yaml.LookupCreate(yaml.ScalarNode, "spec", "source", "targetRevision"), yaml.FieldSetter{StringValue: version})
if err != nil {
return errors.Wrapf(err, "failed to set spec.source.targetRevision to %s", version)
return fmt.Errorf("failed to set spec.source.targetRevision to %s: %w", version, err)
}
log.Logger().Debugf("modified the version in file %s to %s", path, version)
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewCmdArgo() *cobra.Command {
Use: "argo",
Aliases: []string{"argocd"},
Short: "Commands for working with ArgoCD git repositories",
Run: func(command *cobra.Command, args []string) {
Run: func(command *cobra.Command, _ []string) {
err := command.Help()
if err != nil {
log.Logger().Errorf(err.Error())
Expand Down
19 changes: 10 additions & 9 deletions pkg/cmd/argo/promote/promote.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package promote

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand All @@ -15,7 +16,7 @@ import (
"github.com/jenkins-x/jx-helpers/v3/pkg/cobras/helper"
"github.com/jenkins-x/jx-helpers/v3/pkg/kube/jxclient"
"github.com/jenkins-x/jx-helpers/v3/pkg/options"
"github.com/pkg/errors"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -62,7 +63,7 @@ func NewCmdArgoPromote() (*cobra.Command, *Options) {
Short: "Promotes a new Application or ApplicationSet version in an ArgoCD git repository",
Long: cmdLong,
Example: cmdExample,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
err := o.Run()
helper.CheckErr(err)
},
Expand Down Expand Up @@ -91,12 +92,12 @@ func NewCmdArgoPromote() (*cobra.Command, *Options) {
func (o *Options) Run() error {
err := o.Validate()
if err != nil {
return errors.Wrapf(err, "failed to validate options")
return fmt.Errorf("failed to validate options: %w", err)
}

err = o.upgradeRepository(o.TargetGitURL)
if err != nil {
return errors.Wrapf(err, "failed to create Pull Request on repository %s", o.TargetGitURL)
return fmt.Errorf("failed to create Pull Request on repository %s: %w", o.TargetGitURL, err)
}
return nil
}
Expand All @@ -110,7 +111,7 @@ func (o *Options) Validate() error {
if o.SourceGitURL == "" {
o.SourceGitURL, err = gitdiscovery.FindGitURLFromDir(o.Dir, true)
if err != nil {
return errors.Wrapf(err, "failed to detect the source repo git URL")
return fmt.Errorf("failed to detect the source repo git URL: %w", err)
}
o.SourceGitURL = stringhelpers.SanitizeURL(o.SourceGitURL)

Expand All @@ -126,12 +127,12 @@ func (o *Options) Validate() error {
}
exists, err := files.FileExists(o.VersionFile)
if err != nil {
return errors.Wrapf(err, "failed to check for file %s", o.VersionFile)
return fmt.Errorf("failed to check for file %s: %w", o.VersionFile, err)
}
if exists {
data, err := os.ReadFile(o.VersionFile)
if err != nil {
return errors.Wrapf(err, "failed to read version file %s", o.VersionFile)
return fmt.Errorf("failed to read version file %s: %w", o.VersionFile, err)
}
o.Version = strings.TrimSpace(string(data))
} else {
Expand All @@ -150,7 +151,7 @@ func (o *Options) Validate() error {

o.EnvironmentPullRequestOptions.JXClient, o.EnvironmentPullRequestOptions.Namespace, err = jxclient.LazyCreateJXClientAndNamespace(o.EnvironmentPullRequestOptions.JXClient, o.EnvironmentPullRequestOptions.Namespace)
if err != nil {
return errors.Wrapf(err, "failed to create jx client")
return fmt.Errorf("failed to create jx client: %w", err)
}

// lazy create the git client
Expand All @@ -173,7 +174,7 @@ func (o *Options) upgradeRepository(gitURL string) error {

_, err := o.EnvironmentPullRequestOptions.Create(gitURL, "", o.Labels, o.AutoMerge)
if err != nil {
return errors.Wrapf(err, "failed to create Pull Request on repository %s", gitURL)
return fmt.Errorf("failed to create Pull Request on repository %s: %w", gitURL, err)
}
return nil
}
22 changes: 12 additions & 10 deletions pkg/cmd/argo/sync/sync.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sync

import (
"fmt"

"github.com/jenkins-x-plugins/jx-promote/pkg/environments"
"github.com/jenkins-x-plugins/jx-updatebot/pkg/argocd"
"github.com/jenkins-x-plugins/jx-updatebot/pkg/gitops"
Expand All @@ -14,7 +16,7 @@ import (
"github.com/jenkins-x/jx-helpers/v3/pkg/options"
"github.com/jenkins-x/jx-helpers/v3/pkg/versionstream"
"github.com/jenkins-x/jx-logging/v3/pkg/log"
"github.com/pkg/errors"

"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
Expand Down Expand Up @@ -72,7 +74,7 @@ func NewCmdArgoSync() (*cobra.Command, *Options) {
Short: "Synchronizes some or all applications in an ArgoCD git repository to reduce version drift",
Long: cmdLong,
Example: cmdExample,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
err := o.Run()
helper.CheckErr(err)
},
Expand Down Expand Up @@ -109,7 +111,7 @@ func (o *Options) Validate() error {
}
err := o.BaseOptions.Validate()
if err != nil {
return errors.Wrapf(err, "failed to validate base options")
return fmt.Errorf("failed to validate base options: %w", err)
}
if o.Input == nil {
o.Input = inputfactory.NewInput(&o.BaseOptions)
Expand All @@ -130,10 +132,10 @@ func (o *Options) Validate() error {
} else {
o.Source.Dir, err = gitclient.CloneToDir(o.Git(), sourceGitURL, "")
if err != nil {
return errors.Wrapf(err, "failed to clone source cluster %s", sourceGitURL)
return fmt.Errorf("failed to clone source cluster %s: %w", sourceGitURL, err)
}
if o.Source.Dir == "" {
return errors.Errorf("failed to clone the source repository to a directory %s", sourceGitURL)
return fmt.Errorf("failed to clone the source repository to a directory %s", sourceGitURL)
}
}
}
Expand All @@ -144,12 +146,12 @@ func (o *Options) Validate() error {
func (o *Options) Run() error {
err := o.Validate()
if err != nil {
return errors.Wrapf(err, "failed to validate options")
return fmt.Errorf("failed to validate options: %w", err)
}

gitURL := o.Target.GitCloneURL
if gitURL == "" {
return errors.Errorf("no target git clone URL")
return fmt.Errorf("no target git clone URL")
}

// lets clear the branch name so we create a new one each time in a loop
Expand All @@ -166,7 +168,7 @@ func (o *Options) Run() error {

_, err = o.EnvironmentPullRequestOptions.Create(gitURL, "", o.Labels, o.AutoMerge)
if err != nil {
return errors.Wrapf(err, "failed to create Pull Request on repository %s", gitURL)
return fmt.Errorf("failed to create Pull Request on repository %s: %w", gitURL, err)
}
return nil
}
Expand All @@ -175,12 +177,12 @@ func (o *Options) Run() error {
func (o *Options) SyncVersions(sourceDir, targetDir string) error {
err := o.findSourceApplications(sourceDir)
if err != nil {
return errors.Wrapf(err, "failed to find source Applications")
return fmt.Errorf("failed to find source Applications: %w", err)
}

err = o.syncAppVersions(targetDir)
if err != nil {
return errors.Wrapf(err, "failed to modify target Applications")
return fmt.Errorf("failed to modify target Applications: %w", err)
}
return nil
}
Expand Down
Loading

0 comments on commit a5d2541

Please sign in to comment.