Skip to content

Commit

Permalink
Saving UUID to find the correct build folder for a repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Jul 15, 2018
1 parent 775623b commit bc40872
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions gaia.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Pipeline struct {
SHA256Sum []byte `json:"sha256sum,omitempty"`
Jobs []Job `json:"jobs,omitempty"`
Created time.Time `json:"created,omitempty"`
UUID string `json:"uuid,omitempty"`
}

// GitRepo represents a single git repository
Expand Down
1 change: 1 addition & 0 deletions pipeline/build_golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (b *BuildPipelineGolang) PrepareEnvironment(p *gaia.CreatePipeline) error {

// Set new generated path in pipeline obj for later usage
p.Pipeline.Repo.LocalDest = cloneFolder
p.Pipeline.UUID = uuid.String()
return nil
}

Expand Down
16 changes: 9 additions & 7 deletions pipeline/git.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pipeline

import (
"path/filepath"
"strings"
"sync"

Expand Down Expand Up @@ -113,39 +114,40 @@ func updateAllCurrentPipelines() {
var allPipelines []gaia.Pipeline
var wg sync.WaitGroup
sem := make(chan int, 4)

for pipeline := range GlobalActivePipelines.Iter() {
allPipelines = append(allPipelines, pipeline)
}

goPath := filepath.Join(gaia.Cfg.HomePath, tmpFolder, golangFolder)
for _, p := range allPipelines {
wg.Add(1)
go func(pipe gaia.Pipeline) {
defer wg.Done()
sem <- 1
r, err := git.PlainOpen(pipe.Repo.LocalDest)
cloneFolder := filepath.Join(goPath, srcFolder, pipe.UUID)
r, err := git.PlainOpen(cloneFolder)
if err != nil {
// ignore for now
return
}
beforPull, _ := r.Head()
gaia.Cfg.Logger.Debug("selected branch : ", pipe.Repo.SelectedBranch)
tree, _ := r.Worktree()
err = tree.Pull(&git.PullOptions{
RemoteName: "origin",
})
if err != nil {
gaia.Cfg.Logger.Error("error2 : ", err.Error())
err = nil
gaia.Cfg.Logger.Error("error while doing a pull request : ", err.Error())
<-sem
return
}
afterPull, _ := r.Head()
gaia.Cfg.Logger.Debug("no need to update pipeline: ", pipe.Name)
// if there are no changes...
if beforPull.Hash() == afterPull.Hash() {
<-sem
return
}

gaia.Cfg.Logger.Debug("updating pipeline: ", pipe.Name)
// otherwise build the pipeline
b := newBuildPipeline(pipe.Type)
createPipeline := &gaia.CreatePipeline{}
createPipeline.Pipeline = pipe
Expand Down

0 comments on commit bc40872

Please sign in to comment.