-
Notifications
You must be signed in to change notification settings - Fork 633
chore: install pinned versions of package #4147
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
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6b8521e
chore: install pinned versions of package
ogzhanolguncu 4de6753
chore: change version
ogzhanolguncu 8fdfa71
Merge branch 'main' into ENG-2100
Flo4604 daa5bbf
Merge branch 'main' into ENG-2100
Flo4604 4a6a86e
feat: add proper go tooling
ogzhanolguncu ba8fc87
fix: update readme
ogzhanolguncu 5308781
chore: remove gobin
ogzhanolguncu 29b90db
Merge branch 'main' of github.com:unkeyed/unkey into ENG-2100
ogzhanolguncu 2b1604d
chore: run tidy
ogzhanolguncu fdb02ef
fix: missing make setup
ogzhanolguncu 8c4512b
chore: merge
ogzhanolguncu d7eeb2e
fix: conflict
ogzhanolguncu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,3 +27,7 @@ deployment/data/* | |
| deployment/config/depot.json | ||
| metald.db | ||
| bin/ | ||
|
|
||
|
|
||
| go.work | ||
| go.work.sum | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| package db | ||
|
|
||
| //go:generate go build -o ./plugins/dist/bulk-insert ./plugins/bulk-insert | ||
| //go:generate sqlc generate | ||
| //go:generate go tool sqlc generate | ||
| // we copy all of the relevant bits into query.go and don't want the default | ||
| // exports that get generated | ||
| //go:generate rm delete_me.go |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| package db | ||
|
|
||
| //go:generate sqlc generate | ||
| //go:generate go tool sqlc generate | ||
| // we copy all of the relevant bits into query.go and don't want the default | ||
| // exports that get generated | ||
| //go:generate rm delete_me.go |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # Tools Management | ||
|
|
||
| This project uses Go 1.24+'s native `tool` directive to manage development tools like `buf`, `golangci-lint`, `sqlc`, `oapi-codegen` and `protoc-gen-go-restate`. | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Separate Tools Module (`tools/go.mod`) | ||
|
|
||
| We maintain a completely separate Go module for tools: | ||
|
Flo4604 marked this conversation as resolved.
|
||
|
|
||
| ``` | ||
| repo/ | ||
| ├── go.mod # Main project dependencies | ||
| └── tools/ | ||
| ├── go.mod # Tool dependencies (isolated) | ||
| └── go.sum | ||
| ``` | ||
|
|
||
| **Why separate?** | ||
|
|
||
| - **Dependency isolation** - Tools often have heavy dependencies (linters pull in analysis libraries, buf needs protobuf tooling, etc.). We don't want these bleeding into our production code. | ||
| - **Different version requirements** - A tool might need an older version of a shared dependency that conflicts with our main module. | ||
| - **Cleaner main module** - Our primary `go.mod` only contains actual runtime and test dependencies. | ||
| - **Easier auditing** - Security scanning and dependency reviews focus on what actually ships, not build tools. | ||
|
|
||
| ### Go Workspace (`go.work`) | ||
|
|
||
| The workspace ties the main module and tools module together: | ||
|
|
||
| ```go | ||
| go 1.25.1 | ||
|
|
||
| use ( | ||
| . // Main module | ||
| ./tools // Tools module | ||
| ) | ||
| ``` | ||
|
|
||
| **Why a workspace?** | ||
|
|
||
| - **Unified tool access** - Run `go tool <name>` from anywhere in the repo without specifying which module | ||
| - **No `-modfile`** - Without workspace, you'd need `go tool -modfile=tools/go.mod <name>` every time | ||
| - **Multi-module development** - If you're working on both the main code and tool configurations, the workspace makes it seamless | ||
|
|
||
| ## Setup | ||
|
|
||
| First-time setup: | ||
|
|
||
| ```sh | ||
| make install # Creates workspace and installs tools | ||
| ``` | ||
|
|
||
| Or the workspace is auto-created when you run any tool-dependent command: | ||
|
|
||
| ```sh | ||
| make fmt # Auto-creates workspace if needed | ||
| make generate # Auto-creates workspace if needed | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| Run tools via `go tool`: | ||
|
|
||
| ```sh | ||
| go tool buf generate | ||
| go tool golangci-lint run | ||
| go tool sqlc generate | ||
| go tool protoc-gen-go-restate --version | ||
| ``` | ||
|
|
||
| ## Updating Tools | ||
|
|
||
| To update a tool: | ||
|
|
||
| ```sh | ||
| cd tools | ||
| go get -tool github.com/bufbuild/buf/cmd/buf@v1.60.0 | ||
| cd .. | ||
| ``` | ||
|
|
||
| The new version is locked in `tools/go.mod` and `tools/go.sum`, ensuring everyone uses the same version. | ||
|
|
||
| ## Maintenance Guide | ||
|
|
||
| ### Adding a New Tool | ||
|
|
||
| ```sh | ||
| cd tools | ||
| go get -tool github.com/example/tool/cmd/tool@v1.2.3 | ||
| ``` | ||
|
|
||
| ### Critical: Always Use `go tool` Prefix | ||
|
|
||
| **❌ Wrong - uses globally installed version:** | ||
|
|
||
| ```go | ||
| //go:generate sqlc generate | ||
| //go:generate buf generate | ||
| ``` | ||
|
|
||
| ```makefile | ||
| generate: | ||
| sqlc generate | ||
| buf generate | ||
| ``` | ||
|
|
||
| **✅ Correct - uses version from tools/go.mod:** | ||
|
|
||
| ```go | ||
| //go:generate go tool sqlc generate | ||
| //go:generate go tool buf generate | ||
| ``` | ||
|
|
||
| ```makefile | ||
| generate: | ||
| go tool sqlc generate | ||
| go tool buf generate | ||
| ``` | ||
|
|
||
| ### How to Verify You're Using the Right Version | ||
|
|
||
| ```sh | ||
| # Check what version will be used | ||
| go tool sqlc version # Uses tools/go.mod version | ||
| sqlc version # Uses global install | ||
| ``` | ||
|
|
||
| ### Common Mistakes to Avoid | ||
|
|
||
| 1. **Forgetting `go tool` prefix in `//go:generate` directives** | ||
|
|
||
| - Always use `go tool <name>` instead of just `<name>` | ||
| - Search codebase: `grep -r "//go:generate" --include="*.go"` and verify all tool calls have `go tool` prefix | ||
|
|
||
| 2. **Running tools directly from command line** | ||
|
|
||
| - Use `go tool sqlc generate` not `sqlc generate` | ||
| - Update your muscle memory and shell aliases | ||
|
ogzhanolguncu marked this conversation as resolved.
|
||
|
|
||
| 3. **Forgetting to commit `tools/go.sum`** | ||
| - Always commit both `tools/go.mod` and `tools/go.sum` | ||
| - They work together to ensure reproducible builds | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.