From fe84bd55b5177468d9b8ae941eb15936b3cbbb1d Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Thu, 10 Mar 2022 12:15:22 -0800 Subject: [PATCH] fixing bumpr merge. If cli flags have not been passed, dont override values from config file. --- build.sh | 11 ----------- cmd/bumpr/bumpr.go | 9 +++++++-- pkg/config/config.go | 3 --- pkg/config/config_test.go | 19 +++++++++++++++++++ pkg/config/testdata/simple_overrides.yml | 3 +++ pkg/pipeline.go | 10 +++++----- 6 files changed, 34 insertions(+), 21 deletions(-) delete mode 100644 build.sh create mode 100644 pkg/config/testdata/simple_overrides.yml diff --git a/build.sh b/build.sh deleted file mode 100644 index e53fce3..0000000 --- a/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -echo 'Cleaning workspace' -rm -f ./packagr-bumper-linux-amd64 -echo 'Setting up prereqs' -go mod vendor -mkdir -p vendor/gopkg.in/libgit2/git2go.v25/vendor/libgit2/build/ -cp /usr/local/linux/lib/pkgconfig/libgit2.pc vendor/gopkg.in/libgit2/git2go.v25/vendor/libgit2/build/libgit2.pc -echo 'Testing' -go test -mod vendor -v -tags "static" $(go list ./... | grep -v /vendor/) -# build linux binary -echo 'Build binary' -. /scripts/toolchains/linux/linux-build-env.sh && go build -mod vendor -ldflags "-X main.goos=linux -X main.goarch=amd64" -o packagr-bumpr-linux-amd64 -tags "static" cmd/bumpr/bumpr.go \ No newline at end of file diff --git a/cmd/bumpr/bumpr.go b/cmd/bumpr/bumpr.go index 44a8ca3..d6ec204 100644 --- a/cmd/bumpr/bumpr.go +++ b/cmd/bumpr/bumpr.go @@ -54,8 +54,13 @@ func main() { Action: func(c *cli.Context) error { configuration, _ := config.Create() - configuration.Set(config.PACKAGR_SCM, c.String("scm")) - configuration.Set(config.PACKAGR_PACKAGE_TYPE, c.String("package_type")) + if c.IsSet("scm") { + configuration.Set(config.PACKAGR_SCM, c.String("scm")) + } + if c.IsSet("package_type") { + configuration.Set(config.PACKAGR_PACKAGE_TYPE, c.String("package_type")) + } + //config.Set("dry_run", c.String("dry_run")) fmt.Println("package type:", configuration.GetString(config.PACKAGR_PACKAGE_TYPE)) diff --git a/pkg/config/config.go b/pkg/config/config.go index b9a1a5c..d58faa4 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -68,8 +68,5 @@ func (c *configuration) ReadConfig(configFilePath string) error { log.Printf("Error merging config file: %s", err) return err } - log.Println("[new] package type:", c.GetString(PACKAGR_PACKAGE_TYPE)) - log.Println("[new] scm:", c.GetString(PACKAGR_SCM)) - log.Println("[new] bump type:", c.GetString(PACKAGR_VERSION_BUMP_TYPE)) return nil } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 52c99b2..574e435 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -5,6 +5,7 @@ import ( "github.com/packagrio/bumpr/pkg/config" "github.com/stretchr/testify/require" "os" + "path" "testing" ) @@ -36,3 +37,21 @@ func TestConfiguration_init_EnvVariablesShouldLoadProperly(t *testing.T) { //teardown os.Unsetenv("PACKAGR_VERSION_BUMP_TYPE") } + +func TestConfiguration_ReadConfig(t *testing.T) { + //setup + 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", "simple_overrides.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") + +} diff --git a/pkg/config/testdata/simple_overrides.yml b/pkg/config/testdata/simple_overrides.yml new file mode 100644 index 0000000..1ee8806 --- /dev/null +++ b/pkg/config/testdata/simple_overrides.yml @@ -0,0 +1,3 @@ +package_type: 'golang' +scm: 'github' +version_bump_type: 'major' \ No newline at end of file diff --git a/pkg/pipeline.go b/pkg/pipeline.go index 49d979f..28fab46 100644 --- a/pkg/pipeline.go +++ b/pkg/pipeline.go @@ -26,16 +26,16 @@ func (p *Pipeline) Start(configData config.Interface) error { p.Config = configData p.Data = new(pipeline.Data) - //Parse Repo config if present. - if err := p.ParseRepoConfig(); err != nil { - return err - } - //by default the current working directory is the local directory to execute in cwdPath, _ := os.Getwd() p.Data.GitLocalPath = cwdPath p.Data.GitParentPath = filepath.Dir(cwdPath) + //Parse Repo config if present. + if err := p.ParseRepoConfig(); err != nil { + return err + } + sourceScm, err := scm.Create(p.Config.GetString(config.PACKAGR_SCM), p.Data, p.Config, nil) if err != nil { fmt.Printf("FATAL: %+v\n", err)