From bbd603c55a12b59c1a0273f38cdac39dee47128e Mon Sep 17 00:00:00 2001 From: Marc Handalian Date: Fri, 10 Sep 2021 11:44:26 -0700 Subject: [PATCH] Fix publish-snapshot.sh script to only push artifacts ending with -SNAPSHOT.jar|war|zip. Signed-off-by: Marc Handalian --- publish/publish-snapshot.sh | 67 ++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/publish/publish-snapshot.sh b/publish/publish-snapshot.sh index f60c116aad..65ca67bd62 100755 --- a/publish/publish-snapshot.sh +++ b/publish/publish-snapshot.sh @@ -24,25 +24,26 @@ set -e } 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 + 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 + h) + usage ;; - \?) echo "Invalid option -$OPTARG" >&2 - usage + \?) + echo "Invalid option -$OPTARG" >&2 + usage ;; esac done @@ -68,9 +69,9 @@ if [ ! -d "$1" ]; then 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 + # Create a settings.xml file with the user+password for maven + mvn_settings="${workdir}/mvn-settings.xml" + cat >${mvn_settings} <<-EOF and its pom. + if [[ $FILE == *SNAPSHOT.${extension} ]]; then + 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}" + else + echo "Skipping upload of additional artifact: ${FILE}" + fi + ;; + *) echo "Skipping upload for ${FILE}" ;; esac fi done