Skip to content

Commit

Permalink
feat: update AppVersion when helm_update_appversion is set
Browse files Browse the repository at this point in the history
  • Loading branch information
hairmare committed Jul 1, 2022
1 parent 6c1b3fd commit 4530a41
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
16 changes: 15 additions & 1 deletion pkg/updater/helm.go
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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
}
27 changes: 26 additions & 1 deletion pkg/updater/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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"])
}

0 comments on commit 4530a41

Please sign in to comment.