Skip to content

Commit

Permalink
Merge pull request #1243 from paketo-buildpacks/oracle-action
Browse files Browse the repository at this point in the history
Creates an Oracle dependency updater
  • Loading branch information
anthonydahanne authored Dec 7, 2023
2 parents 7841b1a + c5f9d0d commit b28c692
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions actions/oracle-dependency/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2023-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"fmt"
"regexp"

"github.com/gocolly/colly"
"github.com/paketo-buildpacks/pipeline-builder/actions"
)

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

typeName, ok := inputs["type"]
if !ok {
panic(fmt.Errorf("type must be specified"))
}

versionBranch, ok := inputs["version"]
if !ok {
panic(fmt.Errorf("version must be specified"))
}

var pattern *regexp.Regexp
var key string
var urlTemplate string
switch typeName {
case "jdk":
pattern = regexp.MustCompile(`^JDK Development Kit (\d+\.\d+\.\d+) downloads$`)
key = fmt.Sprintf("java%s", versionBranch)
urlTemplate = "https://download.oracle.com/java/%s/archive/jdk-%s_linux-x64_bin.tar.gz"
case "graalvm":
pattern = regexp.MustCompile(`^GraalVM for JDK (\d+\.\d+\.\d+) downloads$`)
key = fmt.Sprintf("graalvmjava%s", versionBranch)
urlTemplate = "https://download.oracle.com/graalvm/%s/archive/graalvm-jdk-%s_linux-x64_bin.tar.gz"
default:
panic(fmt.Errorf("unsupported type %s", typeName))
}

uri := "https://www.oracle.com/java/technologies/downloads"

c := colly.NewCollector()
versions := make(actions.Versions)

c.OnHTML(fmt.Sprintf("h3[id=%s]", key), func(element *colly.HTMLElement) {
foundVersions := pattern.FindStringSubmatch(element.Text)
if len(foundVersions) == 2 {
foundVersion := foundVersions[1] // there should only ever be one
versions[foundVersion] = fmt.Sprintf(urlTemplate, versionBranch, foundVersion)
}
})

if err := c.Visit(uri); err != nil {
panic(err)
}

if o, err := versions.GetLatest(inputs); err != nil {
panic(err)
} else {
o.Write()
}
}

0 comments on commit b28c692

Please sign in to comment.