Skip to content

Commit

Permalink
Add broken support for git packagr.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
zshel committed Mar 10, 2022
1 parent 32fd460 commit 4e97c37
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
11 changes: 11 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
}
2 changes: 2 additions & 0 deletions pkg/config/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
25 changes: 25 additions & 0 deletions pkg/pipeline.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 4e97c37

Please sign in to comment.