Skip to content

Commit

Permalink
fix(tag): directly update refs rather than delete+create (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
isometry committed Sep 20, 2024
1 parent 01f56d9 commit e0b979a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func runTagCmd(cmd *cobra.Command, args []string) (err error) {
annotatedTag := &github.Tag{
Tag: &tagName,
Message: &message,
// Message: github.String("hard-coded message"),
Object: &github.GitObject{
Type: github.String("commit"),
SHA: github.String(branchRef.Object.GetSHA()),
Expand All @@ -95,24 +94,25 @@ func runTagCmd(cmd *cobra.Command, args []string) (err error) {
tagRefObject = branchRef.Object.GetSHA()
}

if existingTagRef != nil {
log.Infof("deleting existing tag reference")
if _, err := client.V3.Git.DeleteRef(ctx, owner, repo, existingTagRef.GetRef()); err != nil {
return errors.Wrap(err, "DeleteRef")
}
}

tagRef := &github.Reference{
Ref: &tagRefName,
Object: &github.GitObject{
SHA: github.String(tagRefObject),
},
}

log.Infof("creating tag reference")
_, _, err = client.V3.Git.CreateRef(ctx, owner, repo, tagRef)
if err != nil {
return errors.Wrap(err, "CreateRef")
if existingTagRef == nil {
log.Infof("creating tag reference")
_, _, err = client.V3.Git.CreateRef(ctx, owner, repo, tagRef)
if err != nil {
return errors.Wrap(err, "CreateRef")
}
} else {
log.Infof("updating tag reference")
_, _, err = client.V3.Git.UpdateRef(ctx, owner, repo, tagRef, true)
if err != nil {
return errors.Wrap(err, "UpdateRef")
}
}

fmt.Printf("https://github.com/%s/%s/releases/tag/%s\n", owner, repo, tagName)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/cloudflare/circl v1.4.0 // indirect
github.com/cyphar/filepath-securejoin v0.3.1 // indirect
github.com/cyphar/filepath-securejoin v0.3.2 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUK
github.com/cloudflare/circl v1.4.0 h1:BV7h5MgrktNzytKmWjpOtdYrf0lkkbF8YMlBGPhJQrY=
github.com/cloudflare/circl v1.4.0/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cyphar/filepath-securejoin v0.3.1 h1:1V7cHiaW+C+39wEfpH6XlLBQo3j/PciWFrgfCLS8XrE=
github.com/cyphar/filepath-securejoin v0.3.1/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc=
github.com/cyphar/filepath-securejoin v0.3.2 h1:QhZu5AxQ+o1XZH0Ye05YzvJ0kAdK6VQc0z9NNMek7gc=
github.com/cyphar/filepath-securejoin v0.3.2/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down

0 comments on commit e0b979a

Please sign in to comment.