diff --git a/cmd/repo-health-checker/main.go b/cmd/repo-health-checker/main.go index 65b90dd..951d76c 100644 --- a/cmd/repo-health-checker/main.go +++ b/cmd/repo-health-checker/main.go @@ -39,7 +39,7 @@ var Version string // Generally, err is used for runtime errors, and checkRes is used for the result of the checks. func main() { - var gitWhitelist, metaFile []string + var gitWhitelist, metaFile, releaseTag []string showVersion := flag.Bool("version", false, "print current version") checkRelease := flag.Bool("checkRelease", true, "trigger release check") rootDir := flag.String("root", "", "") @@ -51,6 +51,7 @@ func main() { checkFileSumList := flag.String("checkFileSumList", "", "Comma-separated list of expected checksums.") parseMultiValueFlag(&gitWhitelist, "whitelist", "") parseMultiValueFlag(&metaFile, "meta", "") + parseMultiValueFlag(&releaseTag, "releaseTag", "Recommended tags") flag.Parse() if *showVersion { fmt.Println(Version) @@ -78,7 +79,7 @@ func main() { if err != nil { fmt.Printf("### Non-ASCII Characters Commit Message Check Failed:\n%s\n", err.Error()) } - err = healthcheck.CheckTags(*rootDir, *checkRelease) + err = healthcheck.CheckTags(*rootDir, *checkRelease, releaseTag) if err != nil { fmt.Printf("### Release Tag Check Failed:\n%s\n", err.Error()) } diff --git a/pkg/healthcheck/tag.go b/pkg/healthcheck/tag.go index cab07ee..6ee557f 100644 --- a/pkg/healthcheck/tag.go +++ b/pkg/healthcheck/tag.go @@ -61,7 +61,37 @@ func getTagsFromRepo(repoPath string) ([]string, error) { return tags, nil } -func CheckTags(repoPath string, skip bool) error { +// INFO: check whether release tag consistent with last commit msg scope +func checkConsist(tags []string, target string) (err error) { + found := false + for _, tag := range tags { + if tag == target { + found = true + break + } + } + if !found { + return fmt.Errorf("Inconsistent release tag with scope in '%s' or missing release tags. Please use '%s'.", strings.Join(tags, "', '"), target) + } + return nil +} + +// INFO: check whether release tag follow the tag list we give +func checkStyle(target string, recommendTag []string) (err error) { + found := false + for _, tag := range recommendTag { + if tag == target { + found = true + break + } + } + if !found { + return fmt.Errorf("Release tag '%s' doesn't match recommended tag list. Please use one of '%s'.", target, strings.Join(recommendTag, "', '")) + } + return nil +} + +func CheckTags(repoPath string, skip bool, recommendTag []string) error { if skip { return nil } @@ -74,15 +104,13 @@ func CheckTags(repoPath string, skip bool) error { if err != nil { return fmt.Errorf("error getting tag from msg scope: %v", err) } - found := false - for _, tag := range tags { - if tag == target { - found = true - break - } + err = checkConsist(tags, target) + if err != nil { + return err } - if !found { - return fmt.Errorf("Wrong release tag in '%s' or missing release tags. Please use '%s'.", strings.Join(tags, "', '"), target) + err = checkStyle(target, recommendTag) + if err != nil { + return err } return nil }