Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ By default `gt` will throw an error when you try to increment a tag on commit, t

In order to skip this error - provide additional flag to increment command like
that: `gt t i min --ignore-exists-tag`.

### Examples

```shell
# Get last semver tag in this repo
$ gt tag last
v1.9.0 (c2e70ec90579ba18fd73078e98f677aec75ae002)

# Show only tag name (useful for ci/cd)
$ gt tag last -f tag
v1.9.0
```
35 changes: 32 additions & 3 deletions cmd/gt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import (
const (
flagRepoPath = "repo"
flagIgnoreExistsTag = "ignore-exists-tag"
flagFormat = "format"
)

const (
formatFull = "full"
formatTagOnly = "tag"
)

var (
Expand Down Expand Up @@ -81,8 +87,18 @@ func main() {
{
Name: "last",
Aliases: []string{"l"},
Action: withManager(cmdTagGetSemverLast),
Usage: "show last semver tag",
Flags: []cli.Flag{
&cli.StringFlag{
Name: flagFormat,
Usage: "will change the output format",
Value: formatFull,
Aliases: []string{"f"},
OnlyOnce: true,
Required: false,
},
},
Action: withManager(cmdTagGetSemverLast),
Usage: "show last semver tag",
},
},
},
Expand Down Expand Up @@ -176,12 +192,25 @@ func buildTagIncrementor(component repomanager.Component) func(context.Context,
}

func cmdTagGetSemverLast(ctx context.Context, c *cli.Command, m *repomanager.Manager) error {
format := c.String(flagFormat)
switch format {
default:
return fmt.Errorf("unknown format: %s", format)
case formatFull, formatTagOnly:
}

maxTag, err := m.GetTagsSemverMax()
if err != nil {
return fmt.Errorf("cannot get max tag: %w", err)
}

fmt.Printf("%s (%s)\n", maxTag.TagName(), maxTag.Ref.Hash())
switch format {
case formatFull:
fmt.Printf("%s (%s)\n", maxTag.TagName(), maxTag.Ref.Hash())
case formatTagOnly:
fmt.Printf("%s\n", maxTag.TagName())
}

return nil
}

Expand Down