Skip to content
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

Use goimports #86

Merged
merged 1 commit into from
May 16, 2018
Merged

Use goimports #86

merged 1 commit into from
May 16, 2018

Conversation

chrsblck
Copy link

@@ -15,6 +15,10 @@ jobs:
keys:
- v1-external-dep
- v1-dep-{{ checksum "Gopkg.lock" }}

- run: test -z "$(goimports -l -w . | tee /dev/stderr)"
name: Ensure goimports has been run
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goimports command should be configured using the tool pre-commit in a .pre-commit-config.yaml. You can then check it, and any other pre-commit hooks, in the CI build via:

- run: pre-commit install
- run: pre-commit run --all-files

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Did I choose the right place to insert the run, is this where I should add the pre-commit hook?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prob better to put it just above run-go-tests. BTW, I'm not sure if Circle has goimports or pre-commit
installed by default...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check their docs to see if they need to be installed.

Copy link
Author

@chrsblck chrsblck May 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it looks pretty common to create your own hooks repo, e.g., for you all it could be github.com/gruntwork-io/pre-commit.

Or would you rather use another Github users go-imports hook from pre-commit hooks page.

Also, I didn't see many examples of users running pre-commit hooks via their CI (travis or CircleCI).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, now that you mention it, we actually had a repo with pre-commit hooks already at Gruntwork, but they were in a private repo. I've extracted them into an open source one: https://github.com/gruntwork-io/pre-commit. There's a go fmt hook there already. Feel free to use that or add a goimports one.

We enforce pre-commit hooks in CI to make sure people are actually running them. The two commands I listed above show how.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the goimports hook to pre-commit repo.

@chrsblck
Copy link
Author

This requires gruntwork-io/pre-commit#2 to be merged first.

Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, almost there. One last set of changes!

@@ -0,0 +1,4 @@
- repo: github.com/gruntwork-io/pre-commit
sha: HEAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to rev: v0.0.2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, missed this in the last update. Adding that now

@@ -29,6 +30,10 @@ jobs:
paths:
- $HOME/.go_workspace/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/test/vendor

- run: pip install pre-commit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment that says something like, "Fail the build if the pre-commit hooks had not been run."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

- Add gruntwork-io/pre-commit goimport hook
- Update acronyms to have consistent case in `terraform_http_example_test.go`
- https://github.com/golang/go/wiki/CodeReviewComments#initialisms
Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's try this out! Thank you for the PR :)

@brikis98 brikis98 merged commit 1644c75 into gruntwork-io:master May 16, 2018
@brikis98
Copy link
Member

Hm, the build failed with a really odd error:

#!/bin/bash -eo pipefail
pre-commit run --all-files
An error has occurred: InvalidConfigError: 
=====> /home/circleci/project/.pre-commit-config.yaml does not exist
Check the log at /home/circleci/.cache/pre-commit/pre-commit.log
Exited with code 1

@brikis98
Copy link
Member

Oh, I see it. The file has a .yml extension and it wants .yaml. Will fix!

@chrsblck
Copy link
Author

oh crap. I noticed that when running it locally and forgot to fix. I can send up a fix if you want, right now

@brikis98
Copy link
Member

No prob, I just committed the fix :)

@chrsblck
Copy link
Author

BTW, I found this repo because I stumbled upon your talk at HashiConf '17 on YouTube. I really enjoyed it, thanks!

@brikis98
Copy link
Member

OK, we are now in business! Thanks for adding this.

BTW, I found this repo because I stumbled upon your talk at HashiConf '17 on YouTube. I really enjoyed it, thanks!

Ah, I'm very happy to hear that :)

Hope you find Terratest useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants