diff --git a/packaging/nuget/README.md b/packaging/nuget/README.md index 0ca2af9903..0d6cca928b 100644 --- a/packaging/nuget/README.md +++ b/packaging/nuget/README.md @@ -48,7 +48,7 @@ The finalized nuget package maybe uploaded manually to NuGet.org 7. If you trust this process you can have release.py upload the package automatically to NuGet after building it: - $ ./release.py --upload "$(cat your-nuget-api.key)" v0.11.0 + $ ./release.py --retries 100 --upload your-nuget-api.key v0.11.0 diff --git a/packaging/nuget/packaging.py b/packaging/nuget/packaging.py index 8dda85be27..cc2de31c30 100755 --- a/packaging/nuget/packaging.py +++ b/packaging/nuget/packaging.py @@ -53,6 +53,10 @@ # librdkafka/p-librdkafka__bld-travis__plat-linux__arch-x64__tag-v0.0.62__sha-d051b2c19eb0c118991cd8bc5cf86d8e5e446cde__bid-1562.1/librdkafka.tar.gz +class MissingArtifactError(Exception): + pass + + s3_bucket = 'librdkafka-ci-packages' dry_run = False @@ -400,7 +404,7 @@ def build (self, buildtype): break if artifact is None: - raise Exception('unable to find artifact with tags %s matching "%s"' % (str(attributes), fname_glob)) + raise MissingArtifactError('unable to find artifact with tags %s matching "%s"' % (str(attributes), fname_glob)) outf = os.path.join(self.stpath, m[2]) member = m[1] @@ -538,7 +542,7 @@ def build (self, buildtype): break if artifact is None: - raise Exception('unable to find artifact with tags %s matching "%s"' % (str(attributes), fname_glob)) + raise MissingArtifactError('unable to find artifact with tags %s matching "%s"' % (str(attributes), fname_glob)) outf = os.path.join(self.stpath, m[2]) member = m[1] diff --git a/packaging/nuget/release.py b/packaging/nuget/release.py index 302e5af7bb..a5b648a0db 100755 --- a/packaging/nuget/release.py +++ b/packaging/nuget/release.py @@ -9,6 +9,7 @@ import os import sys import argparse +import time import packaging @@ -27,12 +28,15 @@ parser.add_argument("--no-cleanup", help="Don't clean up temporary folders", action="store_true") parser.add_argument("--sha", help="Also match on this git sha1", default=None) parser.add_argument("--nuget-version", help="The nuget package version (defaults to same as tag)", default=None) - parser.add_argument("--upload", help="Upload package to after building, using provided NuGet API key", default=None, type=str) + parser.add_argument("--upload", help="Upload package to after building, using provided NuGet API key (either file or the key itself)", default=None, + type=str) parser.add_argument("--class", help="Packaging class (see packaging.py)", default="NugetPackage", dest="pkgclass") + parser.add_argument("--retries", help="Number of retries to collect artifacts", default=0, type=int) parser.add_argument("tag", help="Git tag to collect") args = parser.parse_args() dry_run = args.dry_run + retries = args.retries if not args.directory: args.directory = 'dl-%s' % args.tag @@ -76,8 +80,22 @@ print('Building packages:') - p = pkgclass(package_version, arts) - pkgfile = p.build(buildtype='release') + while True: + try: + p = pkgclass(package_version, arts) + pkgfile = p.build(buildtype='release') + break + except packaging.MissingArtifactError as e: + if retries <= 0: + if not args.no_cleanup: + p.cleanup() + raise e + + p.cleanup() + retries -= 1 + print(e) + print('Retrying in 30 seconds') + time.sleep(30) if not args.no_cleanup: p.cleanup() @@ -93,7 +111,13 @@ print('Created package: %s' % pkgfile) if args.upload is not None: + if os.path.isfile(args.upload): + with open(args.upload, 'r') as f: + nuget_key = f.read().replace('\n', '') + else: + nuget_key = args.upload + print('Uploading %s to NuGet' % pkgfile) - r = os.system("./push-to-nuget.sh '%s' %s" % (args.upload, pkgfile)) + r = os.system("./push-to-nuget.sh '%s' %s" % (nuget_key, pkgfile)) assert int(r) == 0, "NuGet upload failed with exit code {}, see previous errors".format(r) print('%s successfully uploaded to NuGet' % pkgfile)