Skip to content

Commit

Permalink
Fix bellsoft liberica NIK retrieval
Browse files Browse the repository at this point in the history
* there can be, i particular for sources retrieval, https://api.bell-sw.com/v1/nik/releases?package-type=src.tar.gz&version-modifier=latest&bundle-type=standard&component-version=liberica%4017, several components; let's just focus on liberica :

"components": [
      {
        "version": "23.0.3",
        "embedded": true,
        "component": "icu4j"
      },
      {
        "version": "17.0.10+13",
        "embedded": true,
        "component": "liberica"
      },
      ...
]
  • Loading branch information
anthonydahanne committed Mar 25, 2024
1 parent 01528b5 commit fc7badb
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions actions/bellsoft-liberica-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/paketo-buildpacks/pipeline-builder/actions"
)

const liberica = "liberica"

func main() {
inputs := actions.NewInputs()

Expand Down Expand Up @@ -171,12 +173,16 @@ func main() {

func determineNikVersion(r Release, additionalOutputs actions.Outputs) string {
key := ""
if v, err := actions.NormalizeVersion(r.Components[0].Version); err != nil {
componentVersion, err := r.retrieveComponentVersionFor(liberica)
if err != nil {
panic(err)
}
if v, err := actions.NormalizeVersion(componentVersion); err != nil {
panic(err)
} else {
key = v
// Use NIK version for CPE/PURL
re := regexp.MustCompile(`\/vm/([\d]+\.[\d]+\.[\d]+\.?[\d]?)\/`)
re := regexp.MustCompile(`/LibericaNIK/releases/download/([\d]+\.[\d]+\.[\d]+\.?[\d]?)\+.*-`)
matches := re.FindStringSubmatch(r.DownloadURL)
if matches == nil || len(matches) != 2 {
panic(fmt.Errorf("unable to parse NIK version: %s", matches))
Expand All @@ -194,6 +200,16 @@ type Release struct {
BuildVersion int `json:"buildVersion"`
DownloadURL string `json:"downloadUrl"`
Components []struct {
Version string `json:"version"`
Version string `json:"version"`
Component string `json:"component"`
}
}

func (r Release) retrieveComponentVersionFor(componentName string) (string, error) {
for _, v := range r.Components {
if v.Component == componentName {
return v.Version, nil
}
}
return "", fmt.Errorf("unable to find a component for: %s", componentName)
}

0 comments on commit fc7badb

Please sign in to comment.