Merge branch '21521-aptly-flock'
[arvados-dev.git] / jenkins / upload_packages_testing_to_stable.sh
index 66ecd9747036edd9eb2c43a6005cab933ffeaa37..4cf3737f79a4c2409a4910543ed867c6c46d0a62 100755 (executable)
@@ -3,11 +3,9 @@
 #
 # SPDX-License-Identifier: AGPL-3.0
 
-# This script publishes packages from our dev repo to the prod repo (#11572)
-# Parameters: list of packages, space separated, to move from *-testing to *
-# under /var/lib/freight/apt/ in host public.curoverse.com
-
-set -x
+# This script publishes packages from our testing repo to the prod repo
+# (#11572)
+# Parameters: list of packages, space separated, to copy from *-testing to *
 
 APT_REPO_SERVER="apt.arvados.org"
 RPM_REPO_SERVER="rpm.arvados.org"
@@ -24,40 +22,57 @@ if [ -z "${PACKAGES_TO_PUBLISH}" ]; then
 fi
 if [ -z "${LSB_DISTRIB_CODENAMES}" ]; then
   echo "You must provide a space-separated list of LSB distribution codenames to which you want to publish to, ie."
-  echo "* Debian: jessie, xenial, stretch, etc."
-  echo "* Centos: centos7 (the only one currently supported.)"
+  echo "* Debian/Ubuntu: buster, bullseye, focal"
+  echo "* Redhat: centos7 rocky8"
   exit 255
 fi
 
+# Only numbered package versions are supposed to go into the stable repositories
+TMP=$(echo "$PACKAGES_TO_PUBLISH" | sed 's/versions://g;')
+VERPATTERN='[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?-[0-9]+'
+VALIDATED_PACKAGES_TO_PUBLISH=`echo "$TMP" | sed -nE '/^.*: '"$VERPATTERN"'$/p'`
+
+if [[ "$TMP" != "$VALIDATED_PACKAGES_TO_PUBLISH" ]]; then
+  echo "The list of packages has invalid syntax. each line must be of the format:"
+  echo
+  echo "packagename: $VERPATTERN"
+  echo
+  exit 253
+fi
+
 # Sanitize the vars in a way suitable to be used by the remote 'publish_packages.sh' script
 # Just to make copying a single line, and not having to loop over it
-PACKAGES_LIST=$(echo ${PACKAGES_TO_PUBLISH}\* | sed 's/[a-z-]*-gem: [0-9\.]*//g; s/versions://g; s/\([0-9]\)[$, ]/\1* /g; s/[[:blank:]]\+/,/g; s/^,//g; s/:,/*/g')
+PACKAGES_LIST=$(echo ${PACKAGES_TO_PUBLISH} | sed 's/versions://g; s/\([a-z-]*\):[[:blank:]]*\([0-9.-]*\)/\1:\2,/g; s/[[:blank:]]//g; s/,$//g;')
 
 DISTROS=$(echo "${LSB_DISTRIB_CODENAMES}"|sed s/[[:space:]]/,/g |tr '[:upper:]' '[:lower:]')
 
-if ( echo ${LSB_DISTRIB_CODENAMES} |grep -q centos ); then
+if ( echo ${LSB_DISTRIB_CODENAMES} |grep -q -E '(centos|rocky)' ); then
   REPO_SERVER=${RPM_REPO_SERVER}
 else
   REPO_SERVER=${APT_REPO_SERVER}
 fi
 
-REMOTE_CMD="/usr/local/bin/testing_to_stable_publish_packages.sh --distros ${DISTROS} --packages ${PACKAGES_LIST}"
+# Make sure jenkins scripts are up to date
+ssh -t \
+    -l jenkinsapt \
+    -p $SSH_PORT \
+    -o "StrictHostKeyChecking no" \
+    -o "ConnectTimeout 5" \
+    ${REPO_SERVER} \
+    "cd ~/arvados-dev && git fetch -a && git reset --hard origin/main"
 
 # Now we execute it remotely
 TMP_FILE=`mktemp`
 
+REMOTE_CMD="~/arvados-dev/jenkins/testing_to_stable_publish_packages.sh --distros ${DISTROS} --packages ${PACKAGES_LIST}"
+
 ssh -t \
     -l jenkinsapt \
     -p $SSH_PORT \
     -o "StrictHostKeyChecking no" \
     -o "ConnectTimeout 5" \
     ${REPO_SERVER} \
-    "${REMOTE_CMD}" | tee ${TMP_FILE}
+    "${REMOTE_CMD}"
 ECODE=$?
 
-grep -q "FAILED TO PUBLISH" ${TMP_FILE}
-if [ $? -eq 0 ]; then
-  ECODE=1
-fi
-rm -f ${TMP_FILE}
 exit ${ECODE}