diff --git a/pkg/updater/helm.go b/pkg/updater/helm.go index 58be883..bda209e 100644 --- a/pkg/updater/helm.go +++ b/pkg/updater/helm.go @@ -1,15 +1,26 @@ package updater import ( + "fmt" helmutils "helm.sh/helm/v3/pkg/chartutil" ) var FUVERSION = "dev" type Updater struct { + updateAppVersion bool + appVersionTemplate string } func (u *Updater) Init(m map[string]string) error { + helmUpdateAppVersion := m["helm_update_appversion"] + u.updateAppVersion = helmUpdateAppVersion == "true" || helmUpdateAppVersion != "" + + helmAppVersionTemplate := m["helm_appversion_template"] + if helmAppVersionTemplate == "" { + helmAppVersionTemplate = "v%s" + } + u.appVersionTemplate = helmAppVersionTemplate return nil } @@ -33,10 +44,13 @@ func (u *Updater) Apply(file, newVersion string) error { metadata.Version = newVersion + if u.updateAppVersion { + metadata.AppVersion = fmt.Sprintf(u.appVersionTemplate, newVersion) + } + if err := helmutils.SaveChartfile(file, metadata); err == nil { return err } - return nil } diff --git a/pkg/updater/helm_test.go b/pkg/updater/helm_test.go index 0dca4e0..effc932 100644 --- a/pkg/updater/helm_test.go +++ b/pkg/updater/helm_test.go @@ -5,9 +5,10 @@ import ( "testing" "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" ) -func TestNpmUpdater(t *testing.T) { +func TestHelmUpdater(t *testing.T) { require := require.New(t) updater := &Updater{} @@ -21,3 +22,27 @@ func TestNpmUpdater(t *testing.T) { require.NoError(err) defer f.Close() } + +func TestHelmUpdaterAppVersion(t *testing.T) { + require := require.New(t) + + updater := &Updater{} + + conf := map[string]string{ + "helm_update_appversion": "true", + } + updater.Init(conf) + + nVer := "1.2.3" + chartPath := "../../test/Chart.yaml" + + err := updater.Apply(chartPath, nVer) + require.NoError(err) + f, err := os.ReadFile(chartPath) + require.NoError(err) + + data := make(map[interface{}]interface{}) + err = yaml.Unmarshal(f, &data) + require.NoError(err) + require.Equal("v1.2.3", data["appVersion"]) +}