diff --git a/.github/workflows/jenkins-x-pr.yaml b/.github/workflows/jenkins-x-pr.yaml index 3340638..7a20b5b 100644 --- a/.github/workflows/jenkins-x-pr.yaml +++ b/.github/workflows/jenkins-x-pr.yaml @@ -14,14 +14,14 @@ jobs: - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} name: build-make-linux - uses: docker://golang:1.17.9 + uses: docker://golang:1.18 with: args: -c "make linux" entrypoint: /bin/sh - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} name: build-make-test - uses: docker://golang:1.17.9 + uses: docker://golang:1.18 with: args: -c "make test" entrypoint: /bin/sh diff --git a/.github/workflows/jenkins-x-release.yaml b/.github/workflows/jenkins-x-release.yaml index 8db3f07..e3e2dc6 100644 --- a/.github/workflows/jenkins-x-release.yaml +++ b/.github/workflows/jenkins-x-release.yaml @@ -22,7 +22,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GIT_BOT_TOKEN }} VERSION: ${{ steps.prep.outputs.version }} name: release-binary - uses: docker://golang:1.17.9 + uses: docker://golang:1.18 with: args: -c "make release" entrypoint: bash diff --git a/cmd/docs/main.go b/cmd/docs/main.go index 03416e0..413b5e1 100644 --- a/cmd/docs/main.go +++ b/cmd/docs/main.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/cmd/docs/md_docs.go b/cmd/docs/md_docs.go index ec94bf3..1b09002 100644 --- a/cmd/docs/md_docs.go +++ b/cmd/docs/md_docs.go @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, diff --git a/go.mod b/go.mod index 2edf547..cc74ece 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/spf13/cobra v1.3.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.0 + golang.org/x/exp v0.0.0-20230108222341-4b8118a2686a helm.sh/helm/v3 v3.8.1 k8s.io/api v0.23.4 k8s.io/apimachinery v0.23.4 @@ -149,14 +150,13 @@ require ( go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.19.0 // indirect golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect - golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect + golang.org/x/net v0.1.0 // indirect golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect - golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect - golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect - golang.org/x/text v0.3.7 // indirect + golang.org/x/sys v0.1.0 // indirect + golang.org/x/term v0.1.0 // indirect + golang.org/x/text v0.4.0 // indirect golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect - golang.org/x/tools v0.1.12 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/api v0.70.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index 7a5007c..7b18f8d 100644 --- a/go.sum +++ b/go.sum @@ -1411,6 +1411,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20230108222341-4b8118a2686a h1:tlXy25amD5A7gOfbXdqCGN5k8ESEed/Ee1E5RcrYnqU= +golang.org/x/exp v0.0.0-20230108222341-4b8118a2686a/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -1502,8 +1504,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220107192237-5cfca573fb4d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= +golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1657,14 +1659,15 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc= -golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw= +golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1674,8 +1677,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1754,8 +1758,7 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff/go.mod h1:YD9qOF0M9xpSpdWTBbzEl5e/RnCefISl8E5Noe10jFM= -golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/promote/promote.go b/pkg/promote/promote.go index a7522ee..2b34e4e 100644 --- a/pkg/promote/promote.go +++ b/pkg/promote/promote.go @@ -11,6 +11,7 @@ import ( "time" "github.com/jenkins-x/jx-helpers/v3/pkg/requirements" + "golang.org/x/exp/slices" "github.com/jenkins-x/jx-helpers/v3/pkg/gitclient/cli" @@ -560,28 +561,21 @@ func (o *Options) PromoteAll(pred func(*jxcore.EnvironmentConfig) bool) error { // lets group Auto env promotions together into the same git URL var groups [][]*jxcore.EnvironmentConfig - var group []*jxcore.EnvironmentConfig for _, env := range promoteEnvs { - if len(group) == 0 { - group = append(group, env) - continue - } - - sourceURL := requirements.EnvironmentGitURL(o.DevEnvContext.Requirements, env.Key) - - // lets see if the env is the same - if o.NoGroupPullRequest || env.PromotionStrategy != v1.PromotionStrategyTypeAutomatic || sourceURL != group[0].GitURL { - // lets use a different group... - groups = append(groups, group) - group = []*jxcore.EnvironmentConfig{env} - } else { - group = append(group, env) + if !o.NoGroupPullRequest && env.PromotionStrategy == v1.PromotionStrategyTypeAutomatic { + // let's see if the env is has the same url as existing automatic group + i := slices.IndexFunc(groups, + func(group []*jxcore.EnvironmentConfig) bool { + return group[0].GitURL == env.GitURL && group[0].PromotionStrategy == v1.PromotionStrategyTypeAutomatic + }) + if i >= 0 { + groups[i] = append(groups[i], env) + continue + } } + groups = append(groups, []*jxcore.EnvironmentConfig{env}) } - if len(group) > 0 { - groups = append(groups, group) - } - for _, group = range groups { + for _, group := range groups { firstEnv := group[0] // lets clear the branch name so that we create a new branch for each PR... diff --git a/pkg/promote/promote_integration_test.go b/pkg/promote/promote_integration_test.go index 397cdfa..62949c2 100644 --- a/pkg/promote/promote_integration_test.go +++ b/pkg/promote/promote_integration_test.go @@ -441,7 +441,7 @@ func TestPromoteHelmfileAllAutomaticsInOneOrMorePRs(t *testing.T) { expectedPullRequestCount map[string]int }{ { - name: "separate-prs-for-urls", + name: "group-prs-for-urls", noGroupPullRequest: false, envSourceURL: "https://github.com/jx3-gitops-repositories/jx3-gke-vault", expectedPullRequestCount: map[string]int{ @@ -456,11 +456,20 @@ func TestPromoteHelmfileAllAutomaticsInOneOrMorePRs(t *testing.T) { targetFullName: 1, }, }, + { + name: "separate-prs-for-urls", + noGroupPullRequest: true, + envSourceURL: "https://github.com/jx3-gitops-repositories/jx3-gke-vault", + expectedPullRequestCount: map[string]int{ + targetFullName: 1, + "jx3-gitops-repositories/jx3-gke-vault": 2, + }, + }, { name: "separate-prs", noGroupPullRequest: true, expectedPullRequestCount: map[string]int{ - targetFullName: 2, + targetFullName: 3, }, }, } @@ -520,6 +529,12 @@ func TestPromoteHelmfileAllAutomaticsInOneOrMorePRs(t *testing.T) { PromotionStrategy: v1.PromotionStrategyTypeNever, GitURL: devGitURL, }, + { + Key: "anotherenv", + Namespace: "jx-production2", + PromotionStrategy: v1.PromotionStrategyTypeAutomatic, + GitURL: tc.envSourceURL, + }, { Key: "staging", Namespace: "jx-staging",