2018-07-03 07:46:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2023-11-11 14:27:37 +00:00
|
|
|
"fmt"
|
2023-11-11 15:15:41 +00:00
|
|
|
"io/fs"
|
2018-07-03 07:46:37 +00:00
|
|
|
"os"
|
|
|
|
|
2023-11-11 14:27:37 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-07-03 07:46:37 +00:00
|
|
|
yaml "gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type configFile struct {
|
2023-11-11 15:15:41 +00:00
|
|
|
DiableTagSigning bool `yaml:"disable_signed_tags"`
|
|
|
|
|
|
|
|
MatchMajor []string `yaml:"match_major"`
|
|
|
|
MatchPatch []string `yaml:"match_patch"`
|
|
|
|
|
|
|
|
ReleaseCommitMessage string `yaml:"release_commit_message"`
|
|
|
|
|
|
|
|
IgnoreMessages []string `yaml:"ignore_messages"`
|
2023-11-12 12:11:41 +00:00
|
|
|
|
|
|
|
PreCommitCommands []string `yaml:"pre_commit_commands"`
|
2018-07-03 07:46:37 +00:00
|
|
|
}
|
|
|
|
|
2023-11-11 15:15:41 +00:00
|
|
|
func loadConfig(configFiles ...string) (*configFile, error) {
|
2018-07-03 07:46:37 +00:00
|
|
|
var err error
|
|
|
|
|
2018-07-03 07:57:07 +00:00
|
|
|
c := &configFile{}
|
2023-11-11 14:27:37 +00:00
|
|
|
if err = yaml.Unmarshal(mustAsset("assets/git_changerelease.yaml"), c); err != nil {
|
|
|
|
return nil, fmt.Errorf("unmarshalling default config: %w", err)
|
2018-07-03 07:46:37 +00:00
|
|
|
}
|
|
|
|
|
2023-11-11 15:15:41 +00:00
|
|
|
for _, fn := range configFiles {
|
|
|
|
if _, err = os.Stat(fn); err != nil {
|
|
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
|
|
logrus.WithField("path", fn).Debug("config-file does not exist, skipping")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("getting config-file stat for %q: %w", fn, err)
|
2023-11-11 14:27:37 +00:00
|
|
|
}
|
|
|
|
|
2023-11-11 15:15:41 +00:00
|
|
|
logrus.WithField("path", fn).Debug("loading config-file")
|
|
|
|
|
|
|
|
dataFile, err := os.Open(fn) //#nosec:G304 // This is intended to load variable files
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("opening config file: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = yaml.NewDecoder(dataFile).Decode(c); err != nil {
|
|
|
|
return c, fmt.Errorf("decoding config file: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := dataFile.Close(); err != nil {
|
|
|
|
logrus.WithError(err).WithField("path", fn).Debug("closing config file (leaked fd)")
|
|
|
|
}
|
2018-07-03 07:46:37 +00:00
|
|
|
}
|
|
|
|
|
2023-11-11 14:27:37 +00:00
|
|
|
return c, nil
|
2018-07-03 07:46:37 +00:00
|
|
|
}
|