Add support for artifact releases 47/66647/6
authorJessica Wagantall <jwagantall@linuxfoundation.org>
Wed, 20 Jan 2021 21:10:01 +0000 (13:10 -0800)
committerJessica Wagantall <jwagantall@linuxfoundation.org>
Tue, 2 Mar 2021 18:07:58 +0000 (10:07 -0800)
Currently Dent is the only customer for artifact
releases where they need a particular binary to be
pulled from Snapshots and pushed manually into Releases.

These are artifacts built using make.

Issue: RELENG-3376
Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Change-Id: I5a8ec8e2906757b1700505ad10dd2ba8ac844f9a

releasenotes/notes/artifacts-self-releases-support-0448d5269ac8f30f.yaml [new file with mode: 0644]
shell/release-job.sh

diff --git a/releasenotes/notes/artifacts-self-releases-support-0448d5269ac8f30f.yaml b/releasenotes/notes/artifacts-self-releases-support-0448d5269ac8f30f.yaml
new file mode 100644 (file)
index 0000000..3f26ae2
--- /dev/null
@@ -0,0 +1,7 @@
+---
+features:
+  - |
+    Add artifact distribution type for self releases.
+    This support allows customers to specify a particular name
+    and path of an artifact in Nexus which will be downloaded locally,
+    re-tagged and posted into the releases repository of the matching repo.
index 9ff6799..66bed66 100644 (file)
@@ -83,7 +83,7 @@ set_variables_common(){
     # Displaying Release Information (Common variables)
     printf "\t%-30s\n" RELEASE_ENVIRONMENT_INFO:
     printf "\t%-30s %s\n" RELEASE_FILE: "$release_file"
-    printf "\t%-30s %s\n" LOGS_SERVER: "$LOGS_SERVER"
+    printf "\t%-30s %s\n" LOGS_SERVER: "${LOGS_SERVER:-None}"
     printf "\t%-30s %s\n" CDN_URL: "${CDN_URL:-None}"
     printf "\t%-30s %s\n" NEXUS_PATH: "$NEXUS_PATH"
     printf "\t%-30s %s\n" JENKINS_HOSTNAME: "$JENKINS_HOSTNAME"
@@ -217,6 +217,28 @@ set_variables_packagecloud(){
      printf "\t%-30s %s\n" GIT_TAG: "$GIT_TAG"
 }
 
+set_variables_artifact(){
+     echo "INFO: Setting artifact variables"
+     if [[ -z ${VERSION:-} ]]; then
+         VERSION=$(yq -r ".version" "$release_file")
+     fi
+     if [[ -z ${GIT_TAG:-} ]]; then
+         if grep -q "git_tag" $release_file ; then
+             GIT_TAG=$(yq -r ".git_tag" "$release_file")
+         else
+             GIT_TAG="$VERSION"
+         fi
+     fi
+     if [[ -z ${REF:-} ]]; then
+         REF=$(yq -r ".ref" "$release_file")
+     fi
+
+     printf "\t%-30s\n" RELEASE_ARTIFACT_INFO:
+     printf "\t%-30s %s\n" GERRIT_REF_TO_TAG: "$REF"
+     printf "\t%-30s %s\n" VERSION: "$VERSION"
+     printf "\t%-30s %s\n" GIT_TAG: "$GIT_TAG"
+}
+
 verify_schema(){
     echo "INFO: Verifying $release_file against schema $release_schema"
     lftools schema verify "$release_file" "$release_schema"
@@ -494,18 +516,64 @@ packagecloud_promote(){
     tag-git-repo
 }
 
+artifact_release_file(){
+    echo "INFO: Processing artifact release"
+    mkdir artifacts
+    ORG=$(echo "$NEXUS_URL" | awk -F'.' '{print $2}')
+
+    for namequoted in $(yq '.artifacts[].name' $release_file); do
+        pathquoted=$(yq ".artifacts[] |select(.name==$namequoted) |.path" $release_file)
+
+        #Remove extra yaml quotes
+        name="${namequoted#\"}"
+        name="${name%\"}"
+        path="${pathquoted#\"}"
+        path="${path%\"}"
+
+        echo "$name"
+        echo "$path"
+        echo "INFO: Merge will post artifact: $name"
+        # Attempt to pull from releases to see if the artifact has been released.
+        if "${NEXUS_URL}"/content/repositories/releases/org/"${ORG}"/"${VERSION}"/"$name"; then
+            echo "INFO: $name is already released as version:$VERSION, Continuing..."
+        else
+            echo "INFO: $name not found in releases, release will be prepared. Continuing..."
+            wget "${path}"/"${name}" -o artifacts/"${name}"
+            if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
+                #lftools sign sigul artifacts
+                curl -v -u <NEXUSUSER>:<NEXUSPASS> --upload-file "${NEXUS_URL}"/content/repositories/releases/org/"${ORG}"/"${VERSION}"/"${name}" \;
+            fi
+            echo "#########################"
+        fi
+    done
+}
+
 ##############################  End Function Declarations  ################################
 
 # Set common environment variables
 set_variables_common
 
 # Determine the type of release:
+#   - artifact, release-artifact-schema.yaml
 #   - container, release-container-schema.yaml
 #   - maven, release-schema.yaml
 #   - pypi,  release-pypi-schema.yaml
+#   - packagecloud, release-packagecloud-schema.yaml
 
 case $DISTRIBUTION_TYPE in
 
+    artifact)
+        if $USE_RELEASE_FILE ; then
+            release_schema="release-artifact-schema.yaml"
+            echo "INFO: Fetching schema $release_schema"
+            wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/${release_schema}
+            verify_schema
+        fi
+        set_variables_artifact
+        verify_version
+        artifact_release_file
+        ;;
+
     maven)
         if $USE_RELEASE_FILE ; then
             release_schema="release-schema.yaml"