1515package main
1616
1717import (
18+ "context"
1819 "fmt"
1920 "io/fs"
2021 "os"
@@ -53,7 +54,7 @@ func ReleaseCommand(cfg Config) (*cobra.Command, error) {
5354 bump := & cobra.Command {
5455 Use : "bump [OPTIONS] <module>" ,
5556 Args : cobra .ExactArgs (1 ),
56- RunE : func (_ * cobra.Command , args []string ) error {
57+ RunE : func (cmd * cobra.Command , args []string ) error {
5758 mod := args [0 ]
5859 data , err := newRepoData (cfg .EnableModulesWithPreReleaseVersion )
5960 if err != nil {
@@ -67,9 +68,9 @@ func ReleaseCommand(cfg Config) (*cobra.Command, error) {
6768 if ! ok {
6869 return fmt .Errorf ("module %s not found" , mod )
6970 }
70- return helper .BumpModule (mod , opts .level , modData , & projectFS {opts : opts , beforeCommitHook : cfg .BeforeCommitHook , logger : logging .NewDefaultLogger ("" )})
71+ return helper .BumpModule (cmd . Context (), mod , opts .level , modData , & projectFS {opts : opts , beforeCommitHook : cfg .BeforeCommitHook , logger : logging .NewDefaultLogger ("" )})
7172 }
72- return helper .BumpIterative (mod , opts .level , data , & projectFS {opts : opts , beforeCommitHook : cfg .BeforeCommitHook , logger : logging .NewDefaultLogger ("" )})
73+ return helper .BumpIterative (cmd . Context (), mod , opts .level , data , & projectFS {opts : opts , beforeCommitHook : cfg .BeforeCommitHook , logger : logging .NewDefaultLogger ("" )})
7374 },
7475 }
7576
@@ -136,7 +137,7 @@ func (m projectFS) BumpModInFile(filename, mod, version string) (bool, error) {
136137 return needsAction , os .WriteFile (filename , out , perm )
137138}
138139
139- func (m projectFS ) GitTag (tag string ) error {
140+ func (m projectFS ) GitTag (ctx context. Context , tag string ) error {
140141 var prefix string
141142 if m .skipGit {
142143 prefix = "[skip] "
@@ -145,16 +146,16 @@ func (m projectFS) GitTag(tag string) error {
145146 if m .dryRun || m .skipGit {
146147 return nil
147148 }
148- if err := gitTag (tag ); err != nil {
149+ if err := gitTag (ctx , tag ); err != nil {
149150 return err
150151 }
151152 if ! m .noPropagate && ! m .dryRun {
152- return gitPushTags ()
153+ return gitPushTags (ctx )
153154 }
154155 return nil
155156}
156157
157- func (m projectFS ) GitCommit (commit string ) error {
158+ func (m projectFS ) GitCommit (ctx context. Context , commit string ) error {
158159 if ! m .dryRun && m .beforeCommitHook != nil {
159160 if err := m .beforeCommitHook (); err != nil {
160161 return err
@@ -168,7 +169,7 @@ func (m projectFS) GitCommit(commit string) error {
168169 if m .dryRun || m .skipGit {
169170 return nil
170171 }
171- return gitCommit (commit )
172+ return gitCommit (ctx , commit )
172173}
173174
174175func newRepoData (versionExtraAllowList []string ) (helper.RepoData , error ) {
@@ -260,24 +261,24 @@ func getLatestVersion(modName string) (string, error) {
260261 return strings .TrimPrefix (latest , prefix ), nil
261262}
262263
263- func gitTag (tag string ) error {
264- cmd := exec .Command ( "git" , "tag" , tag )
264+ func gitTag (ctx context. Context , tag string ) error {
265+ cmd := exec .CommandContext ( ctx , "git" , "tag" , tag , "-m " , tag )
265266 if out , err := cmd .CombinedOutput (); err != nil {
266267 return fmt .Errorf ("git tag (%s): %s" , err , string (out ))
267268 }
268269 return nil
269270}
270271
271- func gitPushTags () error {
272- cmd := exec .Command ( "git" , "push" , "--tags" )
272+ func gitPushTags (ctx context. Context ) error {
273+ cmd := exec .CommandContext ( ctx , "git" , "push" , "--tags" )
273274 if out , err := cmd .CombinedOutput (); err != nil {
274275 return fmt .Errorf ("git push --tags (%s): %s" , err , string (out ))
275276 }
276277 return nil
277278}
278279
279- func gitCommit (commit string ) error {
280- cmd := exec .Command ( "git" , "commit" , "-am" , commit )
280+ func gitCommit (ctx context. Context , commit string ) error {
281+ cmd := exec .CommandContext ( ctx , "git" , "commit" , "-am" , commit )
281282 if out , err := cmd .CombinedOutput (); err != nil {
282283 return fmt .Errorf ("git commit (%s): %s" , err , string (out ))
283284 }
0 commit comments