Skip to content

Commit

Permalink
fix: 🐛 git pull err that was preventing pulling on every apply
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskaransarkaria committed Oct 22, 2024
1 parent 355062b commit c2865d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 9 additions & 5 deletions pkg/environment/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ func (a *Apply) ApplyBatch() error {
func (a *Apply) applyNamespaceDirs(chunkFolder []string) error {
erroredNs := []string{}

err := util.GetLatestGitPull()
if err != nil {
return err
}

done := make(chan bool)
defer close(done)

Expand Down Expand Up @@ -232,6 +227,15 @@ func (a *Apply) runApply(done <-chan bool, dirStream <-chan string) <-chan strin
ns := strings.Split(dir, "/")
namespace := ns[2]

pullErr := util.GetLatestGitPull()
if pullErr != nil {
if strings.Contains(pullErr.Error(), "index.lock") {
fmt.Printf("ignoring git lock error during parallel run\n")
} else {
return pullErr.Error()
}
}

err := a.applyNamespace(namespace)
if err != nil {
return "Error in namespace: " + namespace + "\n" + err.Error()
Expand Down
8 changes: 3 additions & 5 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,20 @@ func GetLatestGitPull() error {
fmt.Println("Executing git reset")
resetErr := reset.Run()
if resetErr != nil {
fmt.Println(fmt.Sprint(resetErr) + ": " + stderr.String())
return resetErr
return errors.New(resetErr.Error() + ": " + stderr.String())
}

fmt.Println("Executing git pull")
err := pull.Run()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return err
return errors.New(fmt.Sprint(err) + ": " + stderr.String())
}

return nil
}

// Redacted reads bytes of data for any sensitive strings and print REDACTED
// This functiion is used to prevent slack webhooks URLS from being output in pipeline logs
// This function is used to prevent slack webhooks URLS from being output in pipeline logs
func Redacted(w io.Writer, output string, redact bool) {
re := regexp2.MustCompile(`^.*https://hooks\.slack\.com.*$`, 0)
scanner := bufio.NewScanner(strings.NewReader(output))
Expand Down

0 comments on commit c2865d7

Please sign in to comment.