@@ -14,13 +14,13 @@ import (
1414)
1515
1616// Promote will promote the artifact to a given promote label
17- func Promote (artifactName string , options map [string ]interface {}) error {
17+ func Promote (artifactName string , options map [string ]interface {}) ( string , error ) {
1818 inspectOptions := map [string ]interface {}{}
1919
2020 // get metadata
2121 jsonMetadata , err := Inspect (artifactName , inspectOptions )
2222 if err != nil {
23- return errors .Wrap (err , "failed to inspect artifact metadata" )
23+ return "" , errors .Wrap (err , "failed to inspect artifact metadata" )
2424 }
2525
2626 var metadata map [string ]interface {}
@@ -54,7 +54,7 @@ func Promote(artifactName string, options map[string]interface{}) error {
5454 }
5555
5656 if err != nil {
57- return errors .Wrap (err , "failed to resolve env var" )
57+ return "" , errors .Wrap (err , "failed to resolve env var" )
5858 }
5959 }
6060
@@ -66,8 +66,9 @@ func Promote(artifactName string, options map[string]interface{}) error {
6666 newArtifactname = value .(string )
6767 } // generate random name if name empty?
6868
69+ fullArtifactName := fmt .Sprintf ("%s.tar" , newArtifactname )
6970 newArtifact := new (archivex.TarFile )
70- newArtifact .Create (fmt . Sprintf ( "%s.tar" , newArtifactname ) )
71+ newArtifact .Create (fullArtifactName )
7172
7273 // create new pak.metadata with the old data and the new one
7374 jsonString , err := json .MarshalIndent (metadata , "" , " " )
@@ -81,7 +82,7 @@ func Promote(artifactName string, options map[string]interface{}) error {
8182 // Add packaged files from the old artifact to the new one
8283 pkg , err := os .Open (artifactName )
8384 if err != nil {
84- return errors .Wrapf (err , "failed to open artifact %s" , artifactName )
85+ return "" , errors .Wrapf (err , "failed to open artifact %s" , artifactName )
8586 }
8687
8788 tr := tar .NewReader (pkg )
@@ -94,12 +95,12 @@ func Promote(artifactName string, options map[string]interface{}) error {
9495 break
9596 }
9697
97- return errors .Wrap (err , "could not get tar header" )
98+ return "" , errors .Wrap (err , "could not get tar header" )
9899 }
99100
100101 fileContent , err := ioutil .ReadAll (tr )
101102 if err != nil {
102- return errors .Wrapf (err , "could not read artifact %s" , artifactName )
103+ return "" , errors .Wrapf (err , "could not read artifact %s" , artifactName )
103104 }
104105
105106 // Don't add metadata file since we will be adding a new one with new metadata
@@ -111,5 +112,5 @@ func Promote(artifactName string, options map[string]interface{}) error {
111112
112113 newArtifact .Close ()
113114
114- return nil
115+ return fullArtifactName , nil
115116}
0 commit comments