Skip to content

Initial ecosystem implementation for Go.#3709

Merged
mitchell-as merged 2 commits intomasterfrom
mitchell/cp-1028
Aug 19, 2025
Merged

Initial ecosystem implementation for Go.#3709
mitchell-as merged 2 commits intomasterfrom
mitchell/cp-1028

Conversation

@mitchell-as
Copy link
Collaborator

@mitchell-as mitchell-as commented Aug 14, 2025

StoryCP-1028 Implement Go ecosystem installer in State Tool

image
$ cat main.go
package main

import "fmt"
import "github.com/google/uuid"

func main() {
  id := uuid.New()
  fmt.Println("UUID: " + id.String())
}
$ cat go.mod
module hello

go 1.24.5

require github.com/google/uuid v1.6.0

Despite the "go: downloading" line, it's downloading from the local filesystem proxy, not the internet.

Note: I patched my local state tool to allow ':' as a namespace separator so I could run this demo. We should prioritize CP-972.

@mitchell-as mitchell-as requested a review from Naatan August 14, 2025 21:32
@mitchell-as mitchell-as marked this pull request as ready for review August 14, 2025 21:32
Copy link
Contributor

@Naatan Naatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much simpler than I was imagining this would be! Hopefully this holds true as we start testing it more thoroughly.

Just some minor churn.

if err != nil {
return nil, errs.Wrap(err, "Unable to unpack downloaded module")
}
err = fileutils.CopyFile(filepath.Join(unpackDir, artifact.NameAndVersion(), "go.mod"), filepath.Join(vDir, artifact.Version()+".mod"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeremy pointed out not every package will have a go.mod, is that a concern here? I vaguely recall something about the go proxy injecting one, which DI is using so maybe it's fine..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is artifact.NameAndVersion() robust enough? Feels a bit risky to assume a 1:1 mapping there. Perhaps we could locate the go.mod file instead? Assuming the answer to my previous question is that it always exists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair points. I've changed this to a list-dir-and-search approach. If go.mod wasn't found, we create one, according to the goproxy protocol.

Comment on lines +103 to +106
err = os.RemoveAll(unpackDir)
if err != nil {
return nil, errs.Wrap(err, "Unable to remove unpacked module")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should defer this after its creation so we're also cleaning up on errors.

@mitchell-as mitchell-as requested a review from Naatan August 15, 2025 15:18
@mitchell-as
Copy link
Collaborator Author

@Naatan ping

@mitchell-as mitchell-as merged commit 3e66f72 into master Aug 19, 2025
7 of 8 checks passed
@mitchell-as mitchell-as deleted the mitchell/cp-1028 branch August 19, 2025 16:15
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.

2 participants