-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
72 lines (61 loc) · 1.57 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"io/ioutil"
"log"
"os"
"strings"
"github.com/wings-software/autogen-go/builder"
"github.com/wings-software/autogen-go/chroot"
"github.com/wings-software/autogen-go/cloner"
)
func main() {
var path string
// extract the repository path
if len(os.Args) > 1 {
path = os.Args[1]
}
// if the path is a repository url,
// clone the rempository into a temporary
// directory, and then delete
if isRemote(path) {
temp, err := ioutil.TempDir("", "")
if err != nil {
log.Fatalln(err)
}
defer os.RemoveAll(temp)
params := cloner.Params{
Dir: temp,
Repo: path,
Username: "", // not yet implemented
Password: "", // not yet implemented
Privatekey: "", // not yet implemented
}
cloner := cloner.New(1, ioutil.Discard) // 1 depth, discard git clone logs
cloner.Clone(context.Background(), params)
// change the path to the temp directory
path = temp
}
// create a chroot virtual filesystem that we
// pass to the builder for isolation purposes.
chroot, err := chroot.New(path)
if err != nil {
log.Fatalln(err)
}
// builds the pipeline configuration based on
// the contents of the virtual filesystem.
builder := builder.New("harness")
out, err := builder.Build(chroot)
if err != nil {
log.Fatalln(err)
}
// output to console
println(string(out))
}
// returns true if the string is a remote git repository.
func isRemote(s string) bool {
return strings.HasPrefix(s, "git://") ||
strings.HasPrefix(s, "http://") ||
strings.HasPrefix(s, "https://") ||
strings.HasPrefix(s, "git@")
}