@@ -2,6 +2,7 @@ package tagcmd
22
33import (
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
2022func 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 }
0 commit comments