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

x/playground: if Imports is checked, run 'go mod tidy' when the Format button is pressed #32614

Open
bcmills opened this issue Jun 14, 2019 · 3 comments

Comments

@bcmills
Copy link
Member

@bcmills bcmills commented Jun 14, 2019

CL 177421 added formatting for go.mod files in the Playground.

However, that isn't really enough to result in a reproducible build: as noted in #31944 (comment), unresolved dependencies are re-resolved whenever the cache is invalidated, which is difficult to predict.

One simple fix to add stability would be to have the existing Imports checkbox trigger a go mod tidy after running goimports. That would make the versions in use much clearer in the code and more stable over time, without the need for humans to manually resolve and copy over their go.mod files.

CC @dmitshur @ysmolsky

@bcmills

This comment has been minimized.

Copy link
Member Author

@bcmills bcmills commented Jun 14, 2019

This would also make it possible for users to add a go.sum file to their Playground example to show exactly which modules end up being loaded during the build. That seems like a handy bonus feature!

@bcmills bcmills added the modules label Jun 14, 2019
@dmitshur

This comment has been minimized.

Copy link
Member

@dmitshur dmitshur commented Jun 14, 2019

Also /cc @toothrot.

@bcmills bcmills added the help wanted label Jun 14, 2019
@toothrot

This comment has been minimized.

Copy link
Contributor

@toothrot toothrot commented Jul 2, 2019

It looks like the current implementation of Format uses the go/format core library instead of the Run approach of running exec.Command.

In order to run go mod tidy, the Format handler may need to act more like Run: writing the files to a temporary space, running a command, then in this case, reading the files back out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.