From 30dbe9bd02c3be079b63407ba6b0c7be14b8ab54 Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Fri, 12 May 2023 11:38:17 -0700 Subject: [PATCH] Add maven publish for 1.3.x release (#3507) Signed-off-by: Prudhvi Godithi --- .codecov.yml | 8 +- .../maven-publish-1.3.x.jenkinsfile | 93 ++++++++++++ publish/publish-snapshot.sh | 141 ++++++++++++++++++ 3 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 jenkins/opensearch/maven-publish-1.3.x.jenkinsfile create mode 100755 publish/publish-snapshot.sh diff --git a/.codecov.yml b/.codecov.yml index 18f1336234..2217ce09f0 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -3,9 +3,11 @@ codecov: require_ci_to_pass: yes coverage: - precision: 2 - round: down - range: '80...100' + status: + project: + default: + target: 80% # the required coverage value + threshold: 2% # the leniency in hitting the target ignore: - '**/tests/*.py' diff --git a/jenkins/opensearch/maven-publish-1.3.x.jenkinsfile b/jenkins/opensearch/maven-publish-1.3.x.jenkinsfile new file mode 100644 index 0000000000..7f299f3da1 --- /dev/null +++ b/jenkins/opensearch/maven-publish-1.3.x.jenkinsfile @@ -0,0 +1,93 @@ +lib = library(identifier: 'jenkins@1.5.4', retriever: modernSCM([ + $class: 'GitSCMSource', + remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git', +])) + +pipeline { + options { + timeout(time: 2, unit: 'HOURS') + } + agent none + environment { + AGENT_X64 = 'Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host' + } + triggers { + parameterizedCron ''' + H/60 * * * * %INPUT_MANIFEST=1.3.10/opensearch-1.3.10.yml + ''' + } + parameters { + string( + name: 'COMPONENT_NAME', + description: 'If this field contains one or more component names (e.g. OpenSearch common-utils ...), will build with "--component ...", else build everything in the INPUT_MANIFEST.', + trim: true + ) + string( + name: 'INPUT_MANIFEST', + description: 'Input manifest under the manifests folder, e.g. 2.0.0/opensearch-2.0.0.yml.', + trim: true + ) + } + stages { + stage('dockerAgent-setup') { + agent { + docker { + label AGENT_X64 + image 'docker/library/alpine:3' + registryUrl 'https://public.ecr.aws/' + alwaysPull true + } + } + steps { + script { + echo("Detect Docker Images and Related Parameters") + dockerAgent = detectDockerAgent() + currentBuild.description = INPUT_MANIFEST + } + } + } + stage('publish-maven-snaphots') { + environment { + SNAPSHOT_REPO_URL = "https://aws.oss.sonatype.org/content/repositories/snapshots/" + } + agent { + docker { + label AGENT_X64 + image dockerAgent.image + args dockerAgent.args + alwaysPull true + } + } + steps { + script { + buildManifest( + componentName: "${COMPONENT_NAME}", + inputManifest: "manifests/${INPUT_MANIFEST}", + platform: 'linux', + architecture: 'x64', + distribution: 'tar', + snapshot: true + ) + + String mavenPath = "$WORKSPACE/tar/builds/opensearch/maven" + + if (fileExists(mavenPath)) { + withCredentials([ + string(credentialsId: 'maven-snapshots-username', variable: 'SONATYPE_USERNAME'), + string(credentialsId: 'maven-snapshots-password', variable: 'SONATYPE_PASSWORD') + ]) { + sh("$WORKSPACE/publish/publish-snapshot.sh ${mavenPath}") + } + } else { + echo "Skipping publishing snapshots, ${mavenPath} does not exist." + } + } + } + post { + always { + postCleanup() + } + } + } + } +} diff --git a/publish/publish-snapshot.sh b/publish/publish-snapshot.sh new file mode 100755 index 0000000000..ebdf959ba4 --- /dev/null +++ b/publish/publish-snapshot.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +# Copyright OpenSearch Contributors +###### Information ############################################################################ +# 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. +# +# Name: publish-snapshot.sh +# Language: Shell +# +# About: Deploy opensearch artifacts to a sonatype snapshot repository. +# This script will search POM files under the passed in directory and publish artifacts to +# a snapshot repository using the mvn deploy plugin. +# +# Usage: ./publish-snapshot.sh +# +############################################################################################### +set -e + +[ -z "${1:-}" ] && { + usage +} + +usage() { + echo "usage: $0 [-h] [dir]" + echo " dir parent directory of artifacts to be published to org/opensearch namespace." + echo " example: dir = ~/.m2/repository/org/opensearch where dir contains artifacts of a path:" + echo " /maven/reindex-client/1.0.0-SNAPSHOT/reindex-client-1.0.0-SNAPSHOT.jar" + echo " -h display help" + echo "Required environment variables:" + echo "SONATYPE_USERNAME - username with publish rights to a sonatype repository" + echo "SONATYPE_PASSWORD - password for sonatype" + echo "SNAPSHOT_REPO_URL - repository URL ex. http://localhost:8081/nexus/content/repositories/snapshots/" + exit 1 +} + +while getopts ":h" option; do + case $option in + h) + usage + ;; + \?) + echo "Invalid option -$OPTARG" >&2 + usage + ;; + esac +done + +[ -z "${SONATYPE_USERNAME}" ] && { + echo "SONATYPE_USERNAME is required" + exit 1 +} + +[ -z "${SONATYPE_PASSWORD}" ] && { + echo "SONATYPE_PASSWORD is required" + exit 1 +} + +[ -z "${SNAPSHOT_REPO_URL}" ] && { + echo "REPO_URL is required" + exit 1 +} + +if [ ! -d "$1" ]; then + echo "Invalid directory $1 does not exist" + usage +fi + +create_maven_settings() { + # Create a settings.xml file with the user+password for maven + mvn_settings="${workdir}/mvn-settings.xml" + cat >${mvn_settings} <<-EOF + + + + + nexus + ${SONATYPE_USERNAME} + ${SONATYPE_PASSWORD} + + + +EOF +} + +url="${SNAPSHOT_REPO_URL}" +workdir=$(mktemp -d) + +function cleanup() { + rm -rf "${workdir}" +} + +trap cleanup TERM INT EXIT + +create_maven_settings + +cd "$1" + +echo "searching for poms under $PWD" + +pomFiles="$(find "." -name '*.pom')" +if [ -z "${pomFiles}" ]; then + echo "No artifacts found under $PWD" + exit 1 +fi + +for pom in ${pomFiles}; do + pom_dir="$(dirname "${pom}")" + for FILE in "${pom_dir}"/*; do + # The POM is deployed with the artifact in a single deploy-file command, we can skip over it + if [[ $FILE != $pom ]] && + [[ $FILE != *"test-fixtures"* ]] && # This is a hack to ensure the OpenSearch build-tools test fixture jar is not uploaded instead of the actual build-tools jar. + [[ $FILE != *"javadoc"* ]] && + [[ $FILE != *"sources"* ]]; then + extension="${FILE##*.}" + case $extension in jar | war | zip) + echo "Uploading: ${FILE} with ${pom} to ${url}" + mvn --settings="${mvn_settings}" deploy:deploy-file \ + -DgeneratePom=false \ + -DrepositoryId=nexus \ + -Durl="${SNAPSHOT_REPO_URL}" \ + -DpomFile="${pom}" \ + -Dfile="${FILE}" || echo "Failed to upload ${FILE}" + ;; + *) echo "Skipping upload for ${FILE}" ;; + esac + fi + done + + echo "Finished uploading ${pom_dir}" +done + +echo "===========================================" +echo "Done." +echo "==========================================="