1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-18 03:56:52 +02:00

git tags and diff

This commit is contained in:
Carlos Alexandro Becker 2016-12-21 15:03:07 -02:00
parent d8bb50f799
commit 2aa160ffca
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
3 changed files with 66 additions and 1 deletions

18
git/log.go Normal file
View File

@ -0,0 +1,18 @@
package git
import "os/exec"
func Log(previous, current string) (str string, err error) {
cmd := exec.Command(
"git",
"log",
"--pretty=oneline",
"--abbrev-commit",
previous+".."+current,
)
bts, err := cmd.CombinedOutput()
if err != nil {
return str, err
}
return string(bts), err
}

34
git/tag.go Normal file
View File

@ -0,0 +1,34 @@
package git
import (
"os/exec"
"strings"
)
func CurrentTag() (tag string, err error) {
return getTag("master")
}
func PreviousTag() (tag string, err error) {
current, err := CurrentTag()
if err != nil {
return tag, err
}
return getTag(current + "^")
}
func getTag(ref string) (tag string, err error) {
cmd := exec.Command(
"git",
"describe",
"--tags",
"--abbrev=0",
"--always",
ref,
)
bts, err := cmd.CombinedOutput()
if err != nil {
return tag, err
}
return strings.Split(string(bts), "\n")[0], err
}

15
main.go
View File

@ -2,9 +2,11 @@ package main
import (
"fmt"
"log"
"github.com/goreleaser/releaser/build"
"github.com/goreleaser/releaser/config"
"github.com/goreleaser/releaser/git"
)
var version = "none"
@ -14,6 +16,17 @@ func main() {
if err != nil {
panic(err)
}
err = build.Build("master", config)
tag, err := git.CurrentTag()
if err != nil {
panic(err)
}
previousTag, err := git.PreviousTag()
diff, err := git.Log(previousTag, tag)
if err != nil {
panic(err)
}
log.Println(diff)
fmt.Println("Building", tag, "...")
err = build.Build(tag, config)
fmt.Println(err)
}