Skip to content

Commit

Permalink
added check between pkg version and git tag for consistency
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Kumar <abhishek22512@gmail.com>
  • Loading branch information
octonawish-akcodes committed Jan 25, 2024
1 parent 194168a commit 6b2e82f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/cmd/cmd_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ func KpmAdd(c *cli.Context, kpmcli *client.KpmClient) error {
if err != nil {
return err
}

// Check git tag consistency if git options are provided
if addOpts.RegistryOpts.Git != nil && addOpts.RegistryOpts.Git.Tag != "" {
consistencyCheck := checkGitTagConsistency(kclPkg, addOpts.RegistryOpts.Git.Tag)
if consistencyCheck != nil {
reporter.Report(consistencyCheck)
}
}

return nil
}

Expand Down Expand Up @@ -257,3 +266,13 @@ func parseOciPkgNameAndVersion(s string) (string, string, error) {

return parts[0], parts[1], nil
}

func checkGitTagConsistency(kclPkg *pkg.KclPkg, gitTag string) *reporter.KpmEvent {
if kclPkg.GetPkgVersion() != gitTag {
return reporter.NewErrorEvent(
reporter.Bug,
fmt.Errorf("Git tag '%s' is inconsistent with the version field '%s' in kcl.mod", gitTag, kclPkg.GetPkgVersion()),
)
}
return nil
}

0 comments on commit 6b2e82f

Please sign in to comment.