Skip to content

Commit

Permalink
Feat/improved version checking output (#2862)
Browse files Browse the repository at this point in the history
* add dependency name to output

* reduce repeated code

---------

Co-authored-by: Adam McArthur <46480158+Sharpz7@users.noreply.github.com>
  • Loading branch information
Raajheer1 and Sharpz7 authored Aug 16, 2023
1 parent 969cf19 commit 3656d4f
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 53 deletions.
10 changes: 5 additions & 5 deletions magefiles/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func dockerVersion() (*semver.Version, error) {
return version, nil
}

func constraintCheck(version *semver.Version, versionRequirement string) error {
func constraintCheck(version *semver.Version, versionRequirement string, dependencyName string) error {
constraint, err := semver.NewConstraint(versionRequirement)
if err != nil {
return errors.Errorf("error parsing constraint: %v", err)
}
if !constraint.Check(version) {
return errors.Errorf("found version %v but it failed constraint %v", version, constraint)
return errors.Errorf("found %s version %v but it failed constraint %v", dependencyName, version, constraint)
}
return nil
}
Expand All @@ -90,15 +90,15 @@ func dockerComposeCheck() error {
if err != nil {
return errors.Errorf("error getting version: %v", err)
}
return constraintCheck(version, DOCKER_COMPOSE_VERSION_CONSTRAINT)
return constraintCheck(version, DOCKER_COMPOSE_VERSION_CONSTRAINT, "docker-compose")
}

func dockerBuildxCheck() error {
version, err := dockerBuildxVersion()
if err != nil {
return errors.Errorf("error getting version: %v", err)
}
return constraintCheck(version, DOCKER_BUILDX_VERSION_CONSTRAINT)
return constraintCheck(version, DOCKER_BUILDX_VERSION_CONSTRAINT, "docker-buildx")
}

func dockerCheck() error {
Expand All @@ -111,7 +111,7 @@ func dockerCheck() error {
return errors.Errorf("error parsing constraint: %v", err)
}
if !constraint.Check(version) {
return errors.Errorf("found version %v but it failed constraint %v", version, constraint)
return errors.Errorf("found docker version %v but it failed constraint %v", version, constraint)
}
return nil
}
9 changes: 1 addition & 8 deletions magefiles/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@ func goCheck() error {
if err != nil {
return errors.Errorf("error getting version: %v", err)
}
constraint, err := semver.NewConstraint(GO_VERSION_CONSTRAINT)
if err != nil {
return errors.Errorf("error parsing constraint: %v", err)
}
if !constraint.Check(version) {
return errors.Errorf("found version %v but it failed constraint %v", version, constraint)
}
return nil
return constraintCheck(version, GO_VERSION_CONSTRAINT, "Go")
}

func goEnv(name string) (string, error) {
Expand Down
9 changes: 1 addition & 8 deletions magefiles/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,7 @@ func kindCheck() error {
if err != nil {
return errors.Errorf("error getting version: %v", err)
}
constraint, err := semver.NewConstraint(KIND_VERSION_CONSTRAINT)
if err != nil {
return errors.Errorf("error parsing constraint: %v", err)
}
if !constraint.Check(version) {
return errors.Errorf("found version %v but it failed constraint %v", version, constraint)
}
return nil
return constraintCheck(version, KIND_VERSION_CONSTRAINT, "kind")
}

// Images that need to be available in the Kind cluster,
Expand Down
9 changes: 1 addition & 8 deletions magefiles/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,5 @@ func kubectlCheck() error {
if err != nil {
return errors.Errorf("error getting version: %v", err)
}
constraint, err := semver.NewConstraint(KUBECTL_VERSION_CONSTRAINT)
if err != nil {
return errors.Errorf("error parsing constraint: %v", err)
}
if !constraint.Check(version) {
return errors.Errorf("found version %v but it failed constraint %v", version, constraint)
}
return nil
return constraintCheck(version, KUBECTL_VERSION_CONSTRAINT, "kubectl")
}
9 changes: 1 addition & 8 deletions magefiles/linting.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ func golangciLintCheck() error {
if err != nil {
return errors.Errorf("error getting version: %v", err)
}
constraint, err := semver.NewConstraint(GOLANGCI_LINT_VERSION_CONSTRAINT)
if err != nil {
return errors.Errorf("error parsing constraint: %v", err)
}
if !constraint.Check(version) {
return errors.Errorf("found version %v but it failed constraint %v", version, constraint)
}
return nil
return constraintCheck(version, GOLANGCI_LINT_VERSION_CONSTRAINT, "golangci-lint")
}

// Fixing Linting
Expand Down
9 changes: 1 addition & 8 deletions magefiles/protoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,5 @@ func protocCheck() error {
if err != nil {
return errors.Errorf("error getting version: %v", err)
}
constraint, err := semver.NewConstraint(PROTOC_VERSION_CONSTRAINT)
if err != nil {
return errors.Errorf("error parsing constraint: %v", err)
}
if !constraint.Check(version) {
return errors.Errorf("found version %v but it failed constraint %v", version, constraint)
}
return nil
return constraintCheck(version, PROTOC_VERSION_CONSTRAINT, "protoc")
}
9 changes: 1 addition & 8 deletions magefiles/sqlc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,5 @@ func sqlcCheck() error {
if err != nil {
return errors.Errorf("error getting version: %v", err)
}
constraint, err := semver.NewConstraint(SQLC_VERSION_CONSTRAINT)
if err != nil {
return errors.Errorf("error parsing constraint: %v", err)
}
if !constraint.Check(version) {
return errors.Errorf("found version %v but it failed constraint %v", version, constraint)
}
return nil
return constraintCheck(version, SQLC_VERSION_CONSTRAINT, "sqlc")
}

0 comments on commit 3656d4f

Please sign in to comment.