Skip to content

Commit

Permalink
Merge pull request #97 from rithin-pullela-aws/plugin-onboard-main
Browse files Browse the repository at this point in the history
Modified build scripts to onboard LTR to OpenSearch
  • Loading branch information
JohannesDaniel authored Jan 14, 2025
2 parents 425aa0d + c43f509 commit 556f834
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 44 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java:
- 11
- 17
java:
# We need 2.12.0 at minimum for JDK 21.0.2
- 21.0.1
steps:
Expand Down
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.0
21.0
102 changes: 64 additions & 38 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import java.nio.file.Files

buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT")
is_snapshot = "true" == System.getProperty("build.snapshot", "true")
build_version_qualifier = System.getProperty("build.version_qualifier", "")

version_tokens = opensearch_version.tokenize('-')
opensearch_build = version_tokens[0] + '.0'
if (build_version_qualifier) {
opensearch_build += "-${build_version_qualifier}"
}
if (is_snapshot) {
opensearch_build += "-SNAPSHOT"
}
}

repositories {
mavenLocal()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
Expand All @@ -9,25 +24,23 @@ buildscript {
}

dependencies {
classpath "org.opensearch.gradle:build-tools:${opensearchVersion}"
classpath "org.opensearch.gradle:build-tools:${opensearch_version}"
}
}

plugins {
id "co.riiid.gradle" version "0.4.2"
id 'java'
id 'idea'
id 'maven-publish'
}

group = 'org.opensearch'
version = opensearch_build

group = 'com.o19s'
version = "${ltrVersion}-os${opensearchVersion}"

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.java-rest-test'
apply plugin: 'opensearch.rest-resources'
//apply plugin: 'opensearch.yaml-rest-test'

apply plugin: 'opensearch.pluginzip'

idea {
module {
Expand All @@ -46,7 +59,7 @@ noticeFile = rootProject.file('NOTICE.txt')
//uploadArchives.enabled = false

opensearchplugin {
name 'ltr'
name 'opensearch-ltr'
description 'Learning to Rank Query w/ RankLib Models'
classname 'com.o19s.es.ltr.LtrQueryParserPlugin'
// license of the plugin, may be different than the above license
Expand All @@ -55,6 +68,44 @@ opensearchplugin {
noticeFile = rootProject.file('NOTICE.txt')
}

publishing {
publications {
pluginZip(MavenPublication) { publication ->
pom {
name = "opensearch-ltr"
description = "Learning to Rank Query w/ RankLib Models"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
name = "OpenSearch"
url = "https://github.com/opensearch-project/opensearch-learning-to-rank-base"
}
}
}
}
}

repositories {
maven {
name = 'staging'
url = layout.buildDirectory.dir('local-staging-repo')
}
maven {
name = "Snapshots"
url = "https://aws.oss.sonatype.org/content/repositories/snapshots"
credentials {
username "$System.env.SONATYPE_USERNAME"
password "$System.env.SONATYPE_PASSWORD"
}
}
}
}

// In this section you declare the dependencies for your production and test code
// OpenSearch dependency is included due to the build-tools, test-framework as well
repositories {
Expand All @@ -79,9 +130,6 @@ dependencies {
runtimeOnly 'org.apache.logging.log4j:log4j-core:2.21.0'
}




// see https://github.com/opensearch-project/OpenSearch/blob/0ba0e7cc26060f964fcbf6ee45bae53b3a9941d0/buildSrc/src/main/java/org/opensearch/gradle/precommit/DependencyLicensesTask.java
dependencyLicenses {
mapping from: /lucene-.*/, to: 'lucene'
Expand All @@ -99,8 +147,10 @@ sourceSets {
}

java {
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
withSourcesJar()
withJavadocJar()
}


Expand All @@ -123,30 +173,6 @@ validateNebulaPom.enabled = false
// https://github.com/elastic/opensearch/issues/65247
loggerUsageCheck.enabled = false

githubRelease.doFirst {
if (!System.getProperty('GITHUB_TOKEN', '')) {
throw new Exception('Missing property GITHUB_TOKEN')
}

// check if zip file is there
assert file("build/distributions/ltr-${version}.zip").exists()

// rename zip file
def currentVersion = version.replace('-SNAPSHOT', '')
def filename = "build/distributions/ltr-${currentVersion}.zip"
Files.copy(file("build/distributions/ltr-${version}.zip").toPath(), file(filename).toPath())

// configuration
github {
owner = 'gsingers'
repo = 'opensearch-learning-to-rank-base'
token = System.getProperty('GITHUB_TOKEN')
tagName = currentVersion
assets = [ filename ]
targetCommitish = 'main'
}
}

tasks.withType(Test).configureEach { task ->
if (JavaVersion.current().compareTo(JavaVersion.VERSION_17) > 0 && JavaVersion.current().compareTo(JavaVersion.VERSION_21) < 0) {
def policyFile = file("${projectDir}/src/main/plugin-metadata/plugin-security.policy").absolutePath
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ltrVersion = 3.0.0-SNAPSHOT
opensearchVersion = 3.0.0-SNAPSHOT
luceneVersion = 9.7.0
ow2Version = 9.6
antlrVersion=4.11.1
87 changes: 87 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

set -ex

function usage() {
echo "Usage: $0 [args]"
echo ""
echo "Arguments:"
echo -e "-v VERSION\t[Required] OpenSearch version."
echo -e "-q QUALIFIER\t[Optional] Version qualifier."
echo -e "-s SNAPSHOT\t[Optional] Build a snapshot, default is 'false'."
echo -e "-p PLATFORM\t[Optional] Platform, ignored."
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, ignored."
echo -e "-o OUTPUT\t[Optional] Output path, default is 'artifacts'."
echo -e "-h help"
}

while getopts ":h:v:q:s:o:p:a:" arg; do
case $arg in
h)
usage
exit 1
;;
v)
VERSION=$OPTARG
;;
q)
QUALIFIER=$OPTARG
;;
s)
SNAPSHOT=$OPTARG
;;
o)
OUTPUT=$OPTARG
;;
p)
PLATFORM=$OPTARG
;;
a)
ARCHITECTURE=$OPTARG
;;
:)
echo "Error: -${OPTARG} requires an argument"
usage
exit 1
;;
?)
echo "Invalid option: -${arg}"
exit 1
;;
esac
done

if [ -z "$VERSION" ]; then
echo "Error: You must specify the OpenSearch version"
usage
exit 1
fi

[[ ! -z "$QUALIFIER" ]] && VERSION=$VERSION-$QUALIFIER
[[ "$SNAPSHOT" == "true" ]] && VERSION=$VERSION-SNAPSHOT
[ -z "$OUTPUT" ] && OUTPUT=artifacts

mkdir -p $OUTPUT

./gradlew assemble --no-daemon --refresh-dependencies -DskipTests=true -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER

zipPath=$(find . -path \*build/distributions/*.zip)
distributions="$(dirname "${zipPath}")"

echo "COPY ${distributions}/*.zip"
mkdir -p $OUTPUT/plugins
cp ${distributions}/*.zip ./$OUTPUT/plugins

# Publish plugin zips to maven
./gradlew publishPluginZipPublicationToMavenLocal -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
./gradlew publishPluginZipPublicationToZipStagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
./gradlew publishPluginZipPublicationToStagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
mkdir -p $OUTPUT/maven/org/opensearch
cp -r ./build/local-staging-repo/org/opensearch/. $OUTPUT/maven/org/opensearch

0 comments on commit 556f834

Please sign in to comment.