Skip to content

Commit

Permalink
Add pre-release to git info (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard authored Jun 5, 2017
1 parent fd5c627 commit 71fa116
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions conform/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (

// Info contains the status of the working tree.
type Info struct {
Branch string
SHA string
Tag string
Prerelease string
IsTag bool
IsDirty bool
Branch string
SHA string
Tag string
Prerelease string
IsTag bool
IsPrerelease bool
IsDirty bool
}

// NewInfo instantiates and returns info.
Expand All @@ -37,17 +38,24 @@ func NewInfo() (info *Info, err error) {
return
}

prerelease, isPrerelease, err := Prerelease(tag, isTag)
if err != nil {
return
}

_, isDirty, err := Status()
if err != nil {
return
}

info = &Info{
Branch: branch,
SHA: sha,
Tag: strings.TrimSuffix(tag, "\n"),
IsTag: isTag,
IsDirty: isDirty,
Branch: branch,
SHA: sha,
Tag: tag,
Prerelease: prerelease,
IsTag: isTag,
IsPrerelease: isPrerelease,
IsDirty: isDirty,
}

return
Expand Down Expand Up @@ -100,8 +108,35 @@ func Tag() (tag string, isTag bool, err error) {
if err != nil {
return
}
fmt.Printf("IsTag: %v\n", isTag)
fmt.Printf("Tag: %s\n", tag)
fmt.Printf("IsTag: %v\n", isTag)

return
}

// Prerelease returns the prerelease name if the tag is a prerelease.
func Prerelease(tag string, isTag bool) (prerelease string, isPrerelease bool, err error) {
if isTag {
var ver *semver.Version
ver, err = semver.NewVersion(tag[1:])
if err != nil {
return
}
if ver.Prerelease() != "" {
prerelease = ver.Prerelease()
isPrerelease = true
}
}
err = ExportConformVar("prerelease", prerelease)
if err != nil {
return
}
err = ExportConformVar("is_prerelease", strconv.FormatBool(isPrerelease))
if err != nil {
return
}
fmt.Printf("Prerelease: %s\n", prerelease)
fmt.Printf("IsPrerelease: %v\n", isPrerelease)

return
}
Expand Down

0 comments on commit 71fa116

Please sign in to comment.