From 78bbe687ef75ee42230a7321e716b155ed4016a9 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Thu, 17 Nov 2022 07:46:23 -0800 Subject: [PATCH 1/3] add support for bumping multiple files. --- README.md | 1 + go.mod | 1 + pkg/config/config.go | 1 + pkg/config/config_test.go | 22 ++ pkg/config/interface.go | 3 + pkg/config/mock/mock_config.go | 208 +++++++++++------- .../testdata/addl_version_metadata_paths.yml | 6 + pkg/engine/engine_chef.go | 10 +- pkg/engine/engine_generic.go | 12 +- pkg/engine/engine_golang.go | 12 +- pkg/engine/engine_node.go | 14 +- pkg/engine/engine_python.go | 10 +- pkg/engine/engine_ruby.go | 12 +- pkg/engine/interface.go | 1 + pkg/pipeline.go | 19 ++ 15 files changed, 224 insertions(+), 108 deletions(-) create mode 100644 pkg/config/testdata/addl_version_metadata_paths.yml diff --git a/README.md b/README.md index 180ad15..12da479 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ cat pkg/version/version.go - `version_bump_type` - `version_metadata_path` - `generic_version_template` +- `addl_version_metadata_paths` # Outputs - `release_version` diff --git a/go.mod b/go.mod index eb88227..8eb0039 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/stretchr/testify v1.6.1 github.com/urfave/cli v1.22.4 golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect + golang.org/x/sys v0.2.0 // indirect gopkg.in/yaml.v2 v2.3.0 ) diff --git a/pkg/config/config.go b/pkg/config/config.go index d58faa4..79103fe 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -32,6 +32,7 @@ func (c *configuration) Init() error { c.SetDefault(PACKAGR_SCM, "default") c.SetDefault(PACKAGR_VERSION_BUMP_TYPE, "patch") c.SetDefault(PACKAGR_ENGINE_REPO_CONFIG_PATH, "packagr.yml") + c.SetDefault(PACKAGR_ADDL_VERSION_METADATA_PATHS, map[string]string{}) //set the default system config file search path. //if you want to load a non-standard location system config file (~/capsule.yml), use ReadConfig diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index af3af3d..454d358 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -21,6 +21,8 @@ func TestConfiguration_init_ShouldCorrectlyInitializeConfiguration(t *testing.T) require.Equal(t, "generic", testConfig.GetString(config.PACKAGR_PACKAGE_TYPE), "should populate package_type with generic default") require.Equal(t, "default", testConfig.GetString(config.PACKAGR_SCM), "should populate scm with default") require.Equal(t, "patch", testConfig.GetString(config.PACKAGR_VERSION_BUMP_TYPE), "should populate runner with default") + require.Equal(t, map[string]interface{}{}, testConfig.GetStringMap(config.PACKAGR_ADDL_VERSION_METADATA_PATHS), "should populate addl metadata paths from config file") + } func TestConfiguration_init_EnvVariablesShouldLoadProperly(t *testing.T) { @@ -55,3 +57,23 @@ func TestConfiguration_ReadConfig(t *testing.T) { require.Equal(t, "major", testConfig.GetString(config.PACKAGR_VERSION_BUMP_TYPE), "should populate Engine Version Bump Type from overrides config file") } + +func TestConfiguration_ReadConfig_AddlVersionMetadataPaths(t *testing.T) { + //setup + defer utils.UnsetEnv("PACKAGR_")() + testConfig, _ := config.Create() + testConfig.SetDefault(config.PACKAGR_PACKAGE_TYPE, "generic") + testConfig.SetDefault(config.PACKAGR_SCM, "default") + testConfig.SetDefault(config.PACKAGR_VERSION_BUMP_TYPE, "patch") + + //test + err := testConfig.ReadConfig(path.Join("testdata", "addl_version_metadata_paths.yml")) + + //assert + require.NoErrorf(t, err, "No error") + require.Equal(t, "golang", testConfig.GetString(config.PACKAGR_PACKAGE_TYPE), "should populate Package Type from overrides config file") + require.Equal(t, "github", testConfig.GetString(config.PACKAGR_SCM), "should populate SCM from overrides config file") + require.Equal(t, "major", testConfig.GetString(config.PACKAGR_VERSION_BUMP_TYPE), "should populate Engine Version Bump Type from overrides config file") + require.Equal(t, "addl_version_metadata_paths", testConfig.GetStringMap(config.PACKAGR_ADDL_VERSION_METADATA_PATHS), "should populate addl metadata paths from config file") + +} diff --git a/pkg/config/interface.go b/pkg/config/interface.go index 1795144..be3a0d6 100644 --- a/pkg/config/interface.go +++ b/pkg/config/interface.go @@ -17,6 +17,8 @@ type Interface interface { GetInt(key string) int GetString(key string) string GetStringSlice(key string) []string + GetStringMapString(key string) map[string]string + GetStringMap(key string) map[string]interface{} UnmarshalKey(key string, rawVal interface{}, decoder ...viper.DecoderConfigOption) error ReadConfig(configFilePath string) error } @@ -25,5 +27,6 @@ const PACKAGR_PACKAGE_TYPE = "package_type" const PACKAGR_SCM = "scm" const PACKAGR_VERSION_BUMP_TYPE = "version_bump_type" const PACKAGR_VERSION_METADATA_PATH = "version_metadata_path" +const PACKAGR_ADDL_VERSION_METADATA_PATHS = "addl_version_metadata_paths" const PACKAGR_ENGINE_REPO_CONFIG_PATH = "engine_repo_config_path" const PACKAGR_GENERIC_VERSION_TEMPLATE = "generic_version_template" diff --git a/pkg/config/mock/mock_config.go b/pkg/config/mock/mock_config.go index 1a55f29..1e2bcd7 100644 --- a/pkg/config/mock/mock_config.go +++ b/pkg/config/mock/mock_config.go @@ -5,177 +5,216 @@ package mock_config import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" viper "github.com/spf13/viper" - reflect "reflect" ) -// MockInterface is a mock of Interface interface +// MockInterface is a mock of Interface interface. type MockInterface struct { ctrl *gomock.Controller recorder *MockInterfaceMockRecorder } -// MockInterfaceMockRecorder is the mock recorder for MockInterface +// MockInterfaceMockRecorder is the mock recorder for MockInterface. type MockInterfaceMockRecorder struct { mock *MockInterface } -// NewMockInterface creates a new mock instance +// NewMockInterface creates a new mock instance. func NewMockInterface(ctrl *gomock.Controller) *MockInterface { mock := &MockInterface{ctrl: ctrl} mock.recorder = &MockInterfaceMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use +// EXPECT returns an object that allows the caller to indicate expected use. func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder { return m.recorder } -// Init mocks base method -func (m *MockInterface) Init() error { - ret := m.ctrl.Call(m, "Init") - ret0, _ := ret[0].(error) - return ret0 -} - -// Init indicates an expected call of Init -func (mr *MockInterfaceMockRecorder) Init() *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockInterface)(nil).Init)) -} - -// ReadConfig mocks base method -func (m *MockInterface) ReadConfig(configFilePath string) error { - ret := m.ctrl.Call(m, "ReadConfig", configFilePath) - ret0, _ := ret[0].(error) - return ret0 -} - -// ReadConfig indicates an expected call of ReadConfig -func (mr *MockInterfaceMockRecorder) ReadConfig(configFilePath interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadConfig", reflect.TypeOf((*MockInterface)(nil).ReadConfig), configFilePath) -} - -// Set mocks base method -func (m *MockInterface) Set(key string, value interface{}) { - m.ctrl.Call(m, "Set", key, value) -} - -// Set indicates an expected call of Set -func (mr *MockInterfaceMockRecorder) Set(key, value interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockInterface)(nil).Set), key, value) -} - -// SetDefault mocks base method -func (m *MockInterface) SetDefault(key string, value interface{}) { - m.ctrl.Call(m, "SetDefault", key, value) -} - -// SetDefault indicates an expected call of SetDefault -func (mr *MockInterfaceMockRecorder) SetDefault(key, value interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDefault", reflect.TypeOf((*MockInterface)(nil).SetDefault), key, value) -} - -// AllSettings mocks base method +// AllSettings mocks base method. func (m *MockInterface) AllSettings() map[string]interface{} { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AllSettings") ret0, _ := ret[0].(map[string]interface{}) return ret0 } -// AllSettings indicates an expected call of AllSettings +// AllSettings indicates an expected call of AllSettings. func (mr *MockInterfaceMockRecorder) AllSettings() *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AllSettings", reflect.TypeOf((*MockInterface)(nil).AllSettings)) } -// IsSet mocks base method -func (m *MockInterface) IsSet(key string) bool { - ret := m.ctrl.Call(m, "IsSet", key) - ret0, _ := ret[0].(bool) - return ret0 -} - -// IsSet indicates an expected call of IsSet -func (mr *MockInterfaceMockRecorder) IsSet(key interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSet", reflect.TypeOf((*MockInterface)(nil).IsSet), key) -} - -// Get mocks base method +// Get mocks base method. func (m *MockInterface) Get(key string) interface{} { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Get", key) ret0, _ := ret[0].(interface{}) return ret0 } -// Get indicates an expected call of Get +// Get indicates an expected call of Get. func (mr *MockInterfaceMockRecorder) Get(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockInterface)(nil).Get), key) } -// GetBool mocks base method +// GetBool mocks base method. func (m *MockInterface) GetBool(key string) bool { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetBool", key) ret0, _ := ret[0].(bool) return ret0 } -// GetBool indicates an expected call of GetBool +// GetBool indicates an expected call of GetBool. func (mr *MockInterfaceMockRecorder) GetBool(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBool", reflect.TypeOf((*MockInterface)(nil).GetBool), key) } -// GetInt mocks base method +// GetInt mocks base method. func (m *MockInterface) GetInt(key string) int { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetInt", key) ret0, _ := ret[0].(int) return ret0 } -// GetInt indicates an expected call of GetInt +// GetInt indicates an expected call of GetInt. func (mr *MockInterfaceMockRecorder) GetInt(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInt", reflect.TypeOf((*MockInterface)(nil).GetInt), key) } -// GetString mocks base method +// GetString mocks base method. func (m *MockInterface) GetString(key string) string { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetString", key) ret0, _ := ret[0].(string) return ret0 } -// GetString indicates an expected call of GetString +// GetString indicates an expected call of GetString. func (mr *MockInterfaceMockRecorder) GetString(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetString", reflect.TypeOf((*MockInterface)(nil).GetString), key) } -// GetStringSlice mocks base method +// GetStringMap mocks base method. +func (m *MockInterface) GetStringMap(key string) map[string]interface{} { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStringMap", key) + ret0, _ := ret[0].(map[string]interface{}) + return ret0 +} + +// GetStringMap indicates an expected call of GetStringMap. +func (mr *MockInterfaceMockRecorder) GetStringMap(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStringMap", reflect.TypeOf((*MockInterface)(nil).GetStringMap), key) +} + +// GetStringMapString mocks base method. +func (m *MockInterface) GetStringMapString(key string) map[string]string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetStringMapString", key) + ret0, _ := ret[0].(map[string]string) + return ret0 +} + +// GetStringMapString indicates an expected call of GetStringMapString. +func (mr *MockInterfaceMockRecorder) GetStringMapString(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStringMapString", reflect.TypeOf((*MockInterface)(nil).GetStringMapString), key) +} + +// GetStringSlice mocks base method. func (m *MockInterface) GetStringSlice(key string) []string { + m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetStringSlice", key) ret0, _ := ret[0].([]string) return ret0 } -// GetStringSlice indicates an expected call of GetStringSlice +// GetStringSlice indicates an expected call of GetStringSlice. func (mr *MockInterfaceMockRecorder) GetStringSlice(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStringSlice", reflect.TypeOf((*MockInterface)(nil).GetStringSlice), key) } -// GetBase64Decoded mocks base method -func (m *MockInterface) GetBase64Decoded(key string) (string, error) { - ret := m.ctrl.Call(m, "GetBase64Decoded", key) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 +// Init mocks base method. +func (m *MockInterface) Init() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Init") + ret0, _ := ret[0].(error) + return ret0 } -// GetBase64Decoded indicates an expected call of GetBase64Decoded -func (mr *MockInterfaceMockRecorder) GetBase64Decoded(key interface{}) *gomock.Call { - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBase64Decoded", reflect.TypeOf((*MockInterface)(nil).GetBase64Decoded), key) +// Init indicates an expected call of Init. +func (mr *MockInterfaceMockRecorder) Init() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockInterface)(nil).Init)) +} + +// IsSet mocks base method. +func (m *MockInterface) IsSet(key string) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsSet", key) + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsSet indicates an expected call of IsSet. +func (mr *MockInterfaceMockRecorder) IsSet(key interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSet", reflect.TypeOf((*MockInterface)(nil).IsSet), key) +} + +// ReadConfig mocks base method. +func (m *MockInterface) ReadConfig(configFilePath string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ReadConfig", configFilePath) + ret0, _ := ret[0].(error) + return ret0 +} + +// ReadConfig indicates an expected call of ReadConfig. +func (mr *MockInterfaceMockRecorder) ReadConfig(configFilePath interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReadConfig", reflect.TypeOf((*MockInterface)(nil).ReadConfig), configFilePath) +} + +// Set mocks base method. +func (m *MockInterface) Set(key string, value interface{}) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Set", key, value) +} + +// Set indicates an expected call of Set. +func (mr *MockInterfaceMockRecorder) Set(key, value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Set", reflect.TypeOf((*MockInterface)(nil).Set), key, value) +} + +// SetDefault mocks base method. +func (m *MockInterface) SetDefault(key string, value interface{}) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetDefault", key, value) +} + +// SetDefault indicates an expected call of SetDefault. +func (mr *MockInterfaceMockRecorder) SetDefault(key, value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDefault", reflect.TypeOf((*MockInterface)(nil).SetDefault), key, value) } -// UnmarshalKey mocks base method +// UnmarshalKey mocks base method. func (m *MockInterface) UnmarshalKey(key string, rawVal interface{}, decoder ...viper.DecoderConfigOption) error { + m.ctrl.T.Helper() varargs := []interface{}{key, rawVal} for _, a := range decoder { varargs = append(varargs, a) @@ -185,8 +224,9 @@ func (m *MockInterface) UnmarshalKey(key string, rawVal interface{}, decoder ... return ret0 } -// UnmarshalKey indicates an expected call of UnmarshalKey +// UnmarshalKey indicates an expected call of UnmarshalKey. func (mr *MockInterfaceMockRecorder) UnmarshalKey(key, rawVal interface{}, decoder ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() varargs := append([]interface{}{key, rawVal}, decoder...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnmarshalKey", reflect.TypeOf((*MockInterface)(nil).UnmarshalKey), varargs...) } diff --git a/pkg/config/testdata/addl_version_metadata_paths.yml b/pkg/config/testdata/addl_version_metadata_paths.yml new file mode 100644 index 0000000..e828cf4 --- /dev/null +++ b/pkg/config/testdata/addl_version_metadata_paths.yml @@ -0,0 +1,6 @@ +package_type: 'golang' +scm: 'github' +version_bump_type: 'major' +addl_version_metadata_paths: + node: + - 'package.json' diff --git a/pkg/engine/engine_chef.go b/pkg/engine/engine_chef.go index 23f3425..9f8a9f1 100644 --- a/pkg/engine/engine_chef.go +++ b/pkg/engine/engine_chef.go @@ -63,13 +63,17 @@ func (g *engineChef) BumpVersion() error { return perr } - if nerr := g.writeNextMetadata(g.PipelineData.GitLocalPath); nerr != nil { + if nerr := g.SetVersion(g.PipelineData.GitLocalPath, g.NextMetadata.Version); nerr != nil { return nerr } return nil } +func (g *engineChef) SetVersion(versionMetadataPath string, nextVersion string) error { + return g.writeNextMetadata(versionMetadataPath, nextVersion) +} + //private Helpers func (g *engineChef) retrieveCurrentMetadata(gitLocalPath string) error { @@ -106,6 +110,6 @@ func (g *engineChef) populateNextMetadata() error { return nil } -func (g *engineChef) writeNextMetadata(gitLocalPath string) error { - return utils.BashCmdExec(fmt.Sprintf("knife spork bump %s manual %s -o ../", path.Base(gitLocalPath), g.NextMetadata.Version), gitLocalPath, nil, "") +func (g *engineChef) writeNextMetadata(gitLocalPath string, nextVersion string) error { + return utils.BashCmdExec(fmt.Sprintf("knife spork bump %s manual %s -o ../", path.Base(gitLocalPath), nextVersion), gitLocalPath, nil, "") } diff --git a/pkg/engine/engine_generic.go b/pkg/engine/engine_generic.go index f8ac734..82b15ca 100644 --- a/pkg/engine/engine_generic.go +++ b/pkg/engine/engine_generic.go @@ -62,13 +62,17 @@ func (g *engineGeneric) BumpVersion() error { return perr } - if nerr := g.writeNextMetadata(g.PipelineData.GitLocalPath); nerr != nil { + if nerr := g.SetVersion(path.Join(g.PipelineData.GitLocalPath, g.Config.GetString(config.PACKAGR_VERSION_METADATA_PATH)), g.NextMetadata.Version); nerr != nil { return nerr } return nil } +func (g *engineGeneric) SetVersion(versionMetadataPath string, nextVersion string) error { + return g.writeNextMetadata(versionMetadataPath, nextVersion) +} + //Helpers func (g *engineGeneric) retrieveCurrentMetadata(gitLocalPath string) error { //read VERSION file. @@ -99,9 +103,9 @@ func (g *engineGeneric) populateNextMetadata() error { return nil } -func (g *engineGeneric) writeNextMetadata(gitLocalPath string) error { +func (g *engineGeneric) writeNextMetadata(gitLocalMetadataPath string, nextVersion string) error { - v, nerr := semver.NewVersion(g.NextMetadata.Version) + v, nerr := semver.NewVersion(nextVersion) if nerr != nil { return nerr } @@ -109,5 +113,5 @@ func (g *engineGeneric) writeNextMetadata(gitLocalPath string) error { template := g.Config.GetString(config.PACKAGR_GENERIC_VERSION_TEMPLATE) versionContent := fmt.Sprintf(template, v.Major(), v.Minor(), v.Patch()) - return ioutil.WriteFile(path.Join(gitLocalPath, g.Config.GetString(config.PACKAGR_VERSION_METADATA_PATH)), []byte(versionContent), 0644) + return ioutil.WriteFile(gitLocalMetadataPath, []byte(versionContent), 0644) } diff --git a/pkg/engine/engine_golang.go b/pkg/engine/engine_golang.go index 26a615d..380352e 100644 --- a/pkg/engine/engine_golang.go +++ b/pkg/engine/engine_golang.go @@ -103,13 +103,17 @@ func (g *engineGolang) BumpVersion() error { return perr } - if nerr := g.writeNextMetadata(g.PipelineData.GitLocalPath); nerr != nil { + if nerr := g.SetVersion(path.Join(g.PipelineData.GitLocalPath, g.Config.GetString(config.PACKAGR_VERSION_METADATA_PATH)), g.NextMetadata.Version); nerr != nil { return nerr } return nil } +func (g *engineGolang) SetVersion(versionMetadataPath string, nextVersion string) error { + return g.writeNextMetadata(versionMetadataPath, nextVersion) +} + //private Helpers func (g *engineGolang) retrieveCurrentMetadata(gitLocalPath string) error { @@ -149,8 +153,8 @@ func (g *engineGolang) populateNextMetadata() error { return nil } -func (g *engineGolang) writeNextMetadata(gitLocalPath string) error { - versionPath := path.Join(g.PipelineData.GitLocalPath, g.Config.GetString(config.PACKAGR_VERSION_METADATA_PATH)) +func (g *engineGolang) writeNextMetadata(gitLocalMetadataPath string, nextVersion string) error { + versionPath := gitLocalMetadataPath versionContent, rerr := ioutil.ReadFile(versionPath) if rerr != nil { return rerr @@ -165,7 +169,7 @@ func (g *engineGolang) writeNextMetadata(gitLocalPath string) error { return err } - decls, serr := g.setGoVersion(f.Decls, g.NextMetadata.Version) + decls, serr := g.setGoVersion(f.Decls, nextVersion) if serr != nil { return serr } diff --git a/pkg/engine/engine_node.go b/pkg/engine/engine_node.go index da82aa7..51a58c8 100644 --- a/pkg/engine/engine_node.go +++ b/pkg/engine/engine_node.go @@ -59,13 +59,17 @@ func (g *engineNode) BumpVersion() error { return perr } - if nerr := g.writeNextMetadata(g.PipelineData.GitLocalPath); nerr != nil { + if nerr := g.SetVersion(g.PipelineData.GitLocalPath, g.NextMetadata.Version); nerr != nil { return nerr } return nil } +func (g *engineNode) SetVersion(versionMetadataPath string, nextVersion string) error { + return g.writeNextMetadata(versionMetadataPath, nextVersion) +} + //private Helpers func (g *engineNode) retrieveCurrentMetadata(gitLocalPath string) error { @@ -95,13 +99,11 @@ func (g *engineNode) populateNextMetadata() error { return nil } -func (g *engineNode) writeNextMetadata(gitLocalPath string) error { +func (g *engineNode) writeNextMetadata(gitLocalPath string, nextVersion string) error { // The version will be bumped up via the npm version command. // --no-git-tag-version ensures that we dont create a git commit (which npm will do by default). - versionCmd := fmt.Sprintf("npm --no-git-tag-version version %s", - g.NextMetadata.Version, - ) - if verr := utils.BashCmdExec(versionCmd, g.PipelineData.GitLocalPath, nil, ""); verr != nil { + versionCmd := fmt.Sprintf("npm --no-git-tag-version version %s", nextVersion) + if verr := utils.BashCmdExec(versionCmd, gitLocalPath, nil, ""); verr != nil { return errors.EngineTestRunnerError("npm version bump failed") } return nil diff --git a/pkg/engine/engine_python.go b/pkg/engine/engine_python.go index a0440c7..066fe63 100644 --- a/pkg/engine/engine_python.go +++ b/pkg/engine/engine_python.go @@ -79,13 +79,17 @@ func (g *enginePython) BumpVersion() error { return perr } - if nerr := g.writeNextMetadata(g.PipelineData.GitLocalPath); nerr != nil { + if nerr := g.SetVersion(path.Join(g.PipelineData.GitLocalPath, g.Config.GetString(config.PACKAGR_VERSION_METADATA_PATH)), g.NextMetadata.Version); nerr != nil { return nerr } return nil } +func (g *enginePython) SetVersion(versionMetadataPath string, nextVersion string) error { + return g.writeNextMetadata(versionMetadataPath, nextVersion) +} + //private Helpers func (g *enginePython) retrieveCurrentMetadata(gitLocalPath string) error { @@ -110,6 +114,6 @@ func (g *enginePython) populateNextMetadata() error { return nil } -func (g *enginePython) writeNextMetadata(gitLocalPath string) error { - return ioutil.WriteFile(path.Join(gitLocalPath, g.Config.GetString(config.PACKAGR_VERSION_METADATA_PATH)), []byte(g.NextMetadata.Version), 0644) +func (g *enginePython) writeNextMetadata(gitLocalMetadataPath string, nextVersion string) error { + return ioutil.WriteFile(gitLocalMetadataPath, []byte(nextVersion), 0644) } diff --git a/pkg/engine/engine_ruby.go b/pkg/engine/engine_ruby.go index b5e9e1a..e5d88a0 100644 --- a/pkg/engine/engine_ruby.go +++ b/pkg/engine/engine_ruby.go @@ -81,13 +81,17 @@ func (g *engineRuby) BumpVersion() error { return perr } - if nerr := g.writeNextMetadata(g.PipelineData.GitLocalPath); nerr != nil { + if nerr := g.SetVersion(path.Join(g.PipelineData.GitLocalPath, "lib", g.CurrentMetadata.Name, "version.rb"), g.NextMetadata.Version); nerr != nil { return nerr } return nil } +func (g *engineRuby) SetVersion(versionMetadataPath string, nextVersion string) error { + return g.writeNextMetadata(versionMetadataPath, nextVersion) +} + //private Helpers func (g *engineRuby) retrieveCurrentMetadata(gitLocalPath string) error { //read Gemspec file. @@ -150,14 +154,14 @@ func (g *engineRuby) populateNextMetadata() error { return nil } -func (g *engineRuby) writeNextMetadata(gitLocalPath string) error { +func (g *engineRuby) writeNextMetadata(gitLocalMetadataPath string, nextVersion string) error { - versionrbPath := path.Join(g.PipelineData.GitLocalPath, "lib", g.CurrentMetadata.Name, "version.rb") + versionrbPath := gitLocalMetadataPath versionrbContent, rerr := ioutil.ReadFile(versionrbPath) if rerr != nil { return rerr } re := regexp.MustCompile(`(\d+)\.(\d+)\.(\d+)`) - updatedContent := re.ReplaceAllLiteralString(string(versionrbContent), g.NextMetadata.Version) + updatedContent := re.ReplaceAllLiteralString(string(versionrbContent), nextVersion) return ioutil.WriteFile(versionrbPath, []byte(updatedContent), 0644) } diff --git a/pkg/engine/interface.go b/pkg/engine/interface.go index 6649101..cf8c775 100644 --- a/pkg/engine/interface.go +++ b/pkg/engine/interface.go @@ -15,6 +15,7 @@ type Interface interface { ValidateTools() error BumpVersion() error + SetVersion(versionMetadataPath string, nextVersion string) error GetCurrentMetadata() interface{} GetNextMetadata() interface{} diff --git a/pkg/pipeline.go b/pkg/pipeline.go index 427a403..7e81b20 100644 --- a/pkg/pipeline.go +++ b/pkg/pipeline.go @@ -69,6 +69,25 @@ func (p *Pipeline) Start(configData config.Interface) error { os.Exit(1) } + //find addl version files to bump + for engineType, paths := range p.Config.GetStringMap(config.PACKAGR_ADDL_VERSION_METADATA_PATHS) { + //process additional paths, setting version to bumped version + + addlMetadataEngine, err := engine.Create(engineType, p.Data, p.Config, sourceScm) + if err != nil { + fmt.Printf("FATAL: %+v\n", err) + os.Exit(1) + } + for _, metadataPath := range paths.([]string) { + err = addlMetadataEngine.SetVersion(metadataPath, p.Data.ReleaseVersion) + if err != nil { + fmt.Printf("FATAL: %+v\n", err) + os.Exit(1) + } + } + + } + //notify the SCM after the run is complete. if err := p.Scm.SetOutput("release_version", p.Data.ReleaseVersion); err != nil { fmt.Printf("FATAL: %+v\n", err) From f64accb18a8b35f10735246e21982bba638e76db Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Thu, 17 Nov 2022 07:57:43 -0800 Subject: [PATCH 2/3] remove dep use for mac compilation. --- go.mod | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 8eb0039..2547cf3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/packagrio/bumpr -go 1.13 +go 1.18 require ( github.com/Masterminds/semver v1.5.0 @@ -12,7 +12,6 @@ require ( github.com/stretchr/testify v1.6.1 github.com/urfave/cli v1.22.4 golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect - golang.org/x/sys v0.2.0 // indirect gopkg.in/yaml.v2 v2.3.0 ) From 7c26e1eb288b171bed13dcf13b631ef35ad20e17 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Thu, 17 Nov 2022 08:03:53 -0800 Subject: [PATCH 3/3] fix test --- pkg/config/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 454d358..07089b3 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -74,6 +74,6 @@ func TestConfiguration_ReadConfig_AddlVersionMetadataPaths(t *testing.T) { require.Equal(t, "golang", testConfig.GetString(config.PACKAGR_PACKAGE_TYPE), "should populate Package Type from overrides config file") require.Equal(t, "github", testConfig.GetString(config.PACKAGR_SCM), "should populate SCM from overrides config file") require.Equal(t, "major", testConfig.GetString(config.PACKAGR_VERSION_BUMP_TYPE), "should populate Engine Version Bump Type from overrides config file") - require.Equal(t, "addl_version_metadata_paths", testConfig.GetStringMap(config.PACKAGR_ADDL_VERSION_METADATA_PATHS), "should populate addl metadata paths from config file") + require.Equal(t, map[string]interface{}{"node": []interface{}{"package.json"}}, testConfig.GetStringMap(config.PACKAGR_ADDL_VERSION_METADATA_PATHS), "should populate addl metadata paths from config file") }