This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsupport.go
173 lines (153 loc) · 3.55 KB
/
support.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package repoman
import (
"fmt"
"log"
"os"
"path"
"strings"
"github.com/magefile/mage/sh"
)
func mkGroupDirs() error {
for group := range config.Groups {
gpath := groupNameToPath(group)
if _, err := os.Stat(gpath); os.IsNotExist(err) {
fmt.Printf("Creating group: %v\n", gpath)
if err = os.MkdirAll(gpath, os.ModePerm); err != nil {
return err
}
}
}
return nil
}
func groupNameToPath(group string) string {
p := strings.Split(group, ".")
return path.Join(p...)
}
func cloneGroupRepos() error {
for group, repos := range config.Groups {
for _, repo := range repos {
if err := cloneRepo(group, repo); err != nil {
return err
}
}
}
return nil
}
func cloneProjectRepos() error {
for _, repo := range config.Projects {
if err := cloneRepo(".", repo); err != nil {
return err
}
}
return nil
}
func pullGroupRepos() error {
for group, repos := range config.Groups {
for _, repo := range repos {
if err := pullRepo(group, repo); err != nil {
return err
}
}
}
return nil
}
func pullProjectRepos() error {
for _, repo := range config.Projects {
if err := pullRepo(".", repo); err != nil {
return err
}
}
return nil
}
func cloneRepo(group string, r *Repo) error {
if r.Go {
// Go Repos require special treatment to ensure they're cloned into the GOPATH
p := r.GoOrgPath()
if _, err := os.Stat(p); os.IsNotExist(err) {
log.Printf("Creating Go Org Path: %v\n", p)
if err = os.Mkdir(p, os.ModePerm); err != nil {
return err
}
}
if _, err := os.Stat(r.GoProjectPath()); os.IsNotExist(err) {
log.Printf("Cloning Go Repo: %v\n", r.GitRepo())
err = sh.Run("git", "-C", r.GoOrgPath(), "clone", r.GitRepo())
if err != nil {
return err
}
}
gpath := groupNameToPath(group)
p = path.Join(gpath, r.Name)
if _, err := os.Stat(p); os.IsNotExist(err) {
log.Printf("Symlinking Go Repo: %v\n", p)
if err = os.Symlink(r.GoProjectPath(), p); err != nil {
return err
}
}
} else {
// Normal repos are much easier!
gpath := groupNameToPath(group)
p := path.Join(gpath, r.Name)
if _, err := os.Stat(p); os.IsNotExist(err) {
log.Printf("Cloning Repo %v into %v\n", r.GitRepo(), p)
err := sh.Run("git", "-C", gpath, "clone", r.GitRepo(), r.Name)
if err != nil {
return err
}
}
}
return nil
}
func pullRepo(group string, r *Repo) error {
gpath := groupNameToPath(group)
p := path.Join(gpath, r.Name)
if _, err := os.Stat(p); err != nil {
return err
}
log.Printf("Pulling Repo: %v\n", p)
sh.Run("git", "-C", p, "pull")
return nil
}
func goGetProjectRepos() error {
for _, repo := range config.Projects {
if repo.Go {
if err := goGetRepo(".", repo); err != nil {
return err
}
}
}
return nil
}
func goGetGroupRepos() error {
for group, repos := range config.Groups {
gpath := groupNameToPath(group)
for _, repo := range repos {
if repo.Go {
if err := goGetRepo(gpath, repo); err != nil {
return err
}
}
}
}
return nil
}
func goGetRepo(group string, r *Repo) error {
gpath := groupNameToPath(group)
p := path.Join(gpath, r.Name)
if _, err := os.Stat(p); err != nil {
return err
}
// Go doesn't support setting the Working Dir from the command line
os.Chdir(p)
defer os.Chdir(config.pwd)
var err error
if _, err = os.Stat("Gopkg.toml"); err == nil {
os.Chdir(r.GoProjectPath()) // Need to be in project base path
log.Printf("Go 'dep ensure' in Repo: %v\n", p)
err = sh.Run("dep", "ensure", "-v", "-vendor-only")
} else {
log.Printf("Go Get in Repo: %v\n", p)
err = sh.Run("go", "get", "./...")
}
return err
}