Skip to content

Commit

Permalink
fix: handle remaking tag
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjohnson145 committed Dec 18, 2022
1 parent fd9dadc commit 390863f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ outputs:
description: 'Id of the newly created tag, if tag was created'
runs:
using: docker
image: docker://ghcr.io/nicjohnson145/tagbot:v0.5.2
image: docker://ghcr.io/nicjohnson145/tagbot:latest
args:
- "--maintain-latest"
12 changes: 12 additions & 0 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ func (g *GitRepo) MakeTagHead(name string) error {
return g.MakeTag(name, h.Hash())
}

func (g *GitRepo) RemakeTagHead(name string) error {
h, err := g.repo.Head()
if err != nil {
return fmt.Errorf("error getting repo head: %w", err)
}
err = g.repo.DeleteTag(name)
if err != nil && !errors.Is(err, git.ErrTagNotFound) {
return fmt.Errorf("error deleting old tag: %w", err)
}
return g.MakeTag(name, h.Hash())
}

func (g *GitRepo) MakeTag(name string, hash plumbing.Hash) error {
_, err := g.repo.CreateTag(name, hash, &git.CreateTagOptions{
Message: "created by TagBot",
Expand Down
2 changes: 1 addition & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func IncrementTag(opts IncrementOpts) error {
}
if opts.MaintainLatest {
log.Debugf("creating latest tag")
if err := repo.MakeTagHead("latest"); err != nil {
if err := repo.RemakeTagHead("latest"); err != nil {
return err
}
if err := repo.ForcePushTags(); err != nil {
Expand Down

0 comments on commit 390863f

Please sign in to comment.