Skip to content

Commit 1f1b584

Browse files
authored
[plugin planpreview] update actions-plan-preview for pipedv1 (#6149)
* impl for pipedv1 Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * add test: makeTitleText Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * update tests Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * update pipectl version Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * go mod tidy Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> * fix lint Signed-off-by: t-kikuc <tkikuchi07f@gmail.com> --------- Signed-off-by: t-kikuc <tkikuchi07f@gmail.com>
1 parent 802e10c commit 1f1b584

File tree

9 files changed

+450
-55
lines changed

9 files changed

+450
-55
lines changed

tool/actions-plan-preview/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RUN go mod download
55
COPY . ./
66
RUN go build -o /plan-preview .
77

8-
FROM ghcr.io/pipe-cd/pipectl:v0.43.1
8+
FROM ghcr.io/pipe-cd/pipectl:v0.53.0
99
COPY --from=builder /plan-preview /
1010
ENV PATH=$PATH:/app/cmd/pipectl
1111
RUN chmod +x /plan-preview

tool/actions-plan-preview/go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ go 1.24.1
44

55
require (
66
github.com/google/go-github/v36 v36.0.0
7+
github.com/pipe-cd/pipecd v0.53.0
78
github.com/shurcooL/githubv4 v0.0.0-20220115235240-a14260e6f8a2
8-
github.com/stretchr/testify v1.7.0
9+
github.com/stretchr/testify v1.10.0
910
golang.org/x/oauth2 v0.27.0
1011
)
1112

1213
require (
13-
github.com/davecgh/go-spew v1.1.0 // indirect
14+
github.com/coreos/go-oidc/v3 v3.11.0 // indirect
15+
github.com/davecgh/go-spew v1.1.1 // indirect
16+
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
17+
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
1418
github.com/google/go-querystring v1.0.0 // indirect
1519
github.com/pmezard/go-difflib v1.0.0 // indirect
1620
github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a // indirect
1721
golang.org/x/crypto v0.36.0 // indirect
1822
golang.org/x/net v0.38.0 // indirect
23+
google.golang.org/protobuf v1.34.2 // indirect
1924
gopkg.in/yaml.v3 v3.0.1 // indirect
2025
)

tool/actions-plan-preview/go.sum

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1+
github.com/coreos/go-oidc/v3 v3.11.0 h1:Ia3MxdwpSw702YW0xgfmP1GVCMA9aEFWu12XUZ3/OtI=
2+
github.com/coreos/go-oidc/v3 v3.11.0/go.mod h1:gE3LgjOgFoHi9a4ce4/tJczr0Ai2/BoDhf0r5lltWI0=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A=
6+
github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew=
7+
github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE=
8+
github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA=
39
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
410
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5-
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
6-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
11+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
12+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
713
github.com/google/go-github/v36 v36.0.0 h1:ndCzM616/oijwufI7nBRa+5eZHLldT+4yIB68ib5ogs=
814
github.com/google/go-github/v36 v36.0.0/go.mod h1:LFlKC047IOqiglRGNqNb9s/iAPTnnjtlshm+bxp+kwk=
915
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
1016
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
17+
github.com/pipe-cd/pipecd v0.53.0 h1:q6AiDhPFsS0enAehvn2UTVJMKfdnLDPB1BNo6Pr+FgQ=
18+
github.com/pipe-cd/pipecd v0.53.0/go.mod h1:BI0uxrpeuxcjFykL5+tnLc5DRd8v24Hm/it7fBOth6Y=
1119
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1220
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1321
github.com/shurcooL/githubv4 v0.0.0-20220115235240-a14260e6f8a2 h1:82EIpiGB79OIPgSGa63Oj4Ipf+YAX1c6A9qjmEYoRXc=
1422
github.com/shurcooL/githubv4 v0.0.0-20220115235240-a14260e6f8a2/go.mod h1:hAF0iLZy4td2EX+/8Tw+4nodhlMrwN3HupfaXj3zkGo=
1523
github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a h1:KikTa6HtAK8cS1qjvUvvq4QO21QnwC+EfvB+OAuZ/ZU=
1624
github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a/go.mod h1:AuYgA5Kyo4c7HfUmvRGs/6rGlMMV/6B1bVnB9JxJEEg=
17-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
18-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
19-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
25+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
26+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2027
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
2128
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
2229
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
@@ -30,8 +37,9 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
3037
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
3138
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
3239
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
40+
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
41+
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
3342
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
3443
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
35-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3644
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
3745
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

tool/actions-plan-preview/planpreview.go

Lines changed: 116 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"unicode/utf8"
2929

3030
"github.com/shurcooL/githubv4"
31+
32+
"github.com/pipe-cd/pipecd/pkg/model"
3133
)
3234

3335
type PlanPreviewResult struct {
@@ -47,9 +49,13 @@ func (r *PlanPreviewResult) NoChange() bool {
4749
type ApplicationResult struct {
4850
ApplicationInfo
4951
SyncStrategy string // QUICK_SYNC, PIPELINE
50-
PlanSummary string
51-
PlanDetails string
52-
NoChange bool
52+
// Deprecated: Use PluginPlanResults in pipedv1
53+
PlanSummary string
54+
// Deprecated: Use PluginPlanResults in pipedv1
55+
PlanDetails string
56+
NoChange bool
57+
58+
PluginPlanResults []*model.PluginPlanPreviewResult
5359
}
5460

5561
type FailurePiped struct {
@@ -59,8 +65,11 @@ type FailurePiped struct {
5965

6066
type FailureApplication struct {
6167
ApplicationInfo
62-
Reason string
68+
Reason string
69+
// Deprecated: Use PluginPlanResults in pipedv1
6370
PlanDetails string
71+
72+
PluginPlanResults []*model.PluginPlanPreviewResult
6473
}
6574

6675
type PipedInfo struct {
@@ -69,12 +78,16 @@ type PipedInfo struct {
6978
}
7079

7180
type ApplicationInfo struct {
72-
ApplicationID string
73-
ApplicationName string
74-
ApplicationURL string
75-
Env string
81+
ApplicationID string
82+
ApplicationName string
83+
ApplicationURL string
84+
Env string
85+
// Deprecated: Use PluginNames in pipedv1
7686
ApplicationKind string // KUBERNETES, TERRAFORM, CLOUDRUN, LAMBDA, ECS
7787
ApplicationDirectory string
88+
89+
PlannedPluginNames string
90+
AllPluginNames string
7891
}
7992

8093
func retrievePlanPreview(
@@ -133,12 +146,14 @@ const (
133146
failureBadgeURL = `[![PLAN_PREVIEW](https://img.shields.io/static/v1?label=PipeCD&message=Plan_Preview&color=orange&style=flat)](https://pipecd.dev/docs/user-guide/plan-preview/)`
134147
actionBadgeURLFormat = "[![ACTIONS](https://img.shields.io/static/v1?label=PipeCD&message=Action_Log&style=flat)](%s)"
135148

136-
noChangeTitleFormat = "Ran plan-preview against head commit %s of this pull request. PipeCD detected `0` updated application. It means no deployment will be triggered once this pull request got merged.\n"
137-
hasChangeTitleFormat = "Ran plan-preview against head commit %s of this pull request. PipeCD detected `%d` updated applications and here are their plan results. Once this pull request got merged their deployments will be triggered to run as these estimations.\n"
138-
detailsFormat = "<details>\n<summary>Details (Click me)</summary>\n<p>\n\n``` %s\n%s\n```\n</p>\n</details>\n\n"
139-
detailsOmittedMessage = "The details are too long to display. Please check the actions log to see full details."
140-
appInfoWithEnvFormat = "app: [%s](%s), env: %s, kind: %s"
141-
appInfoWithoutEnvFormat = "app: [%s](%s), kind: %s"
149+
noChangeTitleFormat = "Ran plan-preview against head commit %s of this pull request. PipeCD detected `0` updated application. It means no deployment will be triggered once this pull request got merged.\n"
150+
hasChangeTitleFormat = "Ran plan-preview against head commit %s of this pull request. PipeCD detected `%d` updated applications and here are their plan results. Once this pull request got merged their deployments will be triggered to run as these estimations.\n"
151+
detailsFormat = "<details>\n<summary>Details (Click me)</summary>\n<p>\n\n``` %s\n%s\n```\n</p>\n</details>\n\n"
152+
detailsOmittedMessage = "The details are too long to display. Please check the actions log to see full details."
153+
appInfoWithEnvFormat = "app: [%s](%s), env: %s, kind: %s"
154+
appInfoWithoutEnvFormat = "app: [%s](%s), kind: %s"
155+
appInfoWithEnvFormatV1 = "app: [%s](%s), env: %s, planned plugin(s): %s"
156+
appInfoWithoutEnvFormatV1 = "app: [%s](%s), planned plugin(s): %s"
142157

143158
ghMessageLenLimit = 65536
144159

@@ -196,30 +211,67 @@ func makeCommentBody(event *githubEvent, r *PlanPreviewResult, title string) str
196211
for _, app := range changedApps {
197212
fmt.Fprintf(&b, "### %s\n", makeTitleText(&app.ApplicationInfo))
198213
fmt.Fprintf(&b, "Sync strategy: %s\n", app.SyncStrategy)
199-
fmt.Fprintf(&b, "Summary: %s\n\n", app.PlanSummary)
200-
201-
var (
202-
lang = "diff"
203-
details = app.PlanDetails
204-
)
205-
if app.ApplicationKind == "TERRAFORM" {
206-
lang = "hcl"
207-
if shortened, err := generateTerraformShortPlanDetails(details); err == nil {
208-
details = shortened
214+
215+
if app.AllPluginNames == "" {
216+
// pipedv0
217+
fmt.Fprintf(&b, "Summary: %s\n\n", app.PlanSummary)
218+
var (
219+
lang = "diff"
220+
details = app.PlanDetails
221+
)
222+
if app.ApplicationKind == "TERRAFORM" {
223+
lang = "hcl"
224+
if shortened, err := generateTerraformShortPlanDetails(details); err == nil {
225+
details = shortened
226+
}
209227
}
210-
}
211228

212-
l := utf8.RuneCountInString(details)
213-
if detailLen+l > detailsLenLimit {
214-
fmt.Fprintf(&b, detailsFormat, lang, detailsOmittedMessage)
215-
detailLen += utf8.RuneCountInString(detailsOmittedMessage)
216-
continue
217-
}
229+
l := utf8.RuneCountInString(details)
230+
if detailLen+l > detailsLenLimit {
231+
fmt.Fprintf(&b, detailsFormat, lang, detailsOmittedMessage)
232+
detailLen += utf8.RuneCountInString(detailsOmittedMessage)
233+
continue
234+
}
218235

219-
if l > 0 {
220-
detailLen += l
221-
fmt.Fprintf(&b, detailsFormat, lang, details)
236+
if l > 0 {
237+
detailLen += l
238+
fmt.Fprintf(&b, detailsFormat, lang, details)
239+
}
240+
} else {
241+
// pipedv1
242+
fmt.Fprintf(&b, " Plugin(s): %s\n", app.AllPluginNames)
243+
fmt.Fprintf(&b, " Summary:\n")
244+
for _, ppr := range app.PluginPlanResults {
245+
fmt.Fprintf(&b, " - %s(%s): %s\n", ppr.PluginName, ppr.DeployTarget, ppr.PlanSummary)
246+
}
247+
fmt.Fprint(&b, " Details:\n")
248+
for _, ppr := range app.PluginPlanResults {
249+
fmt.Fprintf(&b, " - %s(%s):\n", ppr.PluginName, ppr.DeployTarget)
250+
251+
details := string(ppr.PlanDetails)
252+
switch ppr.DiffLanguage {
253+
case "":
254+
ppr.DiffLanguage = "diff" // Use diff by default
255+
case "hcl":
256+
if shortened, err := generateTerraformShortPlanDetails(details); err == nil {
257+
details = shortened
258+
}
259+
}
260+
261+
l := utf8.RuneCountInString(details)
262+
if detailLen+l > detailsLenLimit {
263+
fmt.Fprintf(&b, detailsFormat, ppr.DiffLanguage, detailsOmittedMessage)
264+
detailLen += utf8.RuneCountInString(detailsOmittedMessage)
265+
continue
266+
}
267+
268+
if l > 0 {
269+
detailLen += l
270+
fmt.Fprintf(&b, detailsFormat, ppr.DiffLanguage, details)
271+
}
272+
}
222273
}
274+
223275
}
224276

225277
if len(pipelineApps)+len(quickSyncApps) > 0 {
@@ -253,13 +305,24 @@ func makeCommentBody(event *githubEvent, r *PlanPreviewResult, title string) str
253305
fmt.Fprintf(&b, "\n### %s\n", makeTitleText(&app.ApplicationInfo))
254306
fmt.Fprintf(&b, "Reason: %s\n\n", app.Reason)
255307

256-
var lang = "diff"
257-
if app.ApplicationKind == "TERRAFORM" {
258-
lang = "hcl"
259-
}
260-
261-
if len(app.PlanDetails) > 0 {
262-
fmt.Fprintf(&b, detailsFormat, lang, app.PlanDetails)
308+
if app.AllPluginNames == "" {
309+
// pipedv0
310+
var lang = "diff"
311+
if app.ApplicationKind == "TERRAFORM" {
312+
lang = "hcl"
313+
}
314+
315+
if len(app.PlanDetails) > 0 {
316+
fmt.Fprintf(&b, detailsFormat, lang, app.PlanDetails)
317+
}
318+
} else {
319+
// pipedv1
320+
for _, ppr := range app.PluginPlanResults {
321+
fmt.Fprintf(&b, " - %s(%s):\n", ppr.PluginName, ppr.DeployTarget)
322+
if len(ppr.PlanDetails) > 0 {
323+
fmt.Fprintf(&b, detailsFormat, ppr.DiffLanguage, ppr.PlanDetails)
324+
}
325+
}
263326
}
264327
}
265328
}
@@ -311,10 +374,19 @@ func makeActionLogURL() string {
311374
}
312375

313376
func makeTitleText(app *ApplicationInfo) string {
314-
if app.Env == "" {
315-
return fmt.Sprintf(appInfoWithoutEnvFormat, app.ApplicationName, app.ApplicationURL, strings.ToLower(app.ApplicationKind))
377+
if app.AllPluginNames == "" {
378+
// pipedv0
379+
if app.Env == "" {
380+
return fmt.Sprintf(appInfoWithoutEnvFormat, app.ApplicationName, app.ApplicationURL, strings.ToLower(app.ApplicationKind))
381+
}
382+
return fmt.Sprintf(appInfoWithEnvFormat, app.ApplicationName, app.ApplicationURL, app.Env, strings.ToLower(app.ApplicationKind))
383+
} else {
384+
// pipedv1
385+
if app.Env == "" {
386+
return fmt.Sprintf(appInfoWithoutEnvFormatV1, app.ApplicationName, app.ApplicationURL, app.PlannedPluginNames)
387+
}
388+
return fmt.Sprintf(appInfoWithEnvFormatV1, app.ApplicationName, app.ApplicationURL, app.Env, app.PlannedPluginNames)
316389
}
317-
return fmt.Sprintf(appInfoWithEnvFormat, app.ApplicationName, app.ApplicationURL, app.Env, strings.ToLower(app.ApplicationKind))
318390
}
319391

320392
func generateTerraformShortPlanDetails(details string) (string, error) {

0 commit comments

Comments
 (0)