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

feat: ignore any directory named vendor #278

Merged
merged 2 commits into from
Jun 5, 2024
Merged

feat: ignore any directory named vendor #278

merged 2 commits into from
Jun 5, 2024

Conversation

CallumNZ
Copy link
Contributor

@CallumNZ CallumNZ commented Jun 3, 2024

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.

@CallumNZ CallumNZ requested a review from wilsonjord June 3, 2024 23:25
@@ -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 {}
Copy link
Contributor

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)/*"

Copy link
Contributor Author

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

Copy link
Contributor

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 {}

@CallumNZ CallumNZ force-pushed the excludeAllVendor branch from 3f6aa4c to e412309 Compare June 5, 2024 03:15
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
@CallumNZ CallumNZ force-pushed the excludeAllVendor branch from e412309 to 69abae6 Compare June 5, 2024 04:06
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
@CallumNZ CallumNZ requested a review from wilsonjord June 5, 2024 20:57
@CallumNZ CallumNZ merged commit be46066 into main Jun 5, 2024
16 checks passed
@CallumNZ CallumNZ deleted the excludeAllVendor branch June 5, 2024 23:46
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