Skip to content

Commit

Permalink
Merge pull request #4 from PackagrIO/configfile
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ authored Mar 17, 2022
2 parents 7e49cff + 9e07205 commit 000c9e5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
19 changes: 19 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/analogj/go-util/utils"
"github.com/packagrio/publishr/pkg/config"
"github.com/stretchr/testify/require"
"path"
"testing"
)

Expand All @@ -21,6 +22,24 @@ func TestConfiguration_init_ShouldCorrectlyInitializeConfiguration(t *testing.T)
require.Equal(t, "default", testConfig.GetString(config.PACKAGR_SCM), "should populate scm with default")
}

func TestConfiguration_ReadConfig(t *testing.T) {
//setup
defer utils.UnsetEnv("PACKAGR_")()
testConfig, _ := config.Create()
testConfig.SetDefault(config.PACKAGR_PACKAGE_TYPE, "generic")
testConfig.SetDefault(config.PACKAGR_SCM, "default")

//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")

}


//func TestConfiguration_init_EnvVariablesShouldLoadProperly(t *testing.T) {
// //setup
// os.Setenv("PACKAGR_VERSION_BUMP_TYPE", "major")
Expand Down
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'
19 changes: 11 additions & 8 deletions pkg/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/packagrio/publishr/pkg/mgr"
"log"
"path"
"os"
"path/filepath"
)

type Pipeline struct {
Expand All @@ -27,10 +29,6 @@ func (p *Pipeline) Start(config config.Interface) error {
p.Config = config
p.Data = new(pipeline.Data)

if err := p.ParseRepoConfig(); err != nil {
return err
}

if err := p.PipelineInitStep(); err != nil {
return err
}
Expand All @@ -45,10 +43,6 @@ func (p *Pipeline) Start(config config.Interface) error {
return perr
}

if err := p.ParseRepoConfig(); err != nil {
return err
}

if err := p.ValidateTools(); err != nil {
return err
}
Expand Down Expand Up @@ -83,6 +77,15 @@ func (p *Pipeline) Start(config config.Interface) error {
func (p *Pipeline) PipelineInitStep() error {
// start the source, and whatever work needs to be done there.
// MUST set options.GitParentPath
cwdPath, _ := os.Getwd()
p.Data.GitLocalPath = cwdPath
p.Data.GitParentPath = filepath.Dir(cwdPath)

if err := p.ParseRepoConfig(); err != nil {
return err
}


log.Println("pipeline_init_step")
scmImpl, serr := scm.Create(p.Config.GetString(config.PACKAGR_SCM), p.Data, p.Config, nil)
if serr != nil {
Expand Down

0 comments on commit 000c9e5

Please sign in to comment.