github.com/pluralsh/plural-cli@v0.9.5/pkg/pluralfile/tags.go (about) 1 package pluralfile 2 3 import ( 4 "errors" 5 "fmt" 6 "io" 7 "os" 8 9 "github.com/pluralsh/plural-cli/pkg/api" 10 "github.com/pluralsh/plural-cli/pkg/executor" 11 "github.com/pluralsh/plural-cli/pkg/utils" 12 "gopkg.in/yaml.v2" 13 ) 14 15 type VersionSpec struct { 16 Chart *string 17 Terraform *string 18 Version string 19 } 20 21 type VersionTags struct { 22 Spec *VersionSpec 23 Tags []string 24 } 25 26 type Tags struct { 27 File string 28 } 29 30 func (a *Tags) Type() ComponentName { 31 return TAG 32 } 33 34 func (a *Tags) Key() string { 35 return a.File 36 } 37 38 func (t *Tags) Push(repo string, sha string) (string, error) { 39 newsha, err := executor.MkHash(t.File, []string{}) 40 if err != nil || newsha == sha { 41 if err == nil { 42 utils.Highlight("No change for %s\n", t.File) 43 } 44 return sha, err 45 } 46 47 f, err := os.Open(t.File) 48 if err != nil { 49 return sha, err 50 } 51 52 utils.Highlight("updating tags for %s", t.File) 53 client := api.NewClient() 54 d := yaml.NewDecoder(f) 55 for { 56 tagSpec := &VersionTags{} 57 err = d.Decode(tagSpec) 58 if errors.Is(err, io.EOF) { 59 break 60 } 61 if err != nil { 62 fmt.Println("") 63 return sha, err 64 } 65 66 vspec := &api.VersionSpec{ 67 Repository: repo, 68 Chart: tagSpec.Spec.Chart, 69 Terraform: tagSpec.Spec.Terraform, 70 Version: tagSpec.Spec.Version, 71 } 72 if err := client.UpdateVersion(vspec, tagSpec.Tags); err != nil { 73 fmt.Println("") 74 return sha, api.GetErrorResponse(err, "UpdateVersion") 75 } 76 77 utils.Highlight(".") 78 } 79 80 utils.Success("\u2713\n") 81 return newsha, nil 82 }