|
9 | 9 | import os
|
10 | 10 | import sys
|
11 | 11 | import argparse
|
| 12 | +import time |
12 | 13 | import packaging
|
13 | 14 |
|
14 | 15 |
|
|
27 | 28 | parser.add_argument("--no-cleanup", help="Don't clean up temporary folders", action="store_true")
|
28 | 29 | parser.add_argument("--sha", help="Also match on this git sha1", default=None)
|
29 | 30 | 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) |
31 | 33 | 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) |
32 | 35 | parser.add_argument("tag", help="Git tag to collect")
|
33 | 36 |
|
34 | 37 | args = parser.parse_args()
|
35 | 38 | dry_run = args.dry_run
|
| 39 | + retries = args.retries |
36 | 40 | if not args.directory:
|
37 | 41 | args.directory = 'dl-%s' % args.tag
|
38 | 42 |
|
|
76 | 80 |
|
77 | 81 | print('Building packages:')
|
78 | 82 |
|
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) |
81 | 99 |
|
82 | 100 | if not args.no_cleanup:
|
83 | 101 | p.cleanup()
|
|
93 | 111 | print('Created package: %s' % pkgfile)
|
94 | 112 |
|
95 | 113 | 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 | + |
96 | 120 | 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)) |
98 | 122 | assert int(r) == 0, "NuGet upload failed with exit code {}, see previous errors".format(r)
|
99 | 123 | print('%s successfully uploaded to NuGet' % pkgfile)
|
0 commit comments