Skip to content

Commit

Permalink
go: add ignore dirty flag
Browse files Browse the repository at this point in the history
Currently, the go-mkopensource will err out and not generate an output
if it detects that the go.mod/go.sum are dirty. This is the ideal flow
for CI but during the normal dev loop it is common to make changes
to the go.mod and then run a "generate" command.

This flag allows the dirty check to be ignored when added so that it
will generate it normally.

Signed-off-by: Lance Austin <[email protected]>
  • Loading branch information
Lance Austin authored and LanceEa committed Aug 21, 2023
1 parent efaba08 commit d1d8451
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cmd/go-mkopensource/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type CLIArgs struct {
ProprietarySoftware string
GoTarFilename string
Package string
IgnoreDirty bool
}

const (
Expand Down Expand Up @@ -69,6 +70,7 @@ func parseArgs() (*CLIArgs, error) {
argparser.StringVar(&args.UnparsablePackages, "unparsable-packages", "",
"Yaml file containing SPDX License IDs for packages that have valid licenses, but cannot be parsed by this license checker")
argparser.StringVar(&args.ProprietarySoftware, "proprietary-software", "", "Yaml file containing proprietary packages")
argparser.BoolVar(&args.IgnoreDirty, "ignore-dirty", false, "ignore go mod being dirty and generate dependencies")

if err := argparser.Parse(os.Args[1:]); err != nil {
return nil, err
Expand Down Expand Up @@ -457,14 +459,15 @@ func Main(args *CLIArgs) error {
}
}

isDirty, err := isGoModDirty()
if err != nil {
fmt.Fprintf(os.Stderr, "WARNING: could not verify if go.mod or go.sum are dirty: %s.\n", err.Error())
}

if isDirty {
return fmt.Errorf("WARNING: go.mod or go.sum are dirty.\nMake sure that these files are commited with the " +
"license information files to maintain consistency between the dependencies and the license information.")
if !args.IgnoreDirty {
isDirty, err := isGoModDirty()
if err != nil {
fmt.Fprintf(os.Stderr, "WARNING: could not verify if go.mod or go.sum are dirty: %s.\n", err.Error())
}
if isDirty {
return fmt.Errorf("WARNING: go.mod or go.sum are dirty.\nMake sure that these files are commited with the " +
"license information files to maintain consistency between the dependencies and the license information.")
}
}

return nil
Expand Down

0 comments on commit d1d8451

Please sign in to comment.