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

Remove impossible errors #818

Merged
merged 1 commit into from
Nov 2, 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
30 changes: 6 additions & 24 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,7 @@ func (b *Build) BuildPackage(ctx context.Context) error {

b.Summarize()

pkg, err := NewPackageContext(&b.Configuration.Package)
if err != nil {
return err
}
pkg := NewPackageContext(&b.Configuration.Package)
pb := PipelineBuild{
Build: b,
Package: pkg,
Expand All @@ -982,10 +979,7 @@ func (b *Build) BuildPackage(ctx context.Context) error {
}

for _, spkg := range b.Configuration.Subpackages {
spkgctx, err := NewSubpackageContext(&spkg)
if err != nil {
return fmt.Errorf("invalid subpackage: %w", err)
}
spkgctx := NewSubpackageContext(&spkg)
pb.Subpackage = spkgctx
for _, p := range spkgctx.Subpackage.Pipeline {
pctx := NewPipelineContext(&p, b.Logger)
Expand Down Expand Up @@ -1067,10 +1061,7 @@ func (b *Build) BuildPackage(ctx context.Context) error {

// run any pipelines for subpackages
for _, sp := range b.Configuration.Subpackages {
spctx, err := NewSubpackageContext(&sp)
if err != nil {
return fmt.Errorf("invalid subpackage context: %w", err)
}
spctx := NewSubpackageContext(&sp)
if !b.IsBuildLess() {
b.Logger.Printf("running pipeline for subpackage %s", sp.Name)
pb.Subpackage = spctx
Expand Down Expand Up @@ -1135,10 +1126,7 @@ func (b *Build) BuildPackage(ctx context.Context) error {
for _, sp := range b.Configuration.Subpackages {
langs := []string{}

spctx, err := NewSubpackageContext(&sp)
if err != nil {
return fmt.Errorf("invalid subpackage context: %w", err)
}
spctx := NewSubpackageContext(&sp)
if !b.IsBuildLess() {
b.Logger.Printf("generating SBOM for subpackage %s", sp.Name)
pb.Subpackage = spctx
Expand Down Expand Up @@ -1190,10 +1178,7 @@ func (b *Build) BuildPackage(ctx context.Context) error {

// emit subpackages
for _, sp := range b.Configuration.Subpackages {
spctx, err := NewSubpackageContext(&sp)
if err != nil {
return fmt.Errorf("invalid subpackage context: %w", err)
}
spctx := NewSubpackageContext(&sp)
pb.Subpackage = spctx

result, err := spctx.ShouldRun(&pb)
Expand Down Expand Up @@ -1234,10 +1219,7 @@ func (b *Build) BuildPackage(ctx context.Context) error {
apkFiles = append(apkFiles, filepath.Join(packageDir, pkgFileName))

for _, subpkg := range b.Configuration.Subpackages {
spctx, err := NewSubpackageContext(&subpkg)
if err != nil {
return fmt.Errorf("invalid subpackage context: %w", err)
}
spctx := NewSubpackageContext(&subpkg)
pb.Subpackage = spctx

result, err := spctx.ShouldRun(&pb)
Expand Down
13 changes: 5 additions & 8 deletions pkg/build/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ type PackageContext struct {
Package *config.Package
}

func NewPackageContext(pkg *config.Package) (*PackageContext, error) {
func NewPackageContext(pkg *config.Package) *PackageContext {
return &PackageContext{
Package: pkg,
}, nil
}
}

type SubpackageContext struct {
Subpackage *config.Subpackage
}

// Create a new subpackage context
func NewSubpackageContext(pkg *config.Subpackage) (*SubpackageContext, error) {
func NewSubpackageContext(pkg *config.Subpackage) *SubpackageContext {
return &SubpackageContext{
Subpackage: pkg,
}, nil
}
}

type PackageBuild struct {
Expand Down Expand Up @@ -121,10 +121,7 @@ func (pkg *PackageContext) Emit(ctx context.Context, pb *PipelineBuild) error {
}

func (spkg *SubpackageContext) Emit(ctx context.Context, pb *PipelineBuild) error {
pkgctx, err := NewPackageContext(&pb.Build.Configuration.Package)
if err != nil {
return err
}
pkgctx := NewPackageContext(&pb.Build.Configuration.Package)

pc := PackageBuild{
Build: pb.Build,
Expand Down
5 changes: 1 addition & 4 deletions pkg/build/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ func Test_removeSelfProvidedDeps_WithEmptyProvides(t *testing.T) {
}

func Test_GenerateControlData(t *testing.T) {
pkgctx, err := NewPackageContext(
pkgctx := NewPackageContext(
&config.Package{
Version: "1.2.3",
Epoch: 4,
},
)
if err != nil {
t.Fatalf("NewPackageContext() = %v", err)
}

tests := []struct {
name string
Expand Down
10 changes: 3 additions & 7 deletions pkg/build/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,12 @@ func Test_substitutionMap(t *testing.T) {
{initialVersion: "1.2.3.9", match: `\.(\d+)$`, replace: "+$1", expected: "1.2.3+9"},
}
for _, tt := range tests {
pkgctx, err := NewPackageContext(
pkgctx := NewPackageContext(
&config.Package{
Name: "foo",
Version: tt.initialVersion,
},
)
if err != nil {
t.Fatalf("NewPackageContext() = %v", err)
}

t.Run("sub", func(t *testing.T) {
pb := &PipelineBuild{
Expand Down Expand Up @@ -118,13 +115,12 @@ func Test_MutateWith(t *testing.T) {
}

func Test_substitutionNeedPackages(t *testing.T) {
pkgctx, err := NewPackageContext(
pkgctx := NewPackageContext(
&config.Package{
Name: "foo",
Version: "1.2.3",
},
)
require.NoError(t, err)

p := &config.Pipeline{
Needs: struct{ Packages []string }{Packages: []string{"foo", "${{inputs.go-package}}"}},
Expand Down Expand Up @@ -156,7 +152,7 @@ func Test_substitutionNeedPackages(t *testing.T) {
},
}

err = pctx.loadUse(pb, "go/build", pb.Build.Configuration.Pipeline[0].With)
err := pctx.loadUse(pb, "go/build", pb.Build.Configuration.Pipeline[0].With)
require.NoError(t, err)
require.Equal(t, "go-5.4.3", pctx.Pipeline.Needs.Packages[0])
}
Expand Down
Loading