forked from codeskyblue/gobuild
/
build_get.go
60 lines (57 loc) · 1.29 KB
/
build_get.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
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"github.com/qiniu/log"
"github.com/shxsun/go-sh"
"github.com/shxsun/goyaml"
"io/ioutil"
"path/filepath"
"strings"
)
import beeutils "github.com/astaxie/beego/utils"
// download src
func (b *Builder) get() (err error) {
log.Debug("start get src to:", b.srcDir)
exists := beeutils.FileExists(b.srcDir)
b.sh.Command("go", "version").Run()
if !exists {
err = b.sh.Command("go", "get", "-v", "-d", b.project).Run()
if err != nil {
return
}
}
b.sh.SetDir(b.srcDir)
if b.ref == "-" {
b.ref = "master"
}
// get code from remote
if err = b.sh.Command("git", "fetch", "origin").Run(); err != nil {
return
}
// change branch
if err = b.sh.Command("git", "checkout", "-q", b.ref).Run(); err != nil {
return
}
// update code
if err = b.sh.Command("git", "merge", "origin/"+b.ref).Run(); err != nil {
log.Warn("git merge error:", err)
//return
}
// get sha
out, err := sh.Command("git", "rev-parse", "HEAD", sh.Dir(b.srcDir)).Output()
if err != nil {
return
}
b.sha = strings.TrimSpace(string(out))
// parse .gobuild
b.rc = new(Assembly)
rcfile := "public/gobuildrc"
if b.sh.Test("f", ".gobuild") {
rcfile = filepath.Join(b.srcDir, ".gobuild")
}
data, err := ioutil.ReadFile(rcfile)
if err != nil {
return
}
err = goyaml.Unmarshal(data, b.rc)
return
}