From be3c956b9ade2553d2448cfb52db945395589b26 Mon Sep 17 00:00:00 2001 From: k2tzumi Date: Fri, 29 Dec 2023 20:28:53 +0900 Subject: [PATCH 1/2] refs https://github.com/Songmu/tagpr/issues/164, Refer to the next version with command --- git.go | 9 +++++++-- tagpr.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/git.go b/git.go index b6a2655..4888697 100644 --- a/git.go +++ b/git.go @@ -2,8 +2,10 @@ package tagpr import ( "bytes" + "fmt" "io" "log" + "os" "os/exec" "strings" ) @@ -20,7 +22,7 @@ func (c *commander) getGitPath() string { return c.gitPath } -func (c *commander) Cmd(prog string, args ...string) (string, string, error) { +func (c *commander) Cmd(prog string, from, to *semv, args ...string) (string, string, error) { log.Println(prog, args) var ( @@ -28,6 +30,9 @@ func (c *commander) Cmd(prog string, args ...string) (string, string, error) { errBuf bytes.Buffer ) cmd := exec.Command(prog, args...) + if from != nil && to != nil { + cmd.Env = append(os.Environ(), fmt.Sprintf("CURRENT_VERSION=%s", from.Tag()), fmt.Sprintf("NEXT_VERSION=%s", to.Tag())) + } cmd.Stdout = io.MultiWriter(&outBuf, c.outStream) cmd.Stderr = io.MultiWriter(&errBuf, c.errStream) if c.dir != "" { @@ -38,5 +43,5 @@ func (c *commander) Cmd(prog string, args ...string) (string, string, error) { } func (c *commander) Git(args ...string) (string, string, error) { - return c.Cmd(c.getGitPath(), args...) + return c.Cmd(c.getGitPath(), nil, nil, args...) } diff --git a/tagpr.go b/tagpr.go index 7c096c1..0e41f16 100644 --- a/tagpr.go +++ b/tagpr.go @@ -312,7 +312,7 @@ OUT: progArgs = []string{"-c", prog} prog = "sh" } - tp.c.Cmd(prog, progArgs...) + tp.c.Cmd(prog, currVer, nextVer, progArgs...) } if len(vfiles) > 0 && vfiles[0] != "" { From 417a3f74deae7abdc9b0cdc35ef314cc9add0aec Mon Sep 17 00:00:00 2001 From: Songmu Date: Sun, 31 Dec 2023 22:24:42 +0900 Subject: [PATCH 2/2] adjust interface of commander.Cmd --- git.go | 11 +++++++---- tagpr.go | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/git.go b/git.go index 4888697..19d70a3 100644 --- a/git.go +++ b/git.go @@ -22,7 +22,7 @@ func (c *commander) getGitPath() string { return c.gitPath } -func (c *commander) Cmd(prog string, from, to *semv, args ...string) (string, string, error) { +func (c *commander) Cmd(prog string, args []string, env map[string]string) (string, string, error) { log.Println(prog, args) var ( @@ -30,8 +30,11 @@ func (c *commander) Cmd(prog string, from, to *semv, args ...string) (string, st errBuf bytes.Buffer ) cmd := exec.Command(prog, args...) - if from != nil && to != nil { - cmd.Env = append(os.Environ(), fmt.Sprintf("CURRENT_VERSION=%s", from.Tag()), fmt.Sprintf("NEXT_VERSION=%s", to.Tag())) + if env != nil { + cmd.Env = os.Environ() + for k, v := range env { + cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v)) + } } cmd.Stdout = io.MultiWriter(&outBuf, c.outStream) cmd.Stderr = io.MultiWriter(&errBuf, c.errStream) @@ -43,5 +46,5 @@ func (c *commander) Cmd(prog string, from, to *semv, args ...string) (string, st } func (c *commander) Git(args ...string) (string, string, error) { - return c.Cmd(c.getGitPath(), nil, nil, args...) + return c.Cmd(c.getGitPath(), args, nil) } diff --git a/tagpr.go b/tagpr.go index 0e41f16..46bde44 100644 --- a/tagpr.go +++ b/tagpr.go @@ -312,7 +312,10 @@ OUT: progArgs = []string{"-c", prog} prog = "sh" } - tp.c.Cmd(prog, currVer, nextVer, progArgs...) + tp.c.Cmd(prog, progArgs, map[string]string{ + "TAGPR_CURRENT_VERSION": currVer.Tag(), + "TAGPR_NEXT_VERSION": nextVer.Tag(), + }) } if len(vfiles) > 0 && vfiles[0] != "" {