Skip to content

Commit 9256128

Browse files
committed
fix: barry quick fix, 2025-07-25 16:49:15
1 parent 5e4f74c commit 9256128

File tree

6 files changed

+46
-7
lines changed

6 files changed

+46
-7
lines changed

cmds/tagcmd/cmd.go

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

33
import (
44
"context"
5+
"os"
56
"strings"
67
"time"
78

@@ -11,16 +12,26 @@ import (
1112
"github.com/pubgo/funk/assert"
1213
"github.com/pubgo/funk/errors"
1314
"github.com/pubgo/funk/recovery"
15+
"github.com/samber/lo"
1416
"github.com/urfave/cli/v3"
1517

1618
"github.com/pubgo/fastcommit/cmds/cmdutils"
1719
"github.com/pubgo/fastcommit/utils"
1820
)
1921

2022
func New() *cli.Command {
23+
var pushRelease bool
2124
return &cli.Command{
2225
Name: "tag",
2326
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+
},
2435
Action: func(ctx context.Context, command *cli.Command) error {
2536
defer recovery.Exit()
2637

@@ -56,10 +67,16 @@ func New() *cli.Command {
5667
tagName = m1.Value()
5768
_, err := semver.NewVersion(tagName)
5869
if err != nil {
59-
return errors.Format("tag name is not valid: %s", tagName)
70+
return errors.Errorf("tag name is not valid: %s", tagName)
71+
}
72+
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)
6078
}
6179

62-
utils.GitPushTag(tagName)
6380
return nil
6481
},
6582
}

cmds/versioncmd/cmd.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package versioncmd
33
import (
44
"context"
55
"fmt"
6-
6+
77
"github.com/pubgo/fastcommit/utils"
88
"github.com/pubgo/funk/recovery"
99
"github.com/pubgo/funk/running"
@@ -17,8 +17,9 @@ 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()
2021
fmt.Println("project:", version.Project())
21-
fmt.Println("version:", version.Version())
22+
fmt.Println("version:", ver)
2223
fmt.Println("commit-id:", version.CommitID())
2324
fmt.Println("build-time:", version.BuildTime())
2425
fmt.Println("instance-id:", running.InstanceID)

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package main
22

33
import (
4-
"github.com/pubgo/fastcommit/bootstrap"
5-
64
_ "github.com/lithammer/fuzzysearch/fuzzy"
5+
"github.com/pubgo/fastcommit/bootstrap"
76
)
87

98
func main() {

utils/git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func GetBranch() result.Result[string] {
135135
})
136136
}
137137

138-
func pushTag(tag string) result.Error {
138+
func PushTag(tag string) result.Error {
139139
shell := fmt.Sprintf("git push origin %s", tag)
140140
return result.ErrOf(script.Exec(shell).Error()).Map(func(err error) error {
141141
return fmt.Errorf("failed to run shell %q, err=%w", shell, err)

utils/util.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ func GetAllGitTags() []*semver.Version {
4040
return versions
4141
}
4242

43+
func GetCurMaxVer() *semver.Version {
44+
tags := GetAllGitTags()
45+
return typex.DoBlock1(func() *semver.Version {
46+
return lo.MaxBy(tags, func(a *semver.Version, b *semver.Version) bool { return a.Compare(b) > 0 })
47+
})
48+
}
49+
4350
func GetNextReleaseTag(tags []*semver.Version) *semver.Version {
4451
var curMaxVer = typex.DoBlock1(func() *semver.Version {
4552
return lo.MaxBy(tags, func(a *semver.Version, b *semver.Version) bool { return a.Compare(b) > 0 })

version/version.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package version
2+
3+
var mainPath string
4+
5+
// git rev-parse HEAD
6+
// git describe --always --abbrev=7 --dirty
7+
var (
8+
commitID string
9+
buildTime string
10+
version = "v0.0.1-dev-99"
11+
project = "project"
12+
)
13+
14+
// git describe --tags --abbrev=0
15+
// git tag --sort=committerdate | tail -n 1

0 commit comments

Comments
 (0)