diff --git a/cmd/joj3/conf/conf.go b/cmd/joj3/conf/conf.go index f75a4d8..538967d 100644 --- a/cmd/joj3/conf/conf.go +++ b/cmd/joj3/conf/conf.go @@ -96,9 +96,14 @@ func parseMsg(confRoot, confName, msg, tag string) ( confPath string, conventionalCommit *ConventionalCommit, err error, ) { slog.Info("parse msg", "msg", msg) - conventionalCommit, err = parseConventionalCommit(msg) - if err != nil { - return + if tag == "" { + conventionalCommit, err = parseConventionalCommit(msg) + if err != nil { + return + } + } else { + conventionalCommit = new(ConventionalCommit) + conventionalCommit.Scope = tag } slog.Info("conventional commit", "commit", conventionalCommit) confRoot = filepath.Clean(confRoot) @@ -111,11 +116,6 @@ func parseMsg(confRoot, confName, msg, tag string) ( err = fmt.Errorf("invalid scope as path: %s", conventionalCommit.Scope) return } - if tag != "" && conventionalCommit.Scope != tag { - err = fmt.Errorf("tag does not match scope: %s != %s", tag, - conventionalCommit.Scope) - return - } return } @@ -156,6 +156,12 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) ( confPath, conventionalCommit, err = parseMsg(confRoot, confName, msg, tag) if err != nil { slog.Error("parse msg", "error", err) + // no fallback when tag is specified, it is triggered by release.yaml + if os.IsNotExist(err) { + slog.Info("tag is not empty, no fallback conf") + hintValidScopes(confRoot, confName) + return confPath, confStat, conventionalCommit, err + } // fallback to conf file in conf root on parse error confPath = filepath.Join(confRoot, fallbackConfName) slog.Info("fallback to conf", "path", confPath) @@ -172,10 +178,10 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) ( confStat, err = os.Stat(confPath) if err != nil { slog.Error("stat fallback conf", "error", err) - return + return confPath, confStat, conventionalCommit, err } } - return + return confPath, confStat, conventionalCommit, err } func MatchGroups(conf *Conf, conventionalCommit *ConventionalCommit) []string { diff --git a/cmd/joj3/main.go b/cmd/joj3/main.go index e0ec906..82edae5 100644 --- a/cmd/joj3/main.go +++ b/cmd/joj3/main.go @@ -29,7 +29,7 @@ func init() { flag.StringVar(&confFileRoot, "conf-root", ".", "root path for all config files") flag.StringVar(&confFileName, "conf-name", "conf.json", "filename for config files") flag.StringVar(&fallbackConfFileName, "fallback-conf-name", "", "filename for the fallback config file in conf-root, leave empty to use conf-name") - flag.StringVar(&tag, "tag", "", "tag to trigger the running, when non-empty, should equal to the scope in msg") + flag.StringVar(&tag, "tag", "", "tag to trigger the running, when non-empty, fallback will be disabled") printVersion = flag.Bool("version", false, "print current version") } diff --git a/go.sum b/go.sum index bf663f2..4ca3152 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,6 @@ github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs= github.com/criyle/go-judge/pb v1.0.0 h1:8A4zHPPCGCDTuFY1GW5Hqpg+8ETIwzgXxiRpYKKb2zA= github.com/criyle/go-judge/pb v1.0.0/go.mod h1:hjgixgK9NH9ktwc29xbXVdZDOlKfEkRkEbZ4W5bOMmw= -github.com/criyle/go-judge/pb v1.2.0 h1:XqR1CEE9ZR7+4nYPZqwIure4VuJOt4kmFygN7aeXeJg= -github.com/criyle/go-judge/pb v1.2.0/go.mod h1:oANRvhBOHpu4WZhbWnm5IeTaLmTbGdZNUNwcnmQe6jI= github.com/cyphar/filepath-securejoin v0.5.0 h1:hIAhkRBMQ8nIeuVwcAoymp7MY4oherZdAxD+m0u9zaw= github.com/cyphar/filepath-securejoin v0.5.0/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=