-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: ignore any directory named vendor #278
Conversation
@@ -19,7 +19,7 @@ jobs: | |||
id: goimports | |||
run: | | |||
go install golang.org/x/tools/cmd/goimports@latest | |||
find . -type f -name '*.go' -not -path './vendor/*' | xargs -I{} goimports -w {} | |||
find . -type f -name '*.go' -not -path '*/vendor/*' | xargs -I{} goimports -w {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want full pedantic brownie points?
The go mod vendor command constructs a directory named vendor
go mod vendor also creates the file vendor/modules.txt
find . -type f -name '*.go' -not -path "$(find . -type d -name vendor -exec test -e '{}'/modules.txt \; -print)/*"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
god you know i love brownie points
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CallumNZ the full one-liner is this:
eval "find . -type f -name '*.go'" $(for i in $(find . -type d -name vendor -exec test -e '{}'/modules.txt \; -print); do echo -n "-not -path \"$i/*\" "; done) | xargs -I{} goimports -w {}
You can make this a little more readable:
go install golang.org/x/tools/cmd/goimports@latest
BASE_CMD="find . -type f -name '*.go'"
VENDOR_PATH_ARGS=$(for i in $(find . -type d -name vendor -exec test -e '{}'/modules.txt \; -print); do echo -n "-not -path \"$i/*\" "; done)
eval $BASE_CMD $VENDOR_PATH_ARGS | xargs -I{} goimports -w {}
3f6aa4c
to
e412309
Compare
For goimports reusable workflow, ignore any directory named vendor. This allows edge cases where a repository has an embedded project, for example dapper inside fits
e412309
to
69abae6
Compare
The vendor folder created by the go toolchain always includes a modules.txt file, so we can discern exactly which vendor folders to ignore by testing for the presence of a modules.txt file
For goimports reusable workflow, ignore any directory named vendor. This allows edge cases where a repository has an embedded project, for example dapper inside fits.