diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..e53fce3 --- /dev/null +++ b/build.sh @@ -0,0 +1,11 @@ +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/pkg/config/config.go b/pkg/config/config.go index 296a819..b9a1a5c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1,7 +1,12 @@ package config import ( + stderrors "errors" + "fmt" + "github.com/analogj/go-util/utils" "github.com/spf13/viper" + "log" + "os" ) // When initializing this class the following methods must be called: @@ -26,6 +31,7 @@ func (c *configuration) Init() error { c.SetDefault(PACKAGR_PACKAGE_TYPE, "generic") c.SetDefault(PACKAGR_SCM, "default") c.SetDefault(PACKAGR_VERSION_BUMP_TYPE, "patch") + c.SetDefault(PACKAGR_ENGINE_REPO_CONFIG_PATH, "packagr.yml") //set the default system config file search path. //if you want to load a non-standard location system config file (~/capsule.yml), use ReadConfig @@ -41,3 +47,29 @@ func (c *configuration) Init() error { return nil } + +func (c *configuration) ReadConfig(configFilePath string) error { + + if !utils.FileExists(configFilePath) { + message := fmt.Sprintf("The configuration file (%s) could not be found. Skipping", configFilePath) + log.Printf(message) + return stderrors.New(message) + } + + log.Printf("Loading configuration file: %s", configFilePath) + + config_data, err := os.Open(configFilePath) + if err != nil { + log.Printf("Error reading configuration file: %s", err) + return err + } + err = c.MergeConfig(config_data) + if err != nil { + 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/interface.go b/pkg/config/interface.go index ae8c3c9..1795144 100644 --- a/pkg/config/interface.go +++ b/pkg/config/interface.go @@ -18,10 +18,12 @@ type Interface interface { GetString(key string) string GetStringSlice(key string) []string UnmarshalKey(key string, rawVal interface{}, decoder ...viper.DecoderConfigOption) error + ReadConfig(configFilePath string) error } 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_ENGINE_REPO_CONFIG_PATH = "engine_repo_config_path" const PACKAGR_GENERIC_VERSION_TEMPLATE = "generic_version_template" diff --git a/pkg/pipeline.go b/pkg/pipeline.go index 68f71da..49d979f 100644 --- a/pkg/pipeline.go +++ b/pkg/pipeline.go @@ -1,12 +1,16 @@ package pkg import ( + "errors" "fmt" + "github.com/analogj/go-util/utils" "github.com/packagrio/bumpr/pkg/config" "github.com/packagrio/bumpr/pkg/engine" "github.com/packagrio/go-common/pipeline" "github.com/packagrio/go-common/scm" + "log" "os" + "path" "path/filepath" ) @@ -22,6 +26,11 @@ 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 @@ -67,3 +76,19 @@ func (p *Pipeline) Start(configData config.Interface) error { fmt.Printf("version bumped to %s", p.Data.ReleaseVersion) return nil } + +func (p *Pipeline) ParseRepoConfig() error { + log.Println("parse_repo_config") + // update the config with repo config file options + repoConfig := path.Join(p.Data.GitLocalPath, p.Config.GetString(config.PACKAGR_ENGINE_REPO_CONFIG_PATH)) + if utils.FileExists(repoConfig) { + log.Println("Found config file in working dir!") + if err := p.Config.ReadConfig(repoConfig); err != nil { + return errors.New("An error occured while parsing repository packagr.yml file") + } + } else { + log.Println("No repo packagr.yml file found, using existing config.") + } + + return nil +}