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

Makes changes needed for 1.0 release #886

Merged
merged 1 commit into from
Dec 4, 2024
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
46 changes: 29 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ file that looks like the following:
build = true
```

## Configuration

### `BP_DOTNET_FRAMEWORK_VERSION`
The `BP_DOTNET_FRAMEWORK_VERSION` variable allows you to specify the version of
ASP.NET Core Runtime that is installed. The environment variable can be
set at build-time either directly (ex. `pack build my-app --env
BP_ENVIRONMENT_VARIABLE=some-value`) or through a [`project.toml`
file](https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md)

```shell
BP_DOTNET_FRAMEWORK_VERSION=6.0.5
```

### `BP_LOG_LEVEL`
The `BP_LOG_LEVEL` variable allows you to configure the level of log output
from the **buildpack itself**. The environment variable can be set at build
time either directly (ex. `pack build my-app --env BP_LOG_LEVEL=DEBUG`) or
through a [`project.toml`
file](https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md)
If no value is set, the default value of `INFO` will be used.

The options for this setting are:
- `INFO`: (Default) log information about the progress of the build process
- `DEBUG`: log debugging information about the progress of the build process

```shell
BP_LOG_LEVEL="DEBUG"
```

## Usage

To package this buildpack for consumption:
Expand All @@ -51,20 +80,3 @@ $ ./scripts/package.sh

This builds the buildpack's Go source using `GOOS=linux` by default. You can
supply another value as the first argument to `package.sh`.

## (Deprecated) `buildpack.yml` Configurations

```yaml
dotnet-sdk:
# this allows you to specify a version constaint for the dotnet-sdk dependency
# any valid semver constaints (e.g. 6.* and 6.0.*) are also acceptable
version: "6.0.1"
```
This configuration option will be deprecated with the next major version
release of the buildpack. Because the versions of the .NET Core runtime and
.NET Core SDK are so tightly coupled, most users should instead use the
`$BP_DOTNET_FRAMEWORK_VERSION` environment variable to specify which version of
the .NET Core runtime that the [Paketo .NET Core Runtime
Buildpack](https://github.com/paketo-buildpacks/dotnet-core-runtime) should
install. This buildpack will automatically select an SDK version to install
that is compatible with the selected .NET Core runtime version.
8 changes: 0 additions & 8 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"
"time"

"github.com/Masterminds/semver"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/cargo"
"github.com/paketo-buildpacks/packit/v2/chronos"
Expand Down Expand Up @@ -47,7 +46,6 @@ func Build(entryResolver EntryResolver,
logger.Candidates(entries)

version, _ := planEntry.Metadata["version"].(string)
versionSource, _ := planEntry.Metadata["version-source"].(string)

sdkDependency, err := dependencyManager.Resolve(filepath.Join(context.CNBPath, "buildpack.toml"), planEntry.Name, version, context.Stack)
if err != nil {
Expand All @@ -56,12 +54,6 @@ func Build(entryResolver EntryResolver,

logger.SelectedDependency(planEntry, sdkDependency, clock.Now())

if versionSource == "buildpack.yml" {
nextMajorVersion := semver.MustParse(context.BuildpackInfo.Version).IncMajor()
logger.Break()
logger.Subprocess("WARNING: Setting the .NET Core SDK version through buildpack.yml will be deprecated soon in .NET Core SDK Buildpack v%s.", nextMajorVersion.String())
}

sdkLayer, err := context.Layers.Get("dotnet-core-sdk")
if err != nil {
return packit.BuildResult{}, err
Expand Down
36 changes: 0 additions & 36 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,42 +334,6 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
})
})

context("when the sdk version is set via buildpack.yml", func() {
it.Before(func() {
entryResolver.ResolveCall.Returns.BuildpackPlanEntry = packit.BuildpackPlanEntry{
Name: "dotnet-sdk",
Metadata: map[string]interface{}{
"version": "2.5.x",
"version-source": "buildpack.yml",
"build": true,
"launch": true,
},
}
})

it("logs a deprecation warning", func() {
_, err := build(packit.BuildContext{
BuildpackInfo: packit.BuildpackInfo{
Version: "1.2.3",
},
Plan: packit.BuildpackPlan{
Entries: []packit.BuildpackPlanEntry{
{
Name: "dotnet-sdk",
},
},
},
Layers: packit.Layers{Path: layersDir},
CNBPath: cnbDir,
WorkingDir: workingDir,
Stack: "some-stack",
})
Expect(err).NotTo(HaveOccurred())

Expect(buffer.String()).To(ContainSubstring("WARNING: Setting the .NET Core SDK version through buildpack.yml will be deprecated soon in .NET Core SDK Buildpack v2.0.0"))
})
})

context("failure cases", func() {
context("when the dependency for the build plan entry cannot be resolved", func() {
it.Before(func() {
Expand Down
22 changes: 1 addition & 21 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import (
"github.com/paketo-buildpacks/packit/v2"
)

//go:generate faux --interface BuildpackYMLParser --output fakes/buildpack_yml_parser.go
type BuildpackYMLParser interface {
Parse(workingDir string) (string, error)
}

func Detect(buildpackYMLParser BuildpackYMLParser) packit.DetectFunc {
func Detect() packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
plan := packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
Expand All @@ -37,21 +32,6 @@ func Detect(buildpackYMLParser BuildpackYMLParser) packit.DetectFunc {
})
}

version, err := buildpackYMLParser.Parse(context.WorkingDir)
if err != nil {
return packit.DetectResult{}, err
}

if version != "" {
plan.Requires = append(plan.Requires, packit.BuildPlanRequirement{
Name: "dotnet-sdk",
Metadata: map[string]interface{}{
"version": version,
"version-source": "buildpack.yml",
},
})
}

return packit.DetectResult{Plan: plan}, nil
}
}
47 changes: 1 addition & 46 deletions detect_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package dotnetcoresdk_test

import (
"errors"
"os"
"testing"

dotnetcoresdk "github.com/paketo-buildpacks/dotnet-core-sdk"
"github.com/paketo-buildpacks/dotnet-core-sdk/fakes"
"github.com/paketo-buildpacks/packit/v2"
"github.com/sclevine/spec"

Expand All @@ -17,14 +15,11 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect

buildpackYMLParser *fakes.BuildpackYMLParser

detect packit.DetectFunc
)

it.Before(func() {
buildpackYMLParser = &fakes.BuildpackYMLParser{}
detect = dotnetcoresdk.Detect(buildpackYMLParser)
detect = dotnetcoresdk.Detect()
})

it("provides the dotnet-sdk as a dependency and requires nothing", func() {
Expand Down Expand Up @@ -69,34 +64,6 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
})
})

context("when a version is specified in the buildpack.yml", func() {
it.Before(func() {
buildpackYMLParser.ParseCall.Returns.String = "some-version"
})

it("requires the version of the SDK specified in the buildpack.yml", func() {
result, err := detect(packit.DetectContext{
WorkingDir: "working-dir",
})
Expect(err).NotTo(HaveOccurred())
Expect(result.Plan).To(Equal(packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: "dotnet-sdk"},
},
Requires: []packit.BuildPlanRequirement{
{
Name: "dotnet-sdk",
Metadata: map[string]interface{}{
"version": "some-version",
"version-source": "buildpack.yml",
},
},
},
}))
Expect(buildpackYMLParser.ParseCall.Receives.WorkingDir).To(Equal("working-dir"))
})
})

context("failure cases", func() {
context("BP_DOTNET_FRAMEWORK_VERSION is not a semantic version", func() {
it.Before(func() {
Expand All @@ -113,17 +80,5 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Expect(err).To(MatchError("Invalid Semantic Version"))
})
})
context("when buildpackYML can't be parsed", func() {
it.Before(func() {
buildpackYMLParser.ParseCall.Returns.Error = errors.New("some-error")
})

it("returns an error", func() {
_, err := detect(packit.DetectContext{
WorkingDir: "working-dir",
})
Expect(err).To(MatchError("some-error"))
})
})
})
}
29 changes: 0 additions & 29 deletions fakes/buildpack_yml_parser.go

This file was deleted.

1 change: 0 additions & 1 deletion init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ func TestUnitDotnetCoreSDK(t *testing.T) {
suite := spec.New("dotnet-core-sdk", spec.Report(report.Terminal{}), spec.Sequential())
suite("Build", testBuild)
suite("Detect", testDetect)
suite("SdkVersionParser", testSdkVersionParser)
suite.Run(t)
}
2 changes: 1 addition & 1 deletion integration.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"builders" : ["paketobuildpacks/builder:buildpackless-base", "paketobuildpacks/builder-jammy-buildpackless-base"],
"builders" : ["paketobuildpacks/builder-jammy-buildpackless-base"],
"build-plan": "github.com/paketo-community/build-plan"
}
3 changes: 1 addition & 2 deletions run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ func (f Generator) GenerateFromDependency(dependency postal.Dependency, path str
}

func main() {
sdkVersionParser := dotnetcoresdk.NewSdkVersionParser()
logEmitter := scribe.NewEmitter(os.Stdout).WithLevel(os.Getenv("BP_LOG_LEVEL"))
entryResolver := draft.NewPlanner()
dependencyManager := postal.NewService(cargo.NewTransport())

packit.Run(
dotnetcoresdk.Detect(sdkVersionParser),
dotnetcoresdk.Detect(),
dotnetcoresdk.Build(
entryResolver,
dependencyManager,
Expand Down
36 changes: 0 additions & 36 deletions sdk_version_parser.go

This file was deleted.

Loading
Loading