@@ -427,11 +427,12 @@ def _publish(gh_token: str) -> None:
427
427
428
428
429
429
@cli .command ()
430
- def upload () -> None :
431
- _upload ()
430
+ @click .option ("--gh-token" , envvar = ["GH_TOKEN" , "GITHUB_TOKEN" ], required = False )
431
+ def upload (gh_token : Optional [str ]) -> None :
432
+ _upload (gh_token )
432
433
433
434
434
- def _upload () -> None :
435
+ def _upload (gh_token : Optional [ str ] ) -> None :
435
436
"""Upload release to pypi."""
436
437
437
438
current_version = get_package_version ()
@@ -444,18 +445,40 @@ def _upload() -> None:
444
445
click .echo ("Tag {tag_name} (tag.commit) is not currently checked out!" )
445
446
click .get_current_context ().abort ()
446
447
447
- pypi_asset_names = [
448
- f"matrix_synapse-{ current_version } -py3-none-any.whl" ,
449
- f"matrix-synapse-{ current_version } .tar.gz" ,
450
- ]
448
+ # Query all the assets corresponding to this release.
449
+ gh = Github (gh_token )
450
+ gh_repo = gh .get_repo ("matrix-org/synapse" )
451
+ gh_release = gh_repo .get_release (tag_name )
452
+
453
+ all_assets = set (gh_release .get_assets ())
454
+
455
+ # Only accept the wheels and sdist.
456
+ # Notably: we don't care about debs.tar.xz.
457
+ asset_names_and_urls = sorted (
458
+ (asset .name , asset .browser_download_url )
459
+ for asset in all_assets
460
+ if asset .name .endswith ((".whl" , ".tar.gz" ))
461
+ )
462
+
463
+ # Print out what we've determined.
464
+ print ("Found relevant assets:" )
465
+ for asset_name , _ in asset_names_and_urls :
466
+ print (f" - { asset_name } " )
467
+
468
+ ignored_asset_names = sorted (
469
+ {asset .name for asset in all_assets }
470
+ - {asset_name for asset_name , _ in asset_names_and_urls }
471
+ )
472
+ print ("\n Ignoring irrelevant assets:" )
473
+ for asset_name in ignored_asset_names :
474
+ print (f" - { asset_name } " )
451
475
452
476
with TemporaryDirectory (prefix = f"synapse_upload_{ tag_name } _" ) as tmpdir :
453
- for name in pypi_asset_names :
477
+ for name , asset_download_url in asset_names_and_urls :
454
478
filename = path .join (tmpdir , name )
455
- url = f"https://github.com/matrix-org/synapse/releases/download/{ tag_name } /{ name } "
456
479
457
480
click .echo (f"Downloading { name } into { filename } " )
458
- urllib .request .urlretrieve (url , filename = filename )
481
+ urllib .request .urlretrieve (asset_download_url , filename = filename )
459
482
460
483
if click .confirm ("Upload to PyPI?" , default = True ):
461
484
subprocess .run ("twine upload *" , shell = True , cwd = tmpdir )
@@ -672,7 +695,7 @@ def full(gh_token: str) -> None:
672
695
_publish (gh_token )
673
696
674
697
click .echo ("\n *** upload ***" )
675
- _upload ()
698
+ _upload (gh_token )
676
699
677
700
click .echo ("\n *** merge back ***" )
678
701
_merge_back ()
0 commit comments