21855: Update RPM filesystem path
[arvados-dev.git] / jenkins / run_upload_packages.py
index 3a51e408f8aeb5fad78d230b187db549f1509c7e..fa008f4a0f8a77cccb190c0d72dd399526cf334e 100755 (executable)
@@ -11,8 +11,8 @@ import glob
 import locale
 import logging
 import os
-import pipes
 import re
+import shlex
 import shutil
 import subprocess
 import sys
@@ -117,40 +117,15 @@ class PackageSuite:
 
 class PythonPackageSuite(PackageSuite):
     LOGGER_PART = 'python'
-    REUPLOAD_REGEXPS = [
-        re.compile(
-            r'^error: Upload failed \(400\): A file named "[^"]+" already exists\b'),
-        re.compile(
-            r'^error: Upload failed \(400\): File already exists\b'),
-        re.compile(
-            r'^error: Upload failed \(400\): Only one sdist may be uploaded per release\b'),
-    ]
-
-    def __init__(self, glob_root, rel_globs):
-        super().__init__(glob_root, rel_globs)
-        self.seen_packages = set()
 
     def upload_file(self, path):
-        src_dir = os.path.dirname(os.path.dirname(path))
-        if src_dir in self.seen_packages:
-            return
-        self.seen_packages.add(src_dir)
-        # We also must run `sdist` before `upload`: `upload` uploads any
-        # distributions previously generated in the command.  It doesn't
-        # know how to upload distributions already on disk.  We write the
-        # result to a dedicated directory to avoid interfering with our
-        # timestamp tracking.
-        cmd = ['python3', 'setup.py']
-        if not self.logger.isEnabledFor(logging.INFO):
-            cmd.append('--quiet')
-        cmd.extend(['bdist_wheel', '--dist-dir', '.upload_dist'])
-        cmd.extend(['sdist', '--dist-dir', '.upload_dist'])
-        cmd.extend(['upload'])
-        upload_returncode, repushed = run_and_grep(
-            cmd, 'stderr', *self.REUPLOAD_REGEXPS, cwd=src_dir)
-        if (upload_returncode != 0) and not repushed:
-            raise subprocess.CalledProcessError(upload_returncode, cmd)
-        shutil.rmtree(os.path.join(src_dir, '.upload_dist'))
+        subprocess.run([
+            'twine', 'upload',
+            '--disable-progress-bar',
+            '--non-interactive',
+            '--skip-existing',
+            path,
+        ], stdin=subprocess.DEVNULL, check=True)
 
 
 class GemPackageSuite(PackageSuite):
@@ -191,8 +166,8 @@ class DistroPackageSuite(PackageSuite):
         # self.__class__.__name__ provides $0 for the script, which makes a
         # nicer message if there's an error.
         subprocess.check_call(self._build_cmd(
-                'ssh', self.ssh_host, 'bash', '-ec', pipes.quote(script),
-                self.__class__.__name__, *(pipes.quote(s) for s in args)))
+                'ssh', self.ssh_host, 'bash', '-ec', shlex.quote(script),
+                self.__class__.__name__, *(shlex.quote(s) for s in args)))
 
     def upload_files(self, paths):
         dest_dir = os.path.join(self.REMOTE_DEST_DIR, self.target)
@@ -208,6 +183,12 @@ class DebianPackageSuite(DistroPackageSuite):
 set -e
 cd "$1"; shift
 DISTNAME=$1; shift
+# aptly implements its own locking, but its wait strategy as of April 2024 is
+# not patient enough to accommodate multiple simultaneous uploads.
+APTLY_LOCK="${XDG_RUNTIME_DIR:-/tmp}/aptly-upload.lock"
+aptly() {
+  flock --wait=300 "$APTLY_LOCK" aptly "$@"
+}
 for package in "$@"; do
   if aptly repo search "$DISTNAME" "${package%.deb}" >/dev/null 2>&1; then
     echo "Not adding $package, it is already present in repo $DISTNAME"
@@ -228,6 +209,7 @@ aptly publish update "$DISTNAME" filesystem:"${DISTNAME%-*}":
             'ubuntu1804': 'bionic-'+repo,
             'ubuntu2004': 'focal-'+repo,
             'ubuntu2204': 'jammy-'+repo,
+            'ubuntu2404': 'noble-'+repo,
             }
 
     def post_uploads(self, paths):
@@ -249,8 +231,8 @@ createrepo_c -c ~/.createrepo-cache --update "$REPODIR"
     def __init__(self, glob_root, rel_globs, target, ssh_host, ssh_opts, repo):
         super().__init__(glob_root, rel_globs, target, ssh_host, ssh_opts)
         self.TARGET_REPODIRS = {
-            'centos7': 'CentOS/7/%s/x86_64/' % repo,
-            'rocky8': 'CentOS/8/%s/x86_64/' % repo,
+            'centos7': 'RHEL/7/%s/x86_64/' % repo,
+            'rocky8': 'RHEL/8/%s/x86_64/' % repo,
         }
 
     def post_uploads(self, paths):
@@ -265,10 +247,14 @@ def _define_suite(suite_class, *rel_globs, **kwargs):
 
 PACKAGE_SUITES = {
     'python': _define_suite(PythonPackageSuite,
-                            'sdk/python/dist/*.tar.gz',
                             'sdk/cwl/dist/*.tar.gz',
+                            'sdk/cwl/dist/*.whl',
+                            'sdk/python/dist/*.tar.gz',
+                            'sdk/python/dist/*.whl',
                             'services/fuse/dist/*.tar.gz',
+                            'services/fuse/dist/*.whl',
                             'tools/crunchstat-summary/dist/*.tar.gz',
+                            'tools/crunchstat-summary/dist/*.whl',
                         ),
     'gems': _define_suite(GemPackageSuite,
                           'sdk/ruby/*.gem',
@@ -307,7 +293,7 @@ def parse_arguments(arguments):
 
     for target in [
             'debian10', 'debian11', 'debian12',
-            'ubuntu1804', 'ubuntu2004', 'ubuntu2204',
+            'ubuntu1804', 'ubuntu2004', 'ubuntu2204', 'ubuntu2404',
     ]:
         PACKAGE_SUITES[target] = _define_suite(
             DebianPackageSuite, os.path.join('packages', target, '*.deb'),