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

Provide latest Chrome Driver releases to tools #140

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
63 changes: 15 additions & 48 deletions chromedriver.groovy
Original file line number Diff line number Diff line change
@@ -1,55 +1,22 @@
#!./lib/runner.groovy
// Generates server-side metadata for chromedriver auto-installation
import net.sf.json.*
import groovy.util.XmlSlurper
import net.sf.json.JSONObject
import groovy.json.JsonSlurper
import groovy.json.JsonOutput

def baseUrl = 'https://chromedriver.storage.googleapis.com/'
def json = []
def map = [:].withDefault {[:].withDefault {[:]}}
def url = 'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json'
def jsonString = new URL(url).text
def jsonData = new JsonSlurper().parseText(jsonString)

def xml = new XmlSlurper().parseText(new URL(baseUrl).text)
xml.Contents.each {
def key = it.Key.text()
def m = key =~ /(.*)\/chromedriver_(.*?)(\d+)\.zip/
if (m) {
def (_, version, os, arch) = m[0]
map[os][arch][version] = key
json << ["id":"${os}${arch}_${version}".toString(), "url":baseUrl + key];
}
}
def jsonList = []

map.each { os, arch ->
if (arch.size() == 1) {
def latest = arch.find().value.max { a, b ->
List verA = a.key.tokenize('.')
List verB = b.key.tokenize('.')
def commonIndices = Math.min(verA.size(), verB.size())
for (int i = 0; i < commonIndices; ++i) {
def numA = verA[i].toInteger()
def numB = verB[i].toInteger()
if (numA != numB) {
return numA <=> numB
}
}
verA.size() <=> verB.size() }
json << ["id":os, "url":baseUrl + latest.value];
} else {
arch.each { k, v ->
def latest = v.max { a, b ->
List verA = a.key.tokenize('.')
List verB = b.key.tokenize('.')
def commonIndices = Math.min(verA.size(), verB.size())
for (int i = 0; i < commonIndices; ++i) {
def numA = verA[i].toInteger()
def numB = verB[i].toInteger()
if (numA != numB) {
return numA <=> numB
}
}
verA.size() <=> verB.size() }
json << ["id":os + k, "url":baseUrl + latest.value];
}
}
// Extract information only for the "Stable" channel
def stableData = jsonData.channels.Stable
def chromeDriverData = stableData.downloads.chromedriver
chromeDriverData.each { entry ->
def id = "${entry.platform}_${stableData.version}"
def entry_url = entry.url
jsonList << ["id": id, "url": entry_url]
}

lib.DataWriter.write("org.jenkins-ci.plugins.chromedriver.ChromeDriver",JSONObject.fromObject([list:json]));
lib.DataWriter.write("org.jenkins-ci.plugins.chromedriver.ChromeDriver",JSONObject.fromObject([list:jsonList]))