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

Pulumi-language-go and pulumi new now checks go version is at least 1.14.0 #5741

Merged
merged 3 commits into from
Nov 12, 2020

Conversation

viveklak
Copy link
Contributor

@viveklak viveklak commented Nov 11, 2020

Fixes #5724
This change enforces that the go version is at least 1.14.0 for go projects.

Now the following error is seen when running pulumi up on an incompatible version:

# pulumi up
Previewing update (dev)

View Live: https://app.pulumi.com/.../dev/previews/...


error: failed to discover plugin requirements: go version must be 1.14.0 or higher (1.13.8 detected)

and the following when pulumi new is invoked:

pulumi new gcp-go

Enter a value or leave blank to accept the (default), and press <ENTER>.
Press ^C at any time to quit.

project name: (new-project)
project description: (A minimal Google Cloud Go Pulumi program)
Created project 'new-project'

Please enter your desired stack name.
To create a stack in an organization, use the format <org-name>/<stack-name> (e.g. `acmecorp/dev`).
stack name: (dev)
Created stack 'dev'

gcp:project: The Google Cloud project to deploy into:
Saved config

Installing dependencies...

error: go version must be 1.14.0 or higher (1.13.8 detected)

// will err if the project isn't using modules
logging.V(5).Infof("GetRequiredPlugins: Error discovering plugin requirements: %s", err.Error())
return &pulumirpc.GetRequiredPluginsResponse{}, nil
logging.V(5).Infof("GetRequiredPlugins: Error discovering plugin requirements using go modules: %s", err.Error())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously returning an empty response essentially silently disabled plugin acquisition for users with glide or dep projects. We can reinstate the behavior if we feel we aren't ready for this breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

I'm leaning towards not introducing this break just yet.

Copy link
Member

@justinvp justinvp left a comment

Choose a reason for hiding this comment

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

I'm leaning towards continuing to not error on the go list command, at least for now.

Aside from that and some nits, LGTM.

cmd := exec.Command(gobin, "version")
stdout, err := cmd.Output()
if err != nil {
return nil, fmt.Errorf("failed to determine go version: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
return nil, fmt.Errorf("failed to determine go version: %w", err)
return nil, errors.Wrap(err, "determining go version")

func checkMinimumGoVersion(goVersionOutput string) error {
split := strings.Split(goVersionOutput, " ")
if len(split) <= 2 {
return fmt.Errorf("unexpected format for go version output: \"%s\"", goVersionOutput)
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
return fmt.Errorf("unexpected format for go version output: \"%s\"", goVersionOutput)
return errors.Errorf("unexpected format for go version output: \"%s\"", goVersionOutput)


currVersion, err := semver.ParseTolerant(version)
if err != nil {
return fmt.Errorf("parsing go version failed: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
return fmt.Errorf("parsing go version failed: %w", err)
return errors.Wrap(err, "parsing go version")

}

if currVersion.LT(minGoVersion) {
return fmt.Errorf("go version must be %s or higher (%s detected)", minGoVersion.String(), version)
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
return fmt.Errorf("go version must be %s or higher (%s detected)", minGoVersion.String(), version)
return errors.Errorf("go version must be %s or higher (%s detected)", minGoVersion.String(), version)

// will err if the project isn't using modules
logging.V(5).Infof("GetRequiredPlugins: Error discovering plugin requirements: %s", err.Error())
return &pulumirpc.GetRequiredPluginsResponse{}, nil
logging.V(5).Infof("GetRequiredPlugins: Error discovering plugin requirements using go modules: %s", err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

I'm leaning towards not introducing this break just yet.

@viveklak
Copy link
Contributor Author

I'm leaning towards continuing to not error on the go list command, at least for now.

Aside from that and some nits, LGTM.

I decided to factor out the version check since I wanted to enforce this on pulumi new as well. I have applied the nit improvements you mentioned and have also excluded the "breaking" change. Apologies for the churn but hopefully the change is easy to grok.

@viveklak viveklak changed the title Pulumi-language-go now checks go version is atleast 1.14.0 Pulumi-language-go and pulumi new now checks go version is at least 1.14.0 Nov 12, 2020
Copy link
Member

@justinvp justinvp left a comment

Choose a reason for hiding this comment

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

LGTM

@viveklak viveklak merged commit 9d6e380 into master Nov 12, 2020
@pulumi-bot pulumi-bot deleted the vl/GoVersion branch November 12, 2020 23:41
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.

Plugins not being automatically installed for new Go + AWS projects on Ubuntu 20 Desktop
2 participants