39 lines
876 B
Go
39 lines
876 B
Go
package gitea
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/magefile/mage/mg"
|
|
"github.com/magefile/mage/sh"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func CurrentRevision() string {
|
|
if mg.Verbose() {
|
|
fmt.Println("Retrieving current Git revision")
|
|
}
|
|
revision, err := sh.Output("git", "log", "--pretty=format:'%h'", "-n", "1")
|
|
if err != nil {
|
|
if mg.Verbose() {
|
|
fmt.Println(errors.Wrap(err, "error while retrieving current git revision"))
|
|
}
|
|
return ""
|
|
}
|
|
return strings.Trim(strings.TrimSpace(revision), "'")
|
|
}
|
|
|
|
func LatestTag() string {
|
|
if mg.Verbose() {
|
|
fmt.Println("Retrieving Git current branch latest tag")
|
|
}
|
|
tag, err := sh.Output("git", "describe", "--abbrev=0")
|
|
if err != nil {
|
|
if mg.Verbose() {
|
|
fmt.Println(errors.Wrap(err, "error while retrieving latest git tag"))
|
|
}
|
|
return fmt.Sprintf("0.0.0-rev.%s", CurrentRevision())
|
|
}
|
|
return strings.TrimSpace(tag)
|
|
}
|