From 88031ba6aba4d0b05308b87789e6e574e4c44eaf Mon Sep 17 00:00:00 2001 From: Ankit Kala Date: Tue, 24 Aug 2021 18:09:33 +0530 Subject: [PATCH] Add OpenSearch build script --- build.gradle | 24 ++++++++++++++++--- build.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 3 deletions(-) create mode 100755 build.sh diff --git a/build.gradle b/build.gradle index 65686a1bd..81dc58dc4 100644 --- a/build.gradle +++ b/build.gradle @@ -27,9 +27,16 @@ import java.util.stream.Collectors import org.opensearch.gradle.testclusters.OpenSearchCluster buildscript { + ext { - opensearch_version = System.getProperty("opensearch_version", "1.1.0") + isSnapshot = "true" == System.getProperty("build.snapshot", "true") + opensearch_version = System.getProperty("opensearch.version", "1.1.0") + // Taken from https://github.com/opensearch-project/alerting/blob/main/build.gradle#L33 + // 1.0.0 -> 1.0.0.0, and 1.0.0-SNAPSHOT -> 1.0.0.0-SNAPSHOT + opensearch_build = opensearch_version.replaceAll(/(\.\d)([^\d]*)$/, '$1.0$2') + common_utils_version = System.getProperty("common_utils.version", opensearch_build) kotlin_version = System.getProperty("kotlin.version", "1.3.72") + } repositories { @@ -47,12 +54,16 @@ buildscript { } } - plugins { id 'nebula.ospackage' version "8.3.0" id "com.dorongold.task-tree" version "1.5" } +allprojects { + group = "org.opensearch" + version = "${opensearch_version}" +} + apply plugin: 'java' apply plugin: 'jacoco' apply plugin: 'idea' @@ -91,7 +102,7 @@ dependencies { compile "org.jetbrains:annotations:13.0" compile "com.github.seancfoley:ipaddress:5.3.3" compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5" - compile "org.opensearch:common-utils:${version}" + compile "org.opensearch:common-utils:${common_utils_version}" testCompile "org.opensearch.test:framework:${opensearch_version}" testImplementation "org.assertj:assertj-core:3.17.2" @@ -104,6 +115,7 @@ repositories { mavenLocal() mavenCentral() maven { url "https://plugins.gradle.org/m2/" } + jcenter() } compileKotlin { @@ -132,6 +144,12 @@ opensearchplugin { classname = "org.opensearch.replication.ReplicationPlugin" } +artifacts { + if (!isSnapshot) { + archives sourcesJar + archives javadocJar + } +} javadoc.enabled = false licenseHeaders.enabled = false diff --git a/build.sh b/build.sh new file mode 100755 index 000000000..7fec94fbf --- /dev/null +++ b/build.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Copyright OpenSearch Contributors. +# SPDX-License-Identifier: Apache-2.0 + +set -ex + +function usage() { + echo "Usage: $0 [args]" + echo "" + echo "Arguments:" + echo -e "-v VERSION\t[Required] OpenSearch version." + echo -e "-s SNAPSHOT\t[Optional] Build a snapshot, default is 'false'." + 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:s:o:a:" arg; do + case $arg in + h) + usage + exit 1 + ;; + v) + VERSION=$OPTARG + ;; + s) + SNAPSHOT=$OPTARG + ;; + o) + OUTPUT=$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 + +[[ "$SNAPSHOT" == "true" ]] && VERSION=$VERSION-SNAPSHOT +[ -z "$OUTPUT" ] && OUTPUT=artifacts + +mkdir -p $OUTPUT/plugins + +./gradlew assemble --no-daemon --refresh-dependencies -DskipTests=true -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT + +zipPath=$(find . -path \*build/distributions/*.zip) +distributions="$(dirname "${zipPath}")" + +echo "COPY ${distributions}/*.zip" +cp ${distributions}/*.zip ./$OUTPUT/plugins + +./gradlew publishToMavenLocal -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT \ No newline at end of file