8
8
"path/filepath"
9
9
"strconv"
10
10
"strings"
11
+ "sync"
11
12
"time"
12
13
13
14
"github.com/jenkins-x/jx-helpers/v3/pkg/requirements"
@@ -575,6 +576,8 @@ func (o *Options) PromoteAll(pred func(*jxcore.EnvironmentConfig) bool) error {
575
576
}
576
577
groups = append (groups , []* jxcore.EnvironmentConfig {env })
577
578
}
579
+ var errorChannel = make (chan error , len (groups ))
580
+ var wg sync.WaitGroup
578
581
for _ , group := range groups {
579
582
firstEnv := group [0 ]
580
583
@@ -585,14 +588,24 @@ func (o *Options) PromoteAll(pred func(*jxcore.EnvironmentConfig) bool) error {
585
588
return err
586
589
}
587
590
o .ReleaseInfo = releaseInfo
588
- if ! o . NoPoll {
589
- err = o . WaitForPromotion ( firstEnv , releaseInfo )
590
- if err != nil {
591
- return err
592
- }
591
+ // TODO: Add test
592
+ if ! o . NoPoll && group [ 0 ]. PromotionStrategy == v1 . PromotionStrategyTypeAutomatic {
593
+ wg . Add ( 1 )
594
+ // Wait for multiple PRs in parallel
595
+ go o . WaitForPromotion ( firstEnv , releaseInfo , errorChannel , & wg )
593
596
}
594
597
}
595
- return nil
598
+ wg .Wait ()
599
+ close (errorChannel )
600
+ var err error
601
+ for err2 := range errorChannel {
602
+ if err == nil {
603
+ err = err2
604
+ } else {
605
+ err = fmt .Errorf ("%w; %v" , err , err2 )
606
+ }
607
+ }
608
+ return err
596
609
}
597
610
598
611
// EnvironmentNamespace returns the namespace for the environment
@@ -833,14 +846,15 @@ func (o *Options) GetTargetNamespace(ns, env string) (string, *jxcore.Environmen
833
846
return targetNS , envResource , nil
834
847
}
835
848
836
- func (o * Options ) WaitForPromotion (env * jxcore.EnvironmentConfig , releaseInfo * ReleaseInfo ) error {
849
+ func (o * Options ) WaitForPromotion (env * jxcore.EnvironmentConfig , releaseInfo * ReleaseInfo , errorChannel chan <- error , wg * sync.WaitGroup ) {
850
+ defer wg .Done ()
837
851
if o .TimeoutDuration == nil {
838
852
log .Logger ().Infof ("No --%s option specified on the 'jx promote' command so not waiting for the promotion to succeed" , optionTimeout )
839
- return nil
853
+ return
840
854
}
841
855
if o .PullRequestPollDuration == nil {
842
856
log .Logger ().Infof ("No --%s option specified on the 'jx promote' command so not waiting for the promotion to succeed" , optionPullRequestPollTime )
843
- return nil
857
+ return
844
858
}
845
859
duration := * o .TimeoutDuration
846
860
end := time .Now ().Add (duration )
@@ -856,12 +870,11 @@ func (o *Options) WaitForPromotion(env *jxcore.EnvironmentConfig, releaseInfo *R
856
870
// TODO based on if the PR completed or not fail the PR or the Promote?
857
871
err2 := promoteKey .OnPromotePullRequest (kubeClient , jxClient , o .Namespace , activities .FailedPromotionPullRequest )
858
872
if err2 != nil {
859
- return err2
873
+ errorChannel <- err2
860
874
}
861
- return err
875
+ errorChannel <- err
862
876
}
863
877
}
864
- return nil
865
878
}
866
879
867
880
// TODO This could do with a refactor and some tests...
@@ -985,7 +998,7 @@ func (o *Options) waitForGitOpsPullRequest(env *jxcore.EnvironmentConfig, releas
985
998
}
986
999
}
987
1000
}
988
- if ! pr .Mergeable {
1001
+ if pr .MergeableState == scm . MergeableStateConflicting {
989
1002
log .Logger ().Info ("Rebasing PullRequest due to conflict" )
990
1003
991
1004
err = o .PromoteViaPullRequest ([]* jxcore.EnvironmentConfig {env }, releaseInfo , false )
0 commit comments