Ensure Go source files are formatted correctly for secure projects
Problem to solve
If a developer hasn't properly configured their editor, code can be committed to the repo which isn't formatted correctly using goimports
. For example, this code was recently committed which isn't properly formatted, despite being called out in the MR in this comment. We need to programmatically enforce this in order to prevent this from happening in the future.
Implementation plan
-
Add a new job in the test stage
of ci-templates/includes-dev/go.yml to automatically rungoimports
, and fail if a non-zero exit code is returned:goimports: extends: .go script: - goimports -w -local gitlab.com/gitlab-org . - git diff --exit-code .
-
Manually test to ensure the above job works as expected
Intended users
User experience goal
Developers will be alerted if they attempt to commit improperly formatted Go code.
Further details
See this discussion for more details
What does success look like, and how can we measure that?
If a developer creates an MR with improperly formatted Go code, the pipeline will fail.
Is this a cross-stage feature?
Yes, it affects all secure projects