Skip to content

Commit dbafbb7

Browse files
committed
NuGet release script improvements
1 parent 8f8c402 commit dbafbb7

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

packaging/nuget/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The finalized nuget package maybe uploaded manually to NuGet.org
4848
7. If you trust this process you can have release.py upload the package
4949
automatically to NuGet after building it:
5050

51-
$ ./release.py --upload "$(cat your-nuget-api.key)" v0.11.0
51+
$ ./release.py --retries 100 --upload your-nuget-api.key v0.11.0
5252

5353

5454

packaging/nuget/packaging.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
# librdkafka/p-librdkafka__bld-travis__plat-linux__arch-x64__tag-v0.0.62__sha-d051b2c19eb0c118991cd8bc5cf86d8e5e446cde__bid-1562.1/librdkafka.tar.gz
5454

5555

56+
class MissingArtifactError(Exception):
57+
pass
58+
59+
5660
s3_bucket = 'librdkafka-ci-packages'
5761
dry_run = False
5862

@@ -400,7 +404,7 @@ def build (self, buildtype):
400404
break
401405

402406
if artifact is None:
403-
raise Exception('unable to find artifact with tags %s matching "%s"' % (str(attributes), fname_glob))
407+
raise MissingArtifactError('unable to find artifact with tags %s matching "%s"' % (str(attributes), fname_glob))
404408

405409
outf = os.path.join(self.stpath, m[2])
406410
member = m[1]
@@ -538,7 +542,7 @@ def build (self, buildtype):
538542
break
539543

540544
if artifact is None:
541-
raise Exception('unable to find artifact with tags %s matching "%s"' % (str(attributes), fname_glob))
545+
raise MissingArtifactError('unable to find artifact with tags %s matching "%s"' % (str(attributes), fname_glob))
542546

543547
outf = os.path.join(self.stpath, m[2])
544548
member = m[1]

packaging/nuget/release.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import sys
1111
import argparse
12+
import time
1213
import packaging
1314

1415

@@ -27,12 +28,15 @@
2728
parser.add_argument("--no-cleanup", help="Don't clean up temporary folders", action="store_true")
2829
parser.add_argument("--sha", help="Also match on this git sha1", default=None)
2930
parser.add_argument("--nuget-version", help="The nuget package version (defaults to same as tag)", default=None)
30-
parser.add_argument("--upload", help="Upload package to after building, using provided NuGet API key", default=None, type=str)
31+
parser.add_argument("--upload", help="Upload package to after building, using provided NuGet API key (either file or the key itself)", default=None,
32+
type=str)
3133
parser.add_argument("--class", help="Packaging class (see packaging.py)", default="NugetPackage", dest="pkgclass")
34+
parser.add_argument("--retries", help="Number of retries to collect artifacts", default=0, type=int)
3235
parser.add_argument("tag", help="Git tag to collect")
3336

3437
args = parser.parse_args()
3538
dry_run = args.dry_run
39+
retries = args.retries
3640
if not args.directory:
3741
args.directory = 'dl-%s' % args.tag
3842

@@ -76,8 +80,22 @@
7680

7781
print('Building packages:')
7882

79-
p = pkgclass(package_version, arts)
80-
pkgfile = p.build(buildtype='release')
83+
while True:
84+
try:
85+
p = pkgclass(package_version, arts)
86+
pkgfile = p.build(buildtype='release')
87+
break
88+
except packaging.MissingArtifactError as e:
89+
if retries <= 0:
90+
if not args.no_cleanup:
91+
p.cleanup()
92+
raise e
93+
94+
p.cleanup()
95+
retries -= 1
96+
print(e)
97+
print('Retrying in 30 seconds')
98+
time.sleep(30)
8199

82100
if not args.no_cleanup:
83101
p.cleanup()
@@ -93,7 +111,13 @@
93111
print('Created package: %s' % pkgfile)
94112

95113
if args.upload is not None:
114+
if os.path.isfile(args.upload):
115+
with open(args.upload, 'r') as f:
116+
nuget_key = f.read().replace('\n', '')
117+
else:
118+
nuget_key = args.upload
119+
96120
print('Uploading %s to NuGet' % pkgfile)
97-
r = os.system("./push-to-nuget.sh '%s' %s" % (args.upload, pkgfile))
121+
r = os.system("./push-to-nuget.sh '%s' %s" % (nuget_key, pkgfile))
98122
assert int(r) == 0, "NuGet upload failed with exit code {}, see previous errors".format(r)
99123
print('%s successfully uploaded to NuGet' % pkgfile)

0 commit comments

Comments
 (0)