Skip to content

Commit

Permalink
fix: changelog tag not being removed during dry-run (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-paul-t authored Jan 17, 2023
1 parent ff334c3 commit b0023f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/git/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ func Tag(tag string) error {
return nil
}

// DeleteLocalTag will remove a local tag from the repository
// with no changes being propagated back to the remote
func DeleteLocalTag(tag string) error {
if _, err := Clean(Run("tag", "-d", tag)); err != nil {
return err
}
return nil
}

// AnnotatedTag will create an annotated tag against the repository
func AnnotatedTag(tag string, cd CommitDetails) error {
args := []string{
Expand Down
13 changes: 13 additions & 0 deletions internal/git/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,19 @@ func TestTag(t *testing.T) {
require.NoError(t, err)
}

func TestDeleteLocalTag(t *testing.T) {
tag := "1.0.0"

InitRepo(t)
EmptyCommitAndTag(t, tag, "first commit")

err := DeleteLocalTag(tag)
require.NoError(t, err)

out, _ := Clean(Run("for-each-ref", fmt.Sprintf("refs/tags/%s", tag)))
assert.Empty(t, out)
}

func TestAnnotatedTag(t *testing.T) {
InitRepo(t)

Expand Down
6 changes: 6 additions & 0 deletions internal/task/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func (t Task) Run(ctx *context.Context) error {
if err := git.Tag(ctx.NextVersion.Raw); err != nil {
return err
}
defer func() {
log.Info("removing pre-tag after changelog creation")
if err := git.DeleteLocalTag(ctx.NextVersion.Raw); err != nil {
log.WithError(err).Error("failed to delete pre-tag")
}
}()
}

// Retrieve log entries based on the changelog expectations
Expand Down

0 comments on commit b0023f5

Please sign in to comment.