github.com/rothwerx/packer@v0.9.0/post-processor/vagrant-cloud/step_release_version.go (about) 1 package vagrantcloud 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 "strings" 8 ) 9 10 type stepReleaseVersion struct { 11 } 12 13 func (s *stepReleaseVersion) Run(state multistep.StateBag) multistep.StepAction { 14 client := state.Get("client").(*VagrantCloudClient) 15 ui := state.Get("ui").(packer.Ui) 16 box := state.Get("box").(*Box) 17 version := state.Get("version").(*Version) 18 config := state.Get("config").(Config) 19 20 ui.Say(fmt.Sprintf("Releasing version: %s", version.Version)) 21 22 if config.NoRelease { 23 ui.Message("Not releasing version due to configuration") 24 return multistep.ActionContinue 25 } 26 27 path := fmt.Sprintf("box/%s/version/%v/release", box.Tag, version.Version) 28 29 resp, err := client.Put(path) 30 31 if err != nil || (resp.StatusCode != 200) { 32 cloudErrors := &VagrantCloudErrors{} 33 err = decodeBody(resp, cloudErrors) 34 if strings.Contains(cloudErrors.FormatErrors(), "already been released") { 35 ui.Message("Not releasing version, already released") 36 return multistep.ActionContinue 37 } 38 state.Put("error", fmt.Errorf("Error releasing version: %s", cloudErrors.FormatErrors())) 39 return multistep.ActionHalt 40 } 41 42 ui.Message(fmt.Sprintf("Version successfully released and available")) 43 44 return multistep.ActionContinue 45 } 46 47 func (s *stepReleaseVersion) Cleanup(state multistep.StateBag) { 48 // No cleanup 49 }