Skip to content

Commit

Permalink
fix(gha): output headers cmd to stdout, not stderr (#80)
Browse files Browse the repository at this point in the history
Previously, the GitHub Actions `::startgroup::` and `::endgroup` directives were being sent to stdout, but all command output from Copywrite was being sent to stderr. This caused an issue that was especially common for the `copywrite headers --plan` command, where the list of files missing headers would be partially included and partially excluded from the logging group.

As a fix I set Cobra up to print to stdout by default, and updated the logger we send to the addlicense module to also use stdout. Ideally, we'd restructure logging entirely within the module, but I'm leaving that for a future PR.
  • Loading branch information
CalebAlbers authored Aug 8, 2023
1 parent a06b017 commit e76cf19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ config, see the "copywrite init" command.`,
// log prefix, e.g. logger.Println("[DEBUG] this is inferred as a debug log")
InferLevels: true,
})
// Redirect output to stdout to match the rest of the command output structure
// Ideally, we would differentiate inside the addlicense run, but in lieu of
// reworking the entire logging functionality there, this at least gets us
// consistency and fixes a race condition when using GitHub Action log groups
stdcliLogger.SetOutput(os.Stdout)

gha.StartGroup("The following files are missing headers:")
err := addlicense.Run(ignoredPatterns, "only", licenseData, "", verbose, plan, []string{"."}, stdcliLogger)
Expand Down
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func init() {
})

rootCmd.PersistentFlags().StringVar(&cfgPath, "config", ".copywrite.hcl", "config file")

// Let's make sure Cobra doesn't default to stderr
rootCmd.SetOut(os.Stdout)
}

func initConfig() {
Expand Down

0 comments on commit e76cf19

Please sign in to comment.