Skip to content

Commit

Permalink
fixing bumpr merge. If cli flags have not been passed, dont override …
Browse files Browse the repository at this point in the history
…values from config file.
  • Loading branch information
AnalogJ committed Mar 10, 2022
1 parent 4e97c37 commit fe84bd5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
11 changes: 0 additions & 11 deletions build.sh

This file was deleted.

9 changes: 7 additions & 2 deletions cmd/bumpr/bumpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 0 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
19 changes: 19 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/packagrio/bumpr/pkg/config"
"github.com/stretchr/testify/require"
"os"
"path"
"testing"
)

Expand Down Expand Up @@ -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")

}
3 changes: 3 additions & 0 deletions pkg/config/testdata/simple_overrides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package_type: 'golang'
scm: 'github'
version_bump_type: 'major'
10 changes: 5 additions & 5 deletions pkg/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fe84bd5

Please sign in to comment.