Skip to content

Commit fdc623d

Browse files
committed
fix: barry quick fix, 2025-07-25 21:11:59
1 parent 9256128 commit fdc623d

File tree

9 files changed

+65
-49
lines changed

9 files changed

+65
-49
lines changed

cmds/cmdutils/utils.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
package cmdutils
22

33
import (
4-
"github.com/pubgo/fastcommit/utils"
5-
"github.com/pubgo/funk/assert"
64
"strings"
75

8-
"github.com/pubgo/funk/log"
9-
106
"github.com/pubgo/fastcommit/configs"
7+
"github.com/pubgo/fastcommit/utils"
8+
"github.com/pubgo/funk/log"
119
)
1210

13-
var curBranchName string
14-
15-
func GetBranchName() string {
16-
if curBranchName != "" {
17-
return curBranchName
18-
}
19-
20-
curBranchName = assert.Exit1(utils.RunOutput("git", "rev-parse", "--abbrev-ref", "HEAD"))
21-
return curBranchName
22-
}
11+
var GetBranchName = utils.Once(func() string { return utils.GetCurrentBranch().Must() })
2312

2413
func LoadConfigAndBranch() {
2514
branchName := GetBranchName()

cmds/tagcmd/cmd.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package tagcmd
22

33
import (
44
"context"
5-
"os"
65
"strings"
76
"time"
87

@@ -12,26 +11,16 @@ import (
1211
"github.com/pubgo/funk/assert"
1312
"github.com/pubgo/funk/errors"
1413
"github.com/pubgo/funk/recovery"
15-
"github.com/samber/lo"
1614
"github.com/urfave/cli/v3"
1715

1816
"github.com/pubgo/fastcommit/cmds/cmdutils"
1917
"github.com/pubgo/fastcommit/utils"
2018
)
2119

2220
func New() *cli.Command {
23-
var pushRelease bool
2421
return &cli.Command{
2522
Name: "tag",
2623
Usage: "gen tag and push origin",
27-
Flags: []cli.Flag{
28-
&cli.BoolFlag{
29-
Name: "push",
30-
Usage: "release tag and push remote",
31-
Value: pushRelease,
32-
Destination: &pushRelease,
33-
},
34-
},
3524
Action: func(ctx context.Context, command *cli.Command) error {
3625
defer recovery.Exit()
3726

@@ -70,12 +59,7 @@ func New() *cli.Command {
7059
return errors.Errorf("tag name is not valid: %s", tagName)
7160
}
7261

73-
lo.Must0(os.MkdirAll("version", 0755))
74-
lo.Must0(os.WriteFile("version/.version", []byte(tagName), 0644))
75-
76-
if pushRelease {
77-
utils.GitPushTag(tagName)
78-
}
62+
utils.GitPushTag(tagName)
7963

8064
return nil
8165
},

cmds/versioncmd/cmd.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ func New() *cli.Command {
1717
Usage: utils.UsageDesc("%s version info", version.Project()),
1818
Action: func(ctx context.Context, command *cli.Command) error {
1919
defer recovery.Exit()
20-
ver := version.Version()
2120
fmt.Println("project:", version.Project())
22-
fmt.Println("version:", ver)
21+
fmt.Println("version:", version.Version())
2322
fmt.Println("commit-id:", version.CommitID())
2423
fmt.Println("build-time:", version.BuildTime())
2524
fmt.Println("instance-id:", running.InstanceID)

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/charmbracelet/lipgloss v1.1.0
1818
github.com/charmbracelet/x/term v0.2.1
1919
github.com/cheggaaa/pb/v3 v3.1.7
20+
github.com/dave/jennifer v1.7.0
2021
github.com/deckarep/golang-set/v2 v2.8.0
2122
github.com/docker/go-units v0.5.0
2223
github.com/google/go-github/v71 v71.0.0
@@ -29,6 +30,7 @@ require (
2930
github.com/rs/zerolog v1.34.0
3031
github.com/samber/lo v1.51.0
3132
github.com/sashabaranov/go-openai v1.40.5
33+
github.com/stretchr/testify v1.10.0
3234
github.com/urfave/cli/v3 v3.3.8
3335
gopkg.in/yaml.v3 v3.0.1
3436
)
@@ -57,6 +59,7 @@ require (
5759
github.com/charmbracelet/x/ansi v0.9.3 // indirect
5860
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
5961
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 // indirect
62+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
6063
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
6164
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
6265
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
@@ -97,6 +100,7 @@ require (
97100
github.com/olekukonko/ll v0.0.9 // indirect
98101
github.com/phuslu/goid v1.0.2 // indirect
99102
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
103+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
100104
github.com/rivo/uniseg v0.4.7 // indirect
101105
github.com/rogpeppe/go-internal v1.14.1 // indirect
102106
github.com/rs/xid v1.6.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 h1:aQ3y1lwWyqYPiWZThqv
467467
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
468468
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
469469
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
470+
github.com/dave/jennifer v1.7.0 h1:uRbSBH9UTS64yXbh4FrMHfgfY762RD+C7bUPKODpSJE=
471+
github.com/dave/jennifer v1.7.0/go.mod h1:nXbxhEmQfOZhWml3D1cDK5M1FLnMSozpbFN/m3RmGZc=
470472
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
471473
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
472474
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=

utils/genversion/gen.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package genversion
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"strings"
7+
"time"
8+
9+
"github.com/dave/jennifer/jen"
10+
"github.com/pubgo/fastcommit/utils"
11+
"github.com/pubgo/funk/assert"
12+
"github.com/pubgo/funk/pathutil"
13+
)
14+
15+
func Gen(path string, version string) {
16+
pathDir := filepath.Dir(path)
17+
assert.Must(pathutil.IsNotExistMkDir(pathDir))
18+
19+
genFile := jen.NewFile("version")
20+
genFile.HeaderComment("Code generated by version. DO NOT EDIT.")
21+
genFile.HeaderComment("Code generated by version. DO NOT EDIT.")
22+
genFile.HeaderComment("Code generated by version. DO NOT EDIT.")
23+
24+
//// git rev-parse HEAD
25+
//// git describe --always --abbrev=7 --dirty
26+
//var (
27+
// commitID string
28+
// buildTime string
29+
// version = "v0.0.1-dev-99"
30+
// project = "project"
31+
//)
32+
//
33+
//// git describe --tags --abbrev=0
34+
//// git tag --sort=committerdate | tail -n 1
35+
36+
genFile.Const().Id("CommitID").Op("=").Lit("123")
37+
genFile.Const().Id("BuildTime").Op("=").Lit(time.Now().UTC().Format(time.RFC3339))
38+
genFile.Const().Id("Version").Op("=").Lit(strings.TrimSpace(version))
39+
genFile.Const().Id("Branch").Op("=").Lit(strings.TrimSpace(utils.GetCurrentBranch().Must()))
40+
genFile.Const().Id("Project").Op("=").Lit("ffff")
41+
42+
assert.Must(os.WriteFile(path, []byte(genFile.GoString()), 0644))
43+
}

utils/git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func GetCommitCount(branch string) (r result.Result[int]) {
128128
return r.WithValue(count)
129129
}
130130

131-
func GetBranch() result.Result[string] {
131+
func GetCurrentBranch() result.Result[string] {
132132
shell := "git branch --show-current"
133133
return result.Wrap(script.Exec(shell).String()).MapErr(func(err error) error {
134134
return fmt.Errorf("failed to run shell %q, err=%w", shell, err)

utils/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os/signal"
88
"strconv"
99
"strings"
10+
"sync"
1011
"syscall"
1112

1213
"github.com/bitfield/script"
@@ -18,6 +19,15 @@ import (
1819
"github.com/samber/lo"
1920
)
2021

22+
func Once[T any](do func() T) func() T {
23+
var once sync.Once
24+
var data T
25+
return func() T {
26+
once.Do(func() { data = do() })
27+
return data
28+
}
29+
}
30+
2131
func GetAllGitTags() []*semver.Version {
2232
log.Info().Msg("get all tags")
2333
var tagText = strings.TrimSpace(assert.Must1(RunOutput("git", "tag")))

version/version.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)