Merge "Update Ansible playbooks to new names"
[releng/builder.git] / jjb / packaging / build-rpm.sh
index 6c76fd958551fb5c262aab4de5769749f4b77927..7613e521916e3843a471217ba52e5a48c59be033 100644 (file)
@@ -14,17 +14,38 @@ PYTHON="rpm_build/bin/python"
 $PYTHON -m pip install --upgrade pip
 $PYTHON -m pip install -r "$WORKSPACE/packaging/packages/requirements.txt"
 
-# Make a URL for the tarball artifact from DOWNLOAD_URL (a zip)
-# shellcheck disable=SC2154
-download_url="${{DOWNLOAD_URL//zip/tar.gz}}"
+# Packaging logic needs a tarball, but can repackage a zip into tar.gz
+# if needed. All builds except multipatch-test publish both a tar.gz and zip.
+# Autorelease passes DOWNLOAD_URL to zip, others typically use tar.gz.
+# If URL is to zip, check if there's a tar.gz available to avoid repackaging.
+if [[ $DOWNLOAD_URL = *.zip ]]; then
+  # shellcheck disable=SC2154
+  candidate_tarball_url="${DOWNLOAD_URL//zip/tar.gz}"
+  # shellcheck disable=SC2154
+  url_status=$(curl --silent --head --location --output /dev/null --write-out \
+    '%{http_code}' "$candidate_tarball_url")
+  if [[ $url_status = 2* ]]; then
+    DOWNLOAD_URL="$candidate_tarball_url"
+  fi
+fi
 
 # Build release specified by build params
-"$WORKSPACE/packaging/packages/build.py" --rpm --download_url "$download_url" \
-                                    --changelog_name "$CHANGELOG_NAME" \
-                                    --changelog_email "$CHANGELOG_EMAIL"
+"$WORKSPACE/packaging/packages/build.py" --rpm \
+                                         --changelog_name "$CHANGELOG_NAME" \
+                                         --changelog_email "$CHANGELOG_EMAIL" \
+                                         direct \
+                                         --download_url "$DOWNLOAD_URL"
 
-# Move RPMs (SRPM and noarch) to dir of files that will be uploaded to Nexus
-UPLOAD_FILES_PATH="$WORKSPACE/upload_files"
-mkdir -p "$UPLOAD_FILES_PATH"
-mv "/home/$USER/rpmbuild/RPMS/noarch/"*.rpm "$_"
-mv "/home/$USER/rpmbuild/SRPMS/"*.rpm "$_"
+# Publish RPMs to Nexus if in production Jenkins, else host on sandbox Jenkins
+if [ "$SILO" == "sandbox" ]; then
+  echo "Not uploading RPMs to Nexus because running in sandbox"
+elif  [ "$SILO" == "releng" ]; then
+  # Move RPMs (SRPM and noarch) to dir of files that will be uploaded to Nexus
+  UPLOAD_FILES_PATH="$WORKSPACE/upload_files"
+  mkdir -p "$UPLOAD_FILES_PATH"
+  cp "/home/$USER/rpmbuild/RPMS/noarch/"*.rpm "$_"
+  cp "/home/$USER/rpmbuild/SRPMS/"*.rpm "$_"
+else
+  echo "Unknown Jenkins silo: $SILO"
+  exit 1
+fi