Skip to content

Commit

Permalink
Creates an Oracle dependency updater
Browse files Browse the repository at this point in the history
This PR creates an Oracle dependency updater. It looks at `https://www.oracle.com/java/technologies/downloads/` and scrapes out the latest version numbers for the given type and version branch. Valid types are either `jdk` or `graalvm`. It will then fetch the download and calculate all the metadata.

Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
dmikusa committed Aug 8, 2023
1 parent 5a2b19d commit c5f9d0d
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 c5f9d0d

Please sign in to comment.