Skip to content

Automatically create output directory for reports #3623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
james-johnston-thumbtack opened this issue Feb 21, 2023 · 1 comment · Fixed by #4524
Closed

Automatically create output directory for reports #3623

james-johnston-thumbtack opened this issue Feb 21, 2023 · 1 comment · Fixed by #4524
Labels
area: output Related to issue output enhancement New feature or improvement

Comments

@james-johnston-thumbtack

Your feature request related to a problem? Please describe.

We have a configuration that looks like this to write a JUnit report to a reports/ output directory that is normally ignored with a direction to ignore it in the top-level .gitignore file.

output:
  format: colored-line-number,junit-xml:reports/junit/lint.xml

If this reports/ directory does not exist, then golangci-lint will fail with:

level=error msg="Running error: can't create output for reports/junit/lint.xml: open reports/junit/lint.xml: no such file or directory"

Describe the solution you'd like.

I would have expected the output directory to be created, rather than failing with an error.

Describe alternatives you've considered.

We can work around the problem by committing some placeholder files in the reports directory, and then setting up .gitignore files to ignore the individual files in this output directory. This forces git to create that output directory upon repo checkout.

But this is less ideal because it means that cleaning the repo is more complicated; you can't just delete the reports/ directory any more because some of those files (the placeholder files) are committed & thus result in dirty repo status. It also makes for more work managing the .gitignore files.

Additional context.

The key location to change is probably here:

func (e *Executor) createWriter(path string) (io.Writer, bool, error) {
if path == "" || path == "stdout" {
return logutils.StdOut, false, nil
}
if path == "stderr" {
return logutils.StdErr, false, nil
}
f, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, defaultFileMode)
if err != nil {
return nil, false, err
}
return f, true, nil
}

If this function creates the directory hierarchy before attempting to open the file, then the problem can be avoided.

@james-johnston-thumbtack james-johnston-thumbtack added the enhancement New feature or improvement label Feb 21, 2023
@fatelei
Copy link

fatelei commented Feb 22, 2023

i want to handle this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: output Related to issue output enhancement New feature or improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants