dominikbraun / timetrace

A simple CLI for tracking your working time.
Apache License 2.0
679 stars 75 forks source link

CI: Include list of files if `goimports` returns an error #122

Closed dominikbraun closed 2 years ago

dominikbraun commented 3 years ago

The CI job for checking the Go imports currently runs ! goimports -l . | read.

https://github.com/dominikbraun/timetrace/blob/b4b7c153e92cd869ac34e92fedc0d6a16460862c/.circleci/config.yml#L25-L27

This is a kind of hacky way to exit with status code 1 if goimports -l . lists files that are not imported correctly.

Explanation: goimports -l . lists all files that aren't formatted correctly, without modifying those files. This output is piped to read which fails if there is no input - e.g. if there are no invalid files listed by goimports. But since the job should file if read doesn't fail, this expression is negated with !.

If the job fails, i.e. the exit code is 1, the affected files that have to be formatted properly should be listed. The easiest way to do this should be to store the output of goimports -l . or just run it again if the read expression doesn't fail.