go get for a specific version for nested module in private gitlab
Summary
TLDR: Issues with version tag when go get pointing to a specific version has been done in private module with nested modules in a private GitLab.
We operate within a monolithic repository structure housing multiple Go modules. Recently, we introduced "Utils" packages intended for use across various modules within the repository. Historically, we've relied on referencing the latest automatically generated version of these packages, which has functioned without issue. However, a decision was made to implement versioning via tags to stabilize package versions within specific modules. This shift has led to an unresolved issue within our workflow.
Related issues found but not with the exactly problem:
#437005 #36354 (closed) #30785
Steps to reproduce
Setup
self-hosted v16.3.7
Go Lang version go1.22.1 linux/amd64
.netrc created with following content:
machine gitlab.mycompany.com login myUser password passToken
.gitconfig created with the following content:
[url "git@gitlab.mycompany.com:"]
insteadOf = https://gitlab.mycompany.com/
GO ENV has the relevant values written:
GONOPROXY='gitlab.mycompany.com/*'
GONOSUMDB='gitlab.mycompany.com/*'
GOPRIVATE='gitlab.mycompany.com/*'
Example of repository structure:
.
├── go.work
├── go.work.sum
├── folder1
│ └── v1
│ └── folder2
│ ├── go.mod
│ ├── go.sum
│ └── cmd
│ └── main.go
└── utils
└── module
├── go.mod
└── module.go
gitlab.mycompany.com/group/project/utils/module
- where project is where the .git can be found.
- module is where the go.mod of the package that will be imported can be found
Steps
- create a tag for the project v0.0.1
- go to the module2
- Try to import the utils package with to the tag version running: go get gitlab.mycompany.com/group/project/folder/module@v0.0.1
Example Project
self-hosted project, therefore, difficult to reproduce the same environment in a public server.
What is the current bug behavior?
When a module executes a 'go get' command to retrieve a specific version, the problem arises.
go get gitlab.mycompany.com/group/project/utils/module@v0.0.1
it returns the following:
go: module gitlab.mycompany.com/group/project@v0.0.1 found, but does not contain package gitlab.mycompany.com/group/project/utils/module
Searching through internet several approaches has been found without success:
.git in the go.mod
As it indicates here with the replace option that adds the .git in the module should git clone the module and then points to the specific version.
Doing the first approach
Putting .git in the module
replace(
gitlab.mycompany.com/group/project/utils/module => gitlab.mycompany.com/group/project/utils/module.git v0.0.1
)
running:
go mod tidy
it returns the following:
github.com/pascaldekloe/goe/verify: gitlab.mycompany.com/group/project/utils/module@v0.0.0-20231130161419-1e9d425b8137: no secure protocol found for repository
Doing the second approach
Putting .git in the project level
replace(
gitlab.mycompany.com/group/project/utils/module => gitlab.mycompany.com/group/project.git/utils/module v0.0.1
)
it returns the following:
github.com/pascaldekloe/goe/verify: gitlab.mycompany.com/group/project/utils/module@v0.0.0-20231130161419-1e9d425b8137: reading gitlab.mycompany.com/group/project.git/utils/module/go.mod at revision utils/module/v0.0.1: unknown revision utils/module/v0.0.1
Other approaches
- Running the
go clean -modcacheandgo clean -cache - Running
go installinstead of go get
What is the expected correct behavior?
go get command to a specific version should work and not only the default/generated option that works with the SHA.
Relevant logs and/or screenshots
All logs has been pasted in the previous sections.
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)(we will only investigate if the tests are passing)