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

Update testenv -ga tag check to handle jdk8u aarch32 port repo and checking for Lightweight git tags #1015

Merged
merged 6 commits into from
Apr 22, 2024
Merged
61 changes: 48 additions & 13 deletions pipelines/build/openjdk_pipeline.groovy
Original file line number Diff line number Diff line change
@@ -21,35 +21,70 @@ Closure configureBuild = null
def buildConfigurations = null
Map<String, ?> DEFAULTS_JSON = null

// Find the testenv ga commit SHA specified by the jdkBranch
// Returns a Tuple2 of "repository", "gaCommitSHA"
def findGaCommitSHA(String repo, String jdkBranch, Boolean annotatedTag) {
def openjdkRepo = repo

// Resolve a "-ga" tag to the actual upstream openjdk build tag of the same commit
// Also check adoptium mirror for "dryrun" tags
def resolveGaTag(String jdkVersion, String jdkBranch) {
def resolvedTag = jdkBranch // Default to as-is

def openjdkRepo = "https://github.com/openjdk/jdk${jdkVersion}.git"

def gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${openjdkRepo} | grep '\\^{}' | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
if (annotatedTag) {
println "Searching for Annotated git tag with name '${jdkBranch}' using repo base: ${openjdkRepo}"
} else {
println "Searching for Lightweight git tag with name '${jdkBranch}' using repo base: ${openjdkRepo}"
}

// Annotated tags are refs with suffix ^{}
def annotatedTagFilter = (annotatedTag ? "| grep '\\^{}'" : "| grep -v '\\^{}'")

def gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${openjdkRepo} ${annotatedTagFilter} | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
if (gaCommitSHA == "") {
// Try "updates" repo..
openjdkRepo = "https://github.com/openjdk/jdk${jdkVersion}u.git"
gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${openjdkRepo} | grep '\\^{}' | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${openjdkRepo} ${annotatedTagFilter} | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
}
if (gaCommitSHA == "") {
// Maybe an Adoptium "dryrun" try Adoptium mirror repo..
openjdkRepo = "https://github.com/adoptium/jdk${jdkVersion}.git"
gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${openjdkRepo} | grep '\\^{}' | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${openjdkRepo} ${annotatedTagFilter} | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
}
if (gaCommitSHA == "") {
// Maybe an Adoptium "dryrun" try Adoptium mirror "updates" repo..
openjdkRepo = "https://github.com/adoptium/jdk${jdkVersion}u.git"
gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${openjdkRepo} | grep '\\^{}' | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${openjdkRepo} ${annotatedTagFilter} | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
}

if (gaCommitSHA == "") {
if (gaCommitSHA != "") {
return new Tuple2(openjdkRepo, gaCommitSHA)
} else {
return null
}
}

// Resolve a "-ga" tag to the actual upstream openjdk build tag of the same commit
// Also check adoptium mirror for "dryrun" tags
def resolveGaTag(String jdkVersion, String jdkBranch) {
def resolvedTag = jdkBranch // Default to as-is

def openjdkRepo = "https://github.com/openjdk/jdk${jdkVersion}.git"
if (jdkBranch.contains("jdk8u") && jdkBranch.contains("aarch32")) {
openjdkRepo = "https://github.com/openjdk/aarch32-port-jdk8u.git"
}

Boolean annotatedTag = true
def resolveGaCommit = findGaCommitSHA(openjdkRepo, jdkBranch, annotatedTag)
if (resolveGaCommit == null) {
// Try searching for a lightweight tag
annotatedTag = false
resolveGaCommit = findGaCommitSHA(openjdkRepo, jdkBranch, annotatedTag)
}

if (resolveGaCommit == null) {
println "[ERROR] Unable to resolve ${jdkBranch} upstream commit, will try to match tag as-is"
} else {
def upstreamTag = sh(returnStdout: true, script:"git ls-remote --tags ${openjdkRepo} | grep '\\^{}' | grep \"${gaCommitSHA}\" | grep -v \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f2 | sed \"s,refs/tags/,,\" | sed \"s,\\^{},,\" | tr -d '\\n'")
// Annotated tags are refs with suffix ^{}
def annotatedTagFilter = (annotatedTag ? "| grep '\\^{}'" : "| grep -v '\\^{}'")
def foundRepo = resolveGaCommit.get(0)
def foundSHA = resolveGaCommit.get(1)
def upstreamTag = sh(returnStdout: true, script:"git ls-remote --tags ${foundRepo} ${annotatedTagFilter} | grep \"${foundSHA}\" | grep -v \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f2 | sed \"s,refs/tags/,,\" | sed \"s,\\^{},,\" | tr -d '\\n'")
if (upstreamTag != "") {
println "[INFO] Resolved ${jdkBranch} to upstream build tag ${upstreamTag}"
resolvedTag = upstreamTag