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

Proposal: add replace directive to go.mod to use local version of v3/* modules #4115

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

VAveryanov8
Copy link
Collaborator

This simplifies workflow when it's needed to make some changes in v3/* modules.

Relates to #4109


Please make sure that:

  • Code is split to commits that address a single change
  • Commit messages are informative
  • Commit titles have module prefix
  • Commit titles have issue nr. suffix

@VAveryanov8 VAveryanov8 marked this pull request as ready for review November 15, 2024 14:54
… v3/* modules

This simplifies workflow when it's needed to make some changes in v3/*
modules.
@VAveryanov8 VAveryanov8 marked this pull request as draft November 18, 2024 10:41
@VAveryanov8
Copy link
Collaborator Author

VAveryanov8 commented Nov 18, 2024

Ok, here is how it works:

  1. From the SM perspective, when scylla-manager repository is pulled, then scylla-manager/go.mod file is the main module and all go tooling will consider replace directives of scylla-manger/go.mod.
  2. When some external module (e.g. siren) is using v3/pkg/managerclient, then main module is siren/go.mod and replace directives of scylla-manager/go.mod and v3/pkg/managerclient/go.mod are ignored, but instead go tooling uses versions from their require sections.

Here is simple example to show this behavior. Imaging we have some managerclient_test module, looking like this:
main.go:

package main

import (
	"github.com/scylladb/scylla-manager/v3/pkg/managerclient"
)

func main() {
	_, _ = managerclient.NewClient("example.com")
}

We pulled managerclient package from this branch (by commit hash):

go get github.com/scylladb/scylla-manager/v3/pkg/managerclient@0cfb5ab6da3bdc631afc138cbf4c6ba2d7cba24a 

Then go.mod will look like this (i've stripped all the deps except scylla-manager/v3*):

module managerclienttest

go 1.23.2

require github.com/scylladb/scylla-manager/v3/pkg/managerclient v0.0.0-20241118090522-0cfb5ab6da3b

require (
	....
	github.com/scylladb/scylla-manager/v3/pkg/util v0.0.0-20241030073626-e409ae491c83 // indirect
	github.com/scylladb/scylla-manager/v3/swagger v0.0.0-20241030073626-e409ae491c83 // indirect
	...
)

We can see that managerclient version is from this branch, but v3/pkg/util and v3/swagger have version that are listed in require section of managerclient/go.mod from this branch (replace directive is ignored).

This means, that if we want to update managerclient dependencies for the external usage, then we need to explicitly update managerclient/go.mod, but when working on scylla-manger only local versions of v3/* modules will be used and there is no need to do several pull requests when we need to update v3/swagger for example.

P.S.
This behavior is described in go.mod reference

replace directives only apply in the main module’s go.mod file and are ignored in other modules. See Minimal version selection for details.

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.

1 participant