diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-05-03 18:34:38 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-05-03 18:43:18 +0200 |
commit | 9166894c696582ee37893ce92a694ba227744fa0 (patch) | |
tree | 8b4c9ffa20de8a4a484c0a427fc74b5c22634994 /vendor/github.com/vbatts/git-validation/main.go | |
parent | 1e0c50df38ff955011f7ebb83a0268f3f1cd2841 (diff) | |
download | podman-9166894c696582ee37893ce92a694ba227744fa0.tar.gz podman-9166894c696582ee37893ce92a694ba227744fa0.tar.bz2 podman-9166894c696582ee37893ce92a694ba227744fa0.zip |
vendor test dependencies instead of installing via network
We can vendor the test dependencies such as go-md2man, git-validation
and goimports. This allows us to always install the same version as
specified in go.mod. Also we do not rely on a network connection for
this.
The advantage with this method is that dependabot will also update the
dependencies for us and we do not have to hardcode versions in the
Makefile.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'vendor/github.com/vbatts/git-validation/main.go')
-rw-r--r-- | vendor/github.com/vbatts/git-validation/main.go | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/vendor/github.com/vbatts/git-validation/main.go b/vendor/github.com/vbatts/git-validation/main.go new file mode 100644 index 000000000..cd5f271a4 --- /dev/null +++ b/vendor/github.com/vbatts/git-validation/main.go @@ -0,0 +1,92 @@ +package main + +import ( + "flag" + "fmt" + "log" + "os" + "strings" + + _ "github.com/vbatts/git-validation/rules/danglingwhitespace" + _ "github.com/vbatts/git-validation/rules/dco" + _ "github.com/vbatts/git-validation/rules/messageregexp" + _ "github.com/vbatts/git-validation/rules/shortsubject" + "github.com/vbatts/git-validation/validate" +) + +var ( + flCommitRange = flag.String("range", "", "use this commit range instead (implies -no-travis)") + flListRules = flag.Bool("list-rules", false, "list the rules registered") + flRun = flag.String("run", "", "comma delimited list of rules to run. Defaults to all.") + flVerbose = flag.Bool("v", false, "verbose") + flDebug = flag.Bool("D", false, "debug output") + flQuiet = flag.Bool("q", false, "less output") + flDir = flag.String("d", ".", "git directory to validate from") + flNoTravis = flag.Bool("no-travis", false, "disables travis environment checks (when env TRAVIS=true is set)") + flTravisPROnly = flag.Bool("travis-pr-only", true, "when on travis, only run validations if the CI-Build is checking pull-request build") +) + +func main() { + flag.Parse() + + if *flDebug { + os.Setenv("DEBUG", "1") + } + if *flQuiet { + os.Setenv("QUIET", "1") + } + + if *flListRules { + for _, r := range validate.RegisteredRules { + fmt.Printf("%q -- %s\n", r.Name, r.Description) + } + return + } + + if *flTravisPROnly && strings.ToLower(os.Getenv("TRAVIS_PULL_REQUEST")) == "false" { + fmt.Printf("only to check travis PR builds and this not a PR build. yielding.\n") + return + } + + // rules to be used + var rules []validate.Rule + for _, r := range validate.RegisteredRules { + // only those that are Default + if r.Default { + rules = append(rules, r) + } + } + // or reduce the set being run to what the user provided + if *flRun != "" { + rules = validate.FilterRules(validate.RegisteredRules, validate.SanitizeFilters(*flRun)) + } + if os.Getenv("DEBUG") != "" { + log.Printf("%#v", rules) // XXX maybe reduce this list + } + + var commitRange = *flCommitRange + if commitRange == "" { + if strings.ToLower(os.Getenv("TRAVIS")) == "true" && !*flNoTravis { + if os.Getenv("TRAVIS_COMMIT_RANGE") != "" { + commitRange = strings.Replace(os.Getenv("TRAVIS_COMMIT_RANGE"), "...", "..", 1) + } else if os.Getenv("TRAVIS_COMMIT") != "" { + commitRange = os.Getenv("TRAVIS_COMMIT") + } + } + } + + runner, err := validate.NewRunner(*flDir, rules, commitRange, *flVerbose) + if err != nil { + log.Fatal(err) + } + + if err := runner.Run(); err != nil { + log.Fatal(err) + } + _, fail := runner.Results.PassFail() + if fail > 0 { + fmt.Printf("%d commits to fix\n", fail) + os.Exit(1) + } + +} |