2014-06-24 15:58:45 -04:00
|
|
|
package vagrantcloud
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2014-06-24 15:58:45 -04:00
|
|
|
"fmt"
|
2017-08-07 13:20:01 -04:00
|
|
|
"strings"
|
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2014-06-24 15:58:45 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepReleaseVersion struct {
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *stepReleaseVersion) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2014-06-24 15:58:45 -04:00
|
|
|
client := state.Get("client").(*VagrantCloudClient)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
box := state.Get("box").(*Box)
|
|
|
|
version := state.Get("version").(*Version)
|
2014-06-25 10:32:17 -04:00
|
|
|
config := state.Get("config").(Config)
|
|
|
|
|
2014-06-25 12:46:25 -04:00
|
|
|
ui.Say(fmt.Sprintf("Releasing version: %s", version.Version))
|
|
|
|
|
2014-06-25 10:32:17 -04:00
|
|
|
if config.NoRelease {
|
2014-06-25 12:46:25 -04:00
|
|
|
ui.Message("Not releasing version due to configuration")
|
2014-06-25 10:32:17 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
2014-06-24 15:58:45 -04:00
|
|
|
|
2014-12-23 20:19:42 -05:00
|
|
|
path := fmt.Sprintf("box/%s/version/%v/release", box.Tag, version.Version)
|
2014-06-24 15:58:45 -04:00
|
|
|
|
|
|
|
resp, err := client.Put(path)
|
|
|
|
|
|
|
|
if err != nil || (resp.StatusCode != 200) {
|
|
|
|
cloudErrors := &VagrantCloudErrors{}
|
2017-08-07 14:09:40 -04:00
|
|
|
if err := decodeBody(resp, cloudErrors); err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Error parsing provider response: %s", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2014-08-01 13:31:10 -04:00
|
|
|
if strings.Contains(cloudErrors.FormatErrors(), "already been released") {
|
|
|
|
ui.Message("Not releasing version, already released")
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
2014-06-24 15:58:45 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error releasing version: %s", cloudErrors.FormatErrors()))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2014-06-25 12:46:25 -04:00
|
|
|
ui.Message(fmt.Sprintf("Version successfully released and available"))
|
|
|
|
|
2014-06-24 15:58:45 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepReleaseVersion) Cleanup(state multistep.StateBag) {
|
|
|
|
// No cleanup
|
|
|
|
}
|