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