Repository navigation
chore: import go-vcs library with clean history - #7496
Conversation
how about using |
Given that the |
but Actually, the package is already called |
|
Agreed - vcs makes sense here. I wouldn't try to line this up with the labeling terminology; this part is more low level and has separate concerns. Nothing is set in stone for the new label plans anyhow |
This commit adds a forked / improved version of Google's RepoRootForImportPath logic. Most of this code is originally part of the go/internal section of Google's codebase: https://github.com/golang/go/blob/16d3040a84be821d801b75bd1a3d8ab4cc89ee36/src/cmd/go/internal/vcs/vcs.go#L1281. However, Justin found a version of this library exposed by Google without all the internal dependencies. It is now deprecated as unmaintained, but the core logic: the dynamic resolving coupled with the regexes are still relevant and enough for our use-case: https://pkg.go.dev/golang.org/x/tools/go/vcs#RepoRootForImportPath. We had to fork the library in order to upgrade the go version used, bump the dependencies and more importantly fix a few unported changes: 1. We remove unsupported VCS, as BuildKit only support Git based VCS 2. We remove the deprecated mercurial check from bitbucket vcs options (golang/go@5b1b80b) leading to an unability to parse the root of a repo from a bitbucket private ref However, in the context of Dagger, the important part is to be able to split the root of the repo from its subdir. I think it is ok as it will fail at the gitdns.Git level (to be verified) 3. Update the regexes and the tests for jazz, apache, git.sr.ht SCM (following current official package's logic) 4. Remove the deprecation notices, as this package does not aim to be 100% compliant with upstream but just handle the split between the root of a repo and the subpath from its URL + rely on io.ReadAll instead of ioutil Signed-off-by: grouville <[email protected]>
… options Current library https://pkg.go.dev/golang.org/x/tools/go/vcs#RepoRootForImportPath was not up-to-date on two updates: 1. cmd/go: remove mercurial from bitbucket vcs options (golang/go@5b1b80b) leading to an unability to parse the root of a repo from a bitbucket private ref 2. allow go get on github.com/ import paths with Unicodes (golang/go@6511931). This one is a bit more subject to discussion as the current implementation (https://github.com/golang/go/blob/master/src/cmd/go/internal/vcs/vcs_test.go) still does not allow it However, in the context of Dagger, the important part is to be able to split the root of the repo from its subdir. I think it is ok as it will fail at the gitdns.Git level (to be verified) 3. Add tests for jazz, apache, git.sr.ht Signed-off-by: grouville <[email protected]>
License was lost with the git filter-branch Signed-off-by: grouville <[email protected]>
BuildKit only supports Git, remove other VCS support Signed-off-by: grouville <[email protected]>
BuildKit only supports Git, remove other VCS support Signed-off-by: grouville <[email protected]>
- I manually updated the logic to comply with the latest changes for bitbucket and unicode. - The deprecation is correct for Google, but in our case, regarding the split function is out of scope - Rely on io.ReadAll instead of ioutil Signed-off-by: grouville <[email protected]>
Bitbucket root is now resolved with regex Signed-off-by: grouville <[email protected]>
Codeberg SCM follows GitHub structures AND also exposes the go meta head. In order to avoid unnecessary network calls, just implement the corresponding regex Signed-off-by: grouville <[email protected]>
Weird behavior encountered on GitLab's subgroups in private mode. After investigation, it turns out that GitLab conceils the existence of the nested project when unauthenticated: https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/lib/gitlab/middleware/go.rb#L114-126. The current behavior of the library is to rely on the `git ls-remote -q` command when the path contains a `.git`, which relies on gitcredentials for auth. The exact behavior is detailed in this comment: golang/go#26232 (comment) Interesting link regrouping all Go private repo issues: golang/go#29953 Signed-off-by: grouville <[email protected]>
Remove noVCSSuffix to allow the .git suffix on the SCM matched via a regex. The underlying reason is to accept inputs with and without this VCSSuffix. This is useful, as in order to resolve the root of a GitLab private repo, we need to specify the root of the repository with `.git` for the function to piggyback on the ping command (in our case: `git ls-remote -q`) Signed-off-by: grouville <[email protected]>
Add a vanity URL coverage redirecting to a public repo. No auth yet, as these are specific use-cases Signed-off-by: grouville <[email protected]>
Current state does not allow path traversal for the CI refs parsed via a regex. Due to our internal handling of those edge cases, it is easier to extend the matching patterns to handle it Signed-off-by: grouville <[email protected]>
Go's repoRootForImportPath is not following Dagger's golintci conventions This commit fixes them or ignores them when it does not impact the pertinence not the security: - exec.Command() is hidden with nolint:gosec as - naked return are hidden with nolint:nakedret, as this is a pattern used on the official library from Google. Instead of refactoring the function, ignore the error - use %w in fmt.Errorf to wrap errors - use ReplaceAll instead of Replace(..., -1) Signed-off-by: grouville <[email protected]>
Move vcs package as a subdir of engine Signed-off-by: grouville <[email protected]>
You're right, I made a mistake and pushed a wrong version at first. I changed and moved to |
Context
First PR of a serie, splitting the implementation of #7420, in a cleaner way.
This one imports the codebase from https://github.com/grouville/go-vcs directly into our codebase for ease/maintainability purposes. I took the liberty of making it part of the
engine/cisubdir, but open to discussionFirst commit
The first commit is Google's library https://pkg.go.dev/golang.org/x/tools/go/vcs#RepoRootForImportPath filtered-history squashed into one, with all the context:
Follow-up commits
All the follow-up commits are mostly maintenance work implemented to sync the deprecated library in a simi-official state with Google's internal version: https://github.com/golang/go/blob/master/src/cmd/go/internal/vcs/vcs.go
Then, it is followed by a few Dagger specific changes: