Add a snapshot mode to the deploy-nexus command 21/7221/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 1 Nov 2017 18:28:03 +0000 (14:28 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 1 Nov 2017 18:39:50 +0000 (14:39 -0400)
This is necessary for RELENG-61 in order to allow pushing
maven-metadata.xml files which in the case of release jobs should not be
allowed. So add an option to the deploy-nexus command to allow an
exception for snapshot artifacts.

Issue: RELENG-173
Change-Id: I6f086bd0987502c5a967ab0b6f313ac405ceabc5
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
lftools/cli/deploy.py
shell/deploy

index 209e963..aad8eae 100644 (file)
@@ -149,8 +149,10 @@ def maven_file(
 @click.command()
 @click.argument('nexus-repo-url', envvar='NEXUS_REPO_URL')
 @click.argument('deploy-dir', envvar='DEPLOY_DIR')
+@click.option('-s', '--snapshot', is_flag=True, default=False,
+              help='Deploy a snapshot repo.')
 @click.pass_context
-def nexus(ctx, nexus_repo_url, deploy_dir):
+def nexus(ctx, nexus_repo_url, deploy_dir, snapshot):
     """Deploy a Maven repository to a specified Nexus repository.
 
     This script takes a local Maven repository and deploys it to a Nexus
@@ -160,7 +162,14 @@ def nexus(ctx, nexus_repo_url, deploy_dir):
 
         https://nexus.example.org/content/repositories/release
     """
-    status = subprocess.call(['deploy', 'nexus', nexus_repo_url, deploy_dir])
+    params = ['deploy', 'nexus']
+
+    if snapshot:
+        params.extend(["-s"])
+
+    params.extend([nexus_repo_url, deploy_dir])
+
+    status = subprocess.call(params)
     sys.exit(status)
 
 
index 4fe12df..e704d35 100755 (executable)
@@ -508,6 +508,13 @@ deploy_maven_file () {
     fi
 }
 
+deploy_nexus_usage() {
+    echo "Usage: deploy nexus <nexus_repo_url> <deploy_dir>"
+    echo
+    echo "Options:"
+    echo "    -s  # Enable snapshot mode for pushing snapshot artifacts to Nexus."
+}
+
 deploy_nexus() {
     # Deploy Maven artifacts to Nexus using curl
     #
@@ -520,22 +527,49 @@ deploy_nexus() {
     # One purpose of this is so that we can get around the problematic
     # deploy-at-end configuration with upstream Maven.
     # https://issues.apache.org/jira/browse/MDEPLOY-193
+    local snapshot="false"
+
+    while getopts s o; do
+      case "$o" in
+        h)
+            deploy_nexus_usage
+            exit 0
+            ;;
+
+        s)
+            local snapshot="true"
+            ;;
+
+        [?])
+            deploy_nexus_usage
+            exit 1
+            ;;
+      esac
+    done
+    shift $((OPTIND-1))
 
     local nexus_repo_url="${1%/}"
     local deploy_dir="$2"
 
     if [ -z "$2" ]; then
         echo "Missing required arguments."
-        echo "Usage: deploy nexus <nexus_repo_url> <deploy_dir>"
+        deploy_nexus_usage
         exit 1
     fi
 
     pushd "$deploy_dir"
-    file_list=($(find . -type f \
-                ! -name "maven-metadata*" \
-                ! -name _remote.repositories \
-                ! -name resolver-status.properties \
-                | cut -c 3-))
+    if [ "$snapshot" == "true" ]; then
+        file_list=($(find . -type f \
+                    ! -name _remote.repositories \
+                    ! -name resolver-status.properties \
+                    | cut -c 3-))
+    else
+        file_list=($(find . -type f \
+                    ! -name "maven-metadata*" \
+                    ! -name _remote.repositories \
+                    ! -name resolver-status.properties \
+                    | cut -c 3-))
+    fi
 
     if hash parallel 2>/dev/null; then
         export -f upload_to_nexus