-
Notifications
You must be signed in to change notification settings - Fork 50
add go mod require & replace support #868
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
base: main
Are you sure you want to change the base?
Conversation
8f760ff to
7b08746
Compare
| // This must happen after build deps are installed so Go is available | ||
| if err := spec.Preprocess(client, sOpt, worker, opts...); err != nil { | ||
| return llb.Scratch() | ||
| return dalec.ErrorState(worker, err) |
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.
This change exposes the error of the state to the user as this is in an error check
72465dc to
981a7eb
Compare
d64502c to
d509f3a
Compare
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.
Pull request overview
This PR adds support for go mod require and replace directives in the gomod generator, allowing users to programmatically modify go.mod files during the build process. This is a continuation of #847 and enables important use cases like replacing dependencies with forks, working with multi-module repositories, and pinning specific dependency versions.
Key Changes:
- New
GomodEdits,GomodReplace, andGomodRequiretypes for declarative go.mod manipulation - Preprocessing logic that generates patches from gomod edits before building
- Internal
SourceLLBtype for programmatically generated patch sources - Validation and extensive test coverage for the new functionality
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/sources.md | Documents the new gomod replace/require directives (contains format errors that need correction) |
| spec.go | Defines GomodEdits, GomodReplace, and GomodRequire types with marshaling/unmarshaling logic |
| preprocess.go | Implements preprocessing logic to generate patches from gomod edits |
| source_llb.go | Introduces internal-only SourceLLB type for programmatically generated sources |
| source_generated.go | Generated code for SourceLLB integration |
| source.go | Integrates LLB field into Source type |
| load.go | Adds validation for gomod edits |
| generator_gomod_test.go | Unit tests for unmarshaling and validation of gomod directives |
| spec_test.go | Validation tests for SourceGenerator gomod edits |
| test/source_test.go | Unit tests for gomod require/replace with debug/patched-sources target |
| test/linux_target_test.go | Integration tests for gomod edits across different scenarios |
| test/fixtures/simple-go-require.yml | Example fixture demonstrating correct usage |
| targets/windows/handle_zip.go | Adds Preprocess call before building |
| targets/linux/rpm/distro/pkg.go | Adds Preprocess call before building |
| targets/linux/deb/distro/pkg.go | Adds Preprocess call before building |
| targets/linux/distro_handler.go | Standard import reordering |
| frontend/gateway.go | Standard import reordering |
| frontend/debug/handle_sources.go | Adds Preprocess call before getting sources |
| docs/spec.schema.json | Updates JSON schema with new gomod edit types |
| docker-bake.hcl | Removes trailing blank line |
| # String format: "old@version=new@version" | ||
| - "github.com/old/[email protected]=github.com/new/[email protected]" |
Copilot
AI
Dec 8, 2025
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.
The documentation shows an incorrect string format for the replace directive. The string format uses : as the separator, not =.
According to the code implementation in spec.go, the string format is parsed by splitting on : (line 244), so it should be:
- "github.com/old/[email protected]:github.com/new/[email protected]"The = is only used internally when constructing the go mod edit argument, not in the YAML format.
| # String format: "old@version=new@version" | |
| - "github.com/old/[email protected]=github.com/new/[email protected]" | |
| # String format: "old@version:new@version" | |
| - "github.com/old/[email protected]:github.com/new/[email protected]" |
website/docs/sources.md
Outdated
| # String format: "module@version" | ||
| - "github.com/some/[email protected]" |
Copilot
AI
Dec 8, 2025
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.
The documentation shows an incorrect string format for the require directive. The string format should use : as the separator and must include the module path before the :.
According to the code implementation in spec.go, the string format is parsed by splitting on : into module and version (line 335-340), so it should be:
- "github.com/some/pkg:github.com/some/[email protected]"This matches the pattern module:module@version where the version field must contain @version.
website/docs/sources.md
Outdated
| - "github.com/some/[email protected]" | ||
| # Struct format | ||
| - module: github.com/another/pkg | ||
| version: v2.0.0 |
Copilot
AI
Dec 8, 2025
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.
The documentation shows an incorrect struct format for the require directive. The version field must include the full module@version format, not just the version number.
According to the code validation in spec.go (lines 360-362), the version field is validated to contain @, so it should be:
- module: github.com/another/pkg
version: github.com/another/[email protected]This matches the pattern where version contains the full module path with @version.
| version: v2.0.0 | |
| version: github.com/another/pkg@v2.0.0 |
website/docs/sources.md
Outdated
| - "example.com/internal/[email protected]=../../shared" | ||
| require: | ||
| - "github.com/new/[email protected]" |
Copilot
AI
Dec 8, 2025
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.
The documentation shows incorrect string formats in the multi-module example. Both the replace and require directives use the wrong format:
-
Replace (line 501): Should use
:instead of=:- "example.com/internal/[email protected]:../../shared" -
Require (line 503): Should include the module path before
::- "github.com/new/dependency:github.com/new/[email protected]"
These formats must match the parsing logic in spec.go which splits on : for both directives.
| - "example.com/internal/[email protected]=../../shared" | |
| require: | |
| - "github.com/new/[email protected]" | |
| - "example.com/internal/[email protected]:../../shared" | |
| require: | |
| - "github.com/new/dependency:github.com/new/dependency@v1.5.0" |
a7c7424 to
c561d30
Compare
spec.go
Outdated
| Replace []GomodReplace `yaml:"replace,omitempty" json:"replace,omitempty"` | ||
| // Require applies go.mod require directives before downloading module dependencies. | ||
| // Each entry can be either a string "module:version" or a struct with Module and Version fields. | ||
| Require []GomodRequire `yaml:"require,omitempty" json:"require,omitempty"` |
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.
So this injects totally new requires?
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.
I think so. Is that a concern or should we be doing this a different way? @DannyBrito can maybe also clarify since he wrote the original struct.
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.
I guess the main thing is, do we have a use-case for this right now?
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.
sorry I missed this but tbh I don't really understand the question here; I reused initial implementation of the GomodEdits https://github.com/project-dalec/dalec/pull/769/changes#diff-f23a639898f3d395e15d7331eeab9d8d6217fe161c2851610171da61d9f92dd5R255.
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.
Basically, do we need to support adding new requires in this feature.
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.
we don't need to inject new requires since they'll get cleaned up by go mod tidy
we should only use require to update existing requires. require: old:new, not require: new
83e0da0 to
28b9ea2
Compare
07cb9e0 to
fd89736
Compare
cf8b522 to
4958b52
Compare
|
@willie-yao This one needs a rebase to get CI fixes and I think one merge conflict? |
Signed-off-by: Danny Brito <[email protected]>
Signed-off-by: Danny Brito <[email protected]>
Signed-off-by: Danny Brito <[email protected]>
Signed-off-by: William Yao <[email protected]> use go 1.18 in go.mod Signed-off-by: William Yao <[email protected]> Fix Bionic go path Signed-off-by: William Yao <[email protected]> Reviews Signed-off-by: William Yao <[email protected]> set source maps Signed-off-by: William Yao <[email protected]>
|
@cpuguy83 The test failures seem to be still related to runners not having enough memory. Otherwise CI looks good? |
Signed-off-by: William Yao <[email protected]>
What this PR does / why we need it:
Continuation of #847
Which issue(s) this PR fixes (optional, using
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when the PR gets merged):Fixes #
Special notes for your reviewer: