@@ -3,44 +3,55 @@ package main
33import (
44 "errors"
55 "fmt"
6+ "io/fs"
67 "os"
78
89 "github.com/sirupsen/logrus"
910 yaml "gopkg.in/yaml.v2"
1011)
1112
1213type configFile struct {
13- DiableTagSigning bool `yaml:"disable_signed_tags"`
14- MatchMajor []string `yaml:"match_major"`
15- MatchPatch []string `yaml:"match_patch"`
16- ReleaseCommitMessage string `yaml:"release_commit_message"`
17- IgnoreMessages []string `yaml:"ignore_messages"`
14+ DiableTagSigning bool `yaml:"disable_signed_tags"`
15+
16+ MatchMajor []string `yaml:"match_major"`
17+ MatchPatch []string `yaml:"match_patch"`
18+
19+ ReleaseCommitMessage string `yaml:"release_commit_message"`
20+
21+ IgnoreMessages []string `yaml:"ignore_messages"`
1822}
1923
20- func loadConfig () (* configFile , error ) {
24+ func loadConfig (configFiles ... string ) (* configFile , error ) {
2125 var err error
2226
23- if _ , err = os .Stat (cfg .ConfigFile ); err != nil {
24- return nil , errors .New ("config file does not exist, use --create-config to create one" )
25- }
26-
2727 c := & configFile {}
2828 if err = yaml .Unmarshal (mustAsset ("assets/git_changerelease.yaml" ), c ); err != nil {
2929 return nil , fmt .Errorf ("unmarshalling default config: %w" , err )
3030 }
3131
32- dataFile , err := os . Open ( cfg . ConfigFile )
33- if err != nil {
34- return nil , fmt . Errorf ( "opening config file: %w" , err )
35- }
36- defer func () {
37- if err := dataFile . Close (); err != nil {
38- logrus . WithError ( err ). Debug ( "closing config file (leaked fd)" )
32+ for _ , fn := range configFiles {
33+ if _ , err = os . Stat ( fn ); err != nil {
34+ if errors . Is ( err , fs . ErrNotExist ) {
35+ logrus . WithField ( "path" , fn ). Debug ( "config-file does not exist, skipping" )
36+ continue
37+ }
38+ return nil , fmt . Errorf ( "getting config- file stat for %q: %w" , fn , err )
3939 }
40- }()
4140
42- if err = yaml .NewDecoder (dataFile ).Decode (c ); err != nil {
43- return c , fmt .Errorf ("decoding config file: %w" , err )
41+ logrus .WithField ("path" , fn ).Debug ("loading config-file" )
42+
43+ dataFile , err := os .Open (fn ) //#nosec:G304 // This is intended to load variable files
44+ if err != nil {
45+ return nil , fmt .Errorf ("opening config file: %w" , err )
46+ }
47+
48+ if err = yaml .NewDecoder (dataFile ).Decode (c ); err != nil {
49+ return c , fmt .Errorf ("decoding config file: %w" , err )
50+ }
51+
52+ if err := dataFile .Close (); err != nil {
53+ logrus .WithError (err ).WithField ("path" , fn ).Debug ("closing config file (leaked fd)" )
54+ }
4455 }
4556
4657 return c , nil
0 commit comments