-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
47 lines (37 loc) · 1.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"log"
"os"
"gopkg.in/src-d/go-git.v4/plumbing"
gogitver "github.com/syncromatics/gogitver/pkg/git"
"github.com/pkg/errors"
"gopkg.in/src-d/go-billy.v4/memfs"
git "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/storage/memory"
)
func main() {
repo, ok := os.LookupEnv("GITHUB_REPOSITORY")
if !ok {
log.Fatal("did not find GITHUB_REPOSITORY env variable")
}
ref, ok := os.LookupEnv("GITHUB_REF")
if !ok {
log.Fatal("did not find GITHUB_REF env variable")
}
remote := fmt.Sprintf("https://github.com/%s", repo)
fs := memfs.New()
storage := memory.NewStorage()
r, err := git.Clone(storage, fs, &git.CloneOptions{
URL: remote,
ReferenceName: plumbing.ReferenceName(ref),
})
if err != nil {
log.Fatal(errors.Wrap(err, "failed cloning git"))
}
version, err := gogitver.GetCurrentVersion(r, gogitver.GetDefaultSettings(), &gogitver.BranchSettings{}, false)
if err != nil {
log.Fatal(errors.Wrap(err, "failed getting current version"))
}
fmt.Printf("::set-output name=version::v%s\n", version)
}