Skip to content

Commit bc40872

Browse files
committed
Saving UUID to find the correct build folder for a repo.
1 parent 775623b commit bc40872

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

gaia.go

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type Pipeline struct {
8888
SHA256Sum []byte `json:"sha256sum,omitempty"`
8989
Jobs []Job `json:"jobs,omitempty"`
9090
Created time.Time `json:"created,omitempty"`
91+
UUID string `json:"uuid,omitempty"`
9192
}
9293

9394
// GitRepo represents a single git repository

pipeline/build_golang.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (b *BuildPipelineGolang) PrepareEnvironment(p *gaia.CreatePipeline) error {
4040

4141
// Set new generated path in pipeline obj for later usage
4242
p.Pipeline.Repo.LocalDest = cloneFolder
43+
p.Pipeline.UUID = uuid.String()
4344
return nil
4445
}
4546

pipeline/git.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pipeline
22

33
import (
4+
"path/filepath"
45
"strings"
56
"sync"
67

@@ -113,39 +114,40 @@ func updateAllCurrentPipelines() {
113114
var allPipelines []gaia.Pipeline
114115
var wg sync.WaitGroup
115116
sem := make(chan int, 4)
116-
117117
for pipeline := range GlobalActivePipelines.Iter() {
118118
allPipelines = append(allPipelines, pipeline)
119119
}
120-
120+
goPath := filepath.Join(gaia.Cfg.HomePath, tmpFolder, golangFolder)
121121
for _, p := range allPipelines {
122122
wg.Add(1)
123123
go func(pipe gaia.Pipeline) {
124124
defer wg.Done()
125125
sem <- 1
126-
r, err := git.PlainOpen(pipe.Repo.LocalDest)
126+
cloneFolder := filepath.Join(goPath, srcFolder, pipe.UUID)
127+
r, err := git.PlainOpen(cloneFolder)
127128
if err != nil {
128129
// ignore for now
129130
return
130131
}
131132
beforPull, _ := r.Head()
133+
gaia.Cfg.Logger.Debug("selected branch : ", pipe.Repo.SelectedBranch)
132134
tree, _ := r.Worktree()
133135
err = tree.Pull(&git.PullOptions{
134136
RemoteName: "origin",
135137
})
136138
if err != nil {
137-
gaia.Cfg.Logger.Error("error2 : ", err.Error())
138-
err = nil
139+
gaia.Cfg.Logger.Error("error while doing a pull request : ", err.Error())
140+
<-sem
141+
return
139142
}
140143
afterPull, _ := r.Head()
141144
gaia.Cfg.Logger.Debug("no need to update pipeline: ", pipe.Name)
142-
// if there are no changes...
143145
if beforPull.Hash() == afterPull.Hash() {
144146
<-sem
145147
return
146148
}
149+
147150
gaia.Cfg.Logger.Debug("updating pipeline: ", pipe.Name)
148-
// otherwise build the pipeline
149151
b := newBuildPipeline(pipe.Type)
150152
createPipeline := &gaia.CreatePipeline{}
151153
createPipeline.Pipeline = pipe

0 commit comments

Comments
 (0)