-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically add deprecation_date field to buildpack dependencies
Co-authored-by: Pavel Busko <pavel.busko@sap.com> Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
- Loading branch information
1 parent
7f364b3
commit ef30385
Showing
7 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package carton | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
eol "github.com/kobayashi/eol/pkg/api" | ||
) | ||
|
||
func GetEolDate(eolID, version string) (string, error) { | ||
cycleList, err := eol.NewHTTPClient().GetProjectCycleList(context.Background(), eolID) | ||
if err != nil { | ||
return "", fmt.Errorf("could not fetch cycle list: %w", err) | ||
} | ||
|
||
cycle, err := selectCycle(version, cycleList) | ||
if err != nil { | ||
return "", fmt.Errorf("could not find a relese cycle: %w", err) | ||
} | ||
|
||
if cycle.EOL.B != nil { | ||
return "", nil | ||
} | ||
|
||
eol, err := time.Parse(time.DateOnly, *cycle.EOL.S) | ||
if err != nil { | ||
return "", fmt.Errorf("could not parse eol %q: %w", *cycle.EOL.S, err) | ||
} | ||
|
||
return eol.Format(time.RFC3339), nil | ||
} | ||
|
||
func selectCycle(version string, cycles eol.CycleList) (*eol.Cycle, error) { | ||
versionParsed, err := semver.NewVersion(version) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, v := range []string{fmt.Sprintf("%d.%d", versionParsed.Major(), versionParsed.Minor()), fmt.Sprintf("%d", versionParsed.Major())} { | ||
for _, c := range cycles { | ||
if (c.Cycle.S != nil && *c.Cycle.S == v) || (c.Cycle.I != nil && fmt.Sprintf("%d", *c.Cycle.I) == v) { | ||
return c, nil | ||
} | ||
} | ||
} | ||
|
||
return nil, fmt.Errorf("no release cycle found for the version %s", version) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package carton_test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/buildpacks/libcnb/mocks" | ||
"github.com/jarcoal/httpmock" | ||
. "github.com/onsi/gomega" | ||
"github.com/paketo-buildpacks/libpak/carton" | ||
"github.com/sclevine/spec" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func testGetEolDate(t *testing.T, context spec.G, it spec.S) { | ||
var ( | ||
Expect = NewWithT(t).Expect | ||
|
||
exitHandler *mocks.ExitHandler | ||
) | ||
|
||
it.Before(func() { | ||
httpmock.Activate() | ||
exitHandler = &mocks.ExitHandler{} | ||
exitHandler.On("Error", mock.Anything) | ||
}) | ||
|
||
it.After(func() { | ||
httpmock.DeactivateAndReset() | ||
}) | ||
|
||
context("finds release cycle by major.minor version", func() { | ||
it.Before(func() { | ||
httpmock.RegisterResponder(http.MethodGet, "https://endoflife.date/api/foo.json", httpmock.NewBytesResponder(200, []byte(` | ||
[ | ||
{ | ||
"cycle": "10.1", | ||
"releaseDate": "2022-09-23", | ||
"eol": false, | ||
"minJavaVersion": 11, | ||
"latest": "10.1.24", | ||
"latestReleaseDate": "2024-05-09", | ||
"lts": false | ||
}, | ||
{ | ||
"cycle": "10.0", | ||
"releaseDate": "2020-12-03", | ||
"eol": "2022-10-31", | ||
"minJavaVersion": 8, | ||
"latest": "10.0.27", | ||
"latestReleaseDate": "2022-10-03", | ||
"lts": false | ||
}, | ||
{ | ||
"cycle": "9", | ||
"releaseDate": "2017-09-27", | ||
"eol": false, | ||
"minJavaVersion": 8, | ||
"latest": "9.0.89", | ||
"latestReleaseDate": "2024-05-03", | ||
"lts": false | ||
} | ||
]`))) | ||
}) | ||
|
||
it("returns correct cycle", func() { | ||
eolDate, err := carton.GetEolDate("foo", "10.0.0") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(eolDate).To(Equal("2022-10-31T00:00:00Z")) | ||
}) | ||
}) | ||
|
||
context("finds release cycle by major version", func() { | ||
it.Before(func() { | ||
httpmock.RegisterResponder(http.MethodGet, "https://endoflife.date/api/foo.json", httpmock.NewBytesResponder(200, []byte(` | ||
[ | ||
{ | ||
"cycle": "10", | ||
"releaseDate": "2022-09-23", | ||
"eol": "2024-10-31", | ||
"minJavaVersion": 11, | ||
"latest": "10.1.24", | ||
"latestReleaseDate": "2024-05-09", | ||
"lts": false | ||
}, | ||
{ | ||
"cycle": "9", | ||
"releaseDate": "2020-12-03", | ||
"eol": "2022-10-31", | ||
"minJavaVersion": 8, | ||
"latest": "9.0.27", | ||
"latestReleaseDate": "2022-10-03", | ||
"lts": false | ||
} | ||
]`))) | ||
}) | ||
|
||
it("returns correct cycle", func() { | ||
eolDate, err := carton.GetEolDate("foo", "10.1.1") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(eolDate).To(Equal("2024-10-31T00:00:00Z")) | ||
}) | ||
}) | ||
|
||
context("cycle.EOL is bool", func() { | ||
it.Before(func() { | ||
httpmock.RegisterResponder(http.MethodGet, "https://endoflife.date/api/foo.json", httpmock.NewBytesResponder(200, []byte(` | ||
[ | ||
{ | ||
"cycle": "10", | ||
"releaseDate": "2022-09-23", | ||
"eol": false, | ||
"minJavaVersion": 11, | ||
"latest": "10.1.24", | ||
"latestReleaseDate": "2024-05-09", | ||
"lts": false | ||
}, | ||
{ | ||
"cycle": "9", | ||
"releaseDate": "2020-12-03", | ||
"eol": "2022-10-31", | ||
"minJavaVersion": 8, | ||
"latest": "9.0.27", | ||
"latestReleaseDate": "2022-10-03", | ||
"lts": false | ||
} | ||
]`))) | ||
}) | ||
|
||
it("returns empty eol date", func() { | ||
eolDate, err := carton.GetEolDate("foo", "10.0.0") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(eolDate).To(Equal("")) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters