Skip to content

Commit

Permalink
NuGet release script improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhill committed Sep 30, 2020
1 parent 8f8c402 commit dbafbb7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packaging/nuget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
8 changes: 6 additions & 2 deletions packaging/nuget/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
32 changes: 28 additions & 4 deletions packaging/nuget/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import sys
import argparse
import time
import packaging


Expand All @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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)

0 comments on commit dbafbb7

Please sign in to comment.