Skip to content

Commit

Permalink
Uses custom plugin to publish zips to maven (#638)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <joshuali925@gmail.com>
  • Loading branch information
joshuali925 authored Jun 17, 2022
1 parent d81ef73 commit 127b662
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sql-test-and-build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: ./gradlew build assemble

- name: Run backward compatibility tests
run: ./bwctest.sh
run: ./scripts/bwctest.sh

- name: Create Artifact Path
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ gen
*/__pycache__
*.iml
.DS_Store

/artifacts/
25 changes: 25 additions & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ plugins {
id 'opensearch.opensearchplugin'
}

apply plugin: 'opensearch.pluginzip'

ext {
projectSubstitutions = [:]
licenseFile = rootProject.file('LICENSE.TXT')
Expand All @@ -46,6 +48,29 @@ opensearchplugin {
noticeFile rootProject.file("NOTICE")
}

publishing {
publications {
pluginZip(MavenPublication) { publication ->
pom {
name = 'opensearch-sql'
description = 'OpenSearch SQL'
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/sql'
}
}
}
}
}
}

javadoc.enabled = false
test.enabled = false
loggerUsageCheck.enabled = false
Expand Down
82 changes: 82 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/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 "-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

./gradlew publishPluginZipPublicationToZipStagingRepository -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
2 changes: 1 addition & 1 deletion bwctest.sh → scripts/bwctest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ done
function setup_bwc_artifact() {
# This gets opensearch version from build.gradle (e.g. 1.2.0-SNAPSHOT),
# then converts to plugin version by appending ".0" (e.g. 1.2.0.0-SNAPSHOT),
# assuming one line in build.gradle is 'opensearch_version= System.getProperty("opensearch.version", "<opensearch_version>")'.
# assuming one line in build.gradle is 'opensearch_version = System.getProperty("opensearch.version", "<opensearch_version>")'.
plugin_version=$(grep 'opensearch_version = System.getProperty' build.gradle | \
grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+[^"]*' | sed -e 's/\(.*\)\(\.[0-9]\)/\1\2.0/')
plugin_artifact="./plugin/build/distributions/opensearch-sql-$plugin_version.zip"
Expand Down

0 comments on commit 127b662

Please sign in to comment.