Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show extensions only if they are present for all output format in inspect builder #1710

Merged
merged 6 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ Detection Order:
│ └ simple/nested-level-2@nested-l2-version
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)

LOCAL:

Created By:
Expand Down Expand Up @@ -97,9 +91,3 @@ Detection Order:
│ └ Group #1:
│ └ simple/nested-level-2@nested-l2-version
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ Detection Order:
│ └ simple/layers@simple-layers-version
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)

LOCAL:

Created By:
Expand Down Expand Up @@ -101,9 +95,3 @@ Detection Order:
│ └ Group #1:
│ └ simple/layers@simple-layers-version
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@
}
]
}
],
"extensions": null,
"order_extensions": null
]
},
"local_info": {
"created_by": {
Expand Down Expand Up @@ -196,8 +194,6 @@
}
]
}
],
"extensions": null,
"order_extensions": null
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ remote_info:
- id: read/env
version: read-env-version
optional: true
extensions: []
order_extensions: []
local_info:
created_by:
name: Pack CLI
Expand Down Expand Up @@ -116,5 +114,3 @@ local_info:
- id: read/env
version: read-env-version
optional: true
extensions: []
order_extensions: []
12 changes: 0 additions & 12 deletions acceptance/testdata/pack_fixtures/inspect_builder_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ Detection Order:
├ simple/layers
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)

LOCAL:

Created By:
Expand Down Expand Up @@ -89,9 +83,3 @@ Detection Order:
└ Group #1:
├ simple/layers
└ read/env@read-env-version (optional)

Extensions:
(none)

Detection Order (Extensions):
(none)
37 changes: 27 additions & 10 deletions internal/builder/writer/human_readable.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ Stack:
{{ .RunImages }}
{{ .Buildpacks }}
{{ .Order }}
{{- if ne .Extensions "" }}
{{ .Extensions }}
{{ .OrderExtensions}}`
{{- end }}
{{- if ne .OrderExtensions "" }}
{{ .OrderExtensions }}
{{- end }}`
)

type HumanReadable struct{}
Expand Down Expand Up @@ -129,29 +133,42 @@ func writeBuilderInfo(
if err != nil {
return fmt.Errorf("compiling detection order output: %w", err)
}
orderExtString, orderExtWarnings, err := detectionOrderExtOutput(info.OrderExtensions, sharedInfo.Name)
if err != nil {
return fmt.Errorf("compiling detection order extensions output: %w", err)

var orderExtString string
var orderExtWarnings []string

if info.Extensions != nil {
orderExtString, orderExtWarnings, err = detectionOrderExtOutput(info.OrderExtensions, sharedInfo.Name)
if err != nil {
return fmt.Errorf("compiling detection order extensions output: %w", err)
}
}
buildpacksString, buildpacksWarnings, err := buildpacksOutput(info.Buildpacks, sharedInfo.Name)
if err != nil {
return fmt.Errorf("compiling buildpacks output: %w", err)
}
lifecycleString, lifecycleWarnings := lifecycleOutput(info.Lifecycle, sharedInfo.Name)

extensionsString, extensionsWarnings, err := extensionsOutput(info.Extensions, sharedInfo.Name)
if err != nil {
return fmt.Errorf("compiling extensions output: %w", err)
var extensionsString string
var extensionsWarnings []string

if info.Extensions != nil {
extensionsString, extensionsWarnings, err = extensionsOutput(info.Extensions, sharedInfo.Name)
if err != nil {
return fmt.Errorf("compiling extensions output: %w", err)
}
}

warnings = append(warnings, runImagesWarnings...)
warnings = append(warnings, orderWarnings...)
warnings = append(warnings, buildpacksWarnings...)
warnings = append(warnings, lifecycleWarnings...)
warnings = append(warnings, extensionsWarnings...)
warnings = append(warnings, orderExtWarnings...)

if info.Extensions != nil {
warnings = append(warnings, extensionsWarnings...)
warnings = append(warnings, orderExtWarnings...)
}
outputTemplate, _ := template.New("").Parse(outputTemplate)

err = outputTemplate.Execute(
logger.Writer(),
&struct {
Expand Down
116 changes: 110 additions & 6 deletions internal/builder/writer/human_readable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,58 @@ Detection Order (Extensions):
├ test.bp.two@test.bp.two.version (optional)
└ test.bp.three@test.bp.three.version
`
expectedRemoteOutputWithoutExtensions = `
REMOTE:

Description: Some remote description

Created By:
Name: Pack CLI
Version: 1.2.3

Trusted: No

Stack:
ID: test.stack.id

Lifecycle:
Version: 6.7.8
Buildpack APIs:
Deprecated: (none)
Supported: 1.2, 2.3
Platform APIs:
Deprecated: 0.1, 1.2
Supported: 4.5

Run Images:
first/local (user-configured)
second/local (user-configured)
some/run-image
first/default
second/default

Buildpacks:
ID NAME VERSION HOMEPAGE
test.top.nested - test.top.nested.version -
test.nested - http://geocities.com/top-bp
test.bp.one - test.bp.one.version http://geocities.com/cool-bp
test.bp.two - test.bp.two.version -
test.bp.three - test.bp.three.version -

Detection Order:
├ Group #1:
│ ├ test.top.nested@test.top.nested.version
│ │ └ Group #1:
│ │ ├ test.nested
│ │ │ └ Group #1:
│ │ │ └ test.bp.one@test.bp.one.version (optional)
│ │ ├ test.bp.three@test.bp.three.version (optional)
│ │ └ test.nested.two@test.nested.two.version
│ │ └ Group #2:
│ │ └ test.bp.one@test.bp.one.version (optional)[cyclic]
│ └ test.bp.two@test.bp.two.version (optional)
└ test.bp.three@test.bp.three.version
`

expectedLocalOutput = `
LOCAL:
Expand Down Expand Up @@ -164,6 +216,60 @@ Detection Order (Extensions):
├ test.bp.two@test.bp.two.version (optional)
└ test.bp.three@test.bp.three.version
`

expectedLocalOutputWithoutExtensions = `
LOCAL:

Description: Some local description

Created By:
Name: Pack CLI
Version: 4.5.6

Trusted: No

Stack:
ID: test.stack.id

Lifecycle:
Version: 4.5.6
Buildpack APIs:
Deprecated: 4.5, 6.7
Supported: 8.9, 10.11
Platform APIs:
Deprecated: (none)
Supported: 7.8

Run Images:
first/local (user-configured)
second/local (user-configured)
some/run-image
first/local-default
second/local-default

Buildpacks:
ID NAME VERSION HOMEPAGE
test.top.nested - test.top.nested.version -
test.nested - http://geocities.com/top-bp
test.bp.one - test.bp.one.version http://geocities.com/cool-bp
test.bp.two - test.bp.two.version -
test.bp.three - test.bp.three.version -

Detection Order:
├ Group #1:
│ ├ test.top.nested@test.top.nested.version
│ │ └ Group #1:
│ │ ├ test.nested
│ │ │ └ Group #1:
│ │ │ └ test.bp.one@test.bp.one.version (optional)
│ │ ├ test.bp.three@test.bp.three.version (optional)
│ │ └ test.nested.two@test.nested.two.version
│ │ └ Group #2:
│ │ └ test.bp.one@test.bp.one.version (optional)[cyclic]
│ └ test.bp.two@test.bp.two.version (optional)
└ test.bp.three@test.bp.three.version
`

expectedVerboseStack = `
Stack:
ID: test.stack.id
Expand All @@ -184,10 +290,6 @@ Run Images:
expectedEmptyBuildpacks = `
Buildpacks:
(none)
`
expectedEmptyExtensions = `
Extensions:
(none)
`
expectedEmptyOrder = `
Detection Order:
Expand Down Expand Up @@ -508,7 +610,7 @@ REMOTE:
})

when("no extensions are specified", func() {
it("displays extensions as (none)", func() {
it("displays no extensions as (none)", func() {
localInfo.Extensions = []dist.ModuleInfo{}
remoteInfo.Extensions = []dist.ModuleInfo{}

Expand All @@ -518,7 +620,9 @@ REMOTE:
err := humanReadableWriter.Print(logger, localRunImages, localInfo, remoteInfo, nil, nil, sharedBuilderInfo)
assert.Nil(err)

assert.Contains(outBuf.String(), expectedEmptyExtensions)
assert.Contains(outBuf.String(), "Inspecting builder: 'test-builder'")
assert.Contains(outBuf.String(), expectedRemoteOutputWithoutExtensions)
assert.Contains(outBuf.String(), expectedLocalOutputWithoutExtensions)
})
})

Expand Down
4 changes: 2 additions & 2 deletions internal/builder/writer/structured_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type BuilderInfo struct {
RunImages []RunImage `json:"run_images" yaml:"run_images" toml:"run_images"`
Buildpacks []dist.ModuleInfo `json:"buildpacks" yaml:"buildpacks" toml:"buildpacks"`
pubbldr.DetectionOrder `json:"detection_order" yaml:"detection_order" toml:"detection_order"`
Extensions []dist.ModuleInfo `json:"extensions" yaml:"extensions" toml:"extensions"`
OrderExtensions pubbldr.DetectionOrder `json:"order_extensions" yaml:"order_extensions" toml:"order_extensions"`
Extensions []dist.ModuleInfo `json:"extensions,omitempty" yaml:"extensions,omitempty" toml:"extensions,omitempty"`
OrderExtensions pubbldr.DetectionOrder `json:"order_extensions,omitempty" yaml:"order_extensions,omitempty" toml:"order_extensions,omitempty"`
}

type StructuredFormat struct {
Expand Down