diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-05-15 21:02:45 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-05-15 21:39:11 +0300 |
commit | c3017b04fbcb05df96067b50e729cd332991dd4d (patch) | |
tree | 1177c14b0a07e044bc7683d91061c977cc3a6c8d | |
parent | e31495e181c1a959aabb44fb6883650451f3687c (diff) |
Make the builder runnable on Travis
-rw-r--r-- | testmodBuilder/build/main.go | 33 | ||||
-rw-r--r-- | testmodBuilder/mods/mods.go | 25 |
2 files changed, 35 insertions, 23 deletions
diff --git a/testmodBuilder/build/main.go b/testmodBuilder/build/main.go index e28bfdd..2c0960a 100644 --- a/testmodBuilder/build/main.go +++ b/testmodBuilder/build/main.go @@ -4,11 +4,13 @@ import ( "bytes" "fmt" "io" + "io/ioutil" "log" "os" "os/exec" "path" "path/filepath" + "runtime" "strings" "github.com/gohugoio/hugo/modules" @@ -19,30 +21,36 @@ import ( ) const ( - // TODO(bep) - basePath = "github.com/gohugoio/hugoTestModules1" - localDir = "/Users/bep/dev/go/gohugoio/hugoTestModules1" // Increment the minor version. versionTemplate = "v1.%d.0" + testGitRepoBase = "hugoTestModules1" ) func main() { + // Run this on darwin, linux and windows. + goos := runtime.GOOS + gitRepo := testGitRepoBase + "_" + goos + + dir, err := ioutil.TempDir("", "hugotestmods") + if err != nil { + log.Fatal(err) + } + defer os.RemoveAll(dir) - dir := localDir fs := afero.NewOsFs() m := mods.CreateModules() - environ := osutil.Environ(os.Environ()) - environ.Set("PWD", dir) - b := &mb{ fs: fs, mods: m.Collect(), - environ: environ, - dir: dir, + environ: osutil.Environ(os.Environ()), } + b.cdir(dir) + + must(b.run("git", "clone", fmt.Sprintf("git@github.com:gohugoio/%s.git", gitRepo))) + b.cdir(filepath.Join(dir, gitRepo)) must(b.all()) } @@ -55,7 +63,12 @@ type mb struct { fs afero.Fs mods []*mods.Md dir string - environ []string + environ osutil.Environ +} + +func (b *mb) cdir(dir string) { + b.environ.Set("PWD", dir) + b.dir = dir } func (b *mb) createFiles() error { diff --git a/testmodBuilder/mods/mods.go b/testmodBuilder/mods/mods.go index 667a047..0016b8d 100644 --- a/testmodBuilder/mods/mods.go +++ b/testmodBuilder/mods/mods.go @@ -3,13 +3,12 @@ package mods import ( "fmt" "path" + "runtime" "strings" ) const ( - // TODO(bep) - basePath = "github.com/gohugoio/hugoTestModules1" - localDir = "/Users/bep/dev/go/gohugoio/hugoTestModules1" + basePath = "github.com/gohugoio/hugoTestModules1_" + runtime.GOOS // Increment the minor version. versionTemplate = "v1.%d.0" @@ -19,12 +18,12 @@ type Md struct { name string Vendor bool - Children Mds + Children Mds } func (m *Md) String() string { s := m.Path() - for _, mm := range m. Children { + for _, mm := range m.Children { s += "\n" + mm.String() } @@ -33,7 +32,7 @@ func (m *Md) String() string { func (m *Md) Collect() []*Md { mds := []*Md{m} - for _, mm := range m. Children { + for _, mm := range m.Children { mds = append(mds, mm.Collect()...) } @@ -43,7 +42,7 @@ func (m *Md) Collect() []*Md { func (m *Md) Paths() []string { var p []string - for _, mm := range m. Children { + for _, mm := range m.Children { p = append(p, mm.Path()) } @@ -75,7 +74,7 @@ func (m *Md) init(idx int, parent *Md) { m.name = fmt.Sprintf("%s%d", parentName, idx+1) m.Vendor = idx%2 == 0 - for i, mm := range m. Children { + for i, mm := range m.Children { mm.init(i, m) } @@ -83,12 +82,12 @@ func (m *Md) init(idx int, parent *Md) { func createModule() *Md { return &Md{ - Children: []*Md{ - &Md{ Children: []*Md{ + Children: []*Md{ + &Md{Children: []*Md{ &Md{}, &Md{}, }}, - &Md{ Children: []*Md{ + &Md{Children: []*Md{ &Md{}, &Md{}, }}, @@ -98,8 +97,8 @@ func createModule() *Md { func createSmallModule() *Md { return &Md{ - Children: []*Md{ - &Md{ Children: []*Md{ + Children: []*Md{ + &Md{Children: []*Md{ &Md{}, }}, }, |