@@ -331,14 +331,18 @@ def find_missing_from_index(url, installs):
331331
332332if INDEX_FILE :
333333 INDEX_FILE = Path (INDEX_FILE ).absolute ()
334- INDEX_CAT_FILE = INDEX_FILE .with_suffix ( " .cat" )
334+ INDEX_CAT_FILE = INDEX_FILE .with_name ( f" { INDEX_FILE . name } .cat" )
335335 INDEX_FILE .parent .mkdir (parents = True , exist_ok = True )
336336 with open (INDEX_FILE , "w" , encoding = "utf-8" ) as f :
337337 json .dump (index , f )
338338
339339 sign_json (INDEX_CAT_FILE , INDEX_FILE )
340+ INDEX_CAT_URL = f"{ INDEX_URL } .cat"
341+ INDEX_CAT_PATH = f"{ INDEX_PATH } .cat"
340342else :
341343 INDEX_CAT_FILE = None
344+ INDEX_CAT_URL = None
345+ INDEX_CAT_PATH = None
342346
343347
344348if MANIFEST_FILE :
@@ -376,37 +380,36 @@ def find_missing_from_index(url, installs):
376380 print ("Expecting mtime" , INDEX_MTIME , "but saw" , mtime )
377381 sys .exit (1 )
378382
383+ TO_PURGE = [i ["url" ] for i , * _ in UPLOADS ]
379384
380- if not NO_UPLOAD :
381- if MANIFEST_FILE :
382- print ("Uploading" , MANIFEST_FILE , "to" , MANIFEST_URL )
383- upload_ssh (MANIFEST_FILE , MANIFEST_PATH )
384-
385- if INDEX_FILE :
386- print ("Uploading" , INDEX_FILE , "to" , INDEX_URL )
387- upload_ssh (INDEX_FILE , INDEX_PATH )
388-
389- if INDEX_CAT_FILE :
390- print ("Uploading" , INDEX_CAT_FILE , "to" , f"{ INDEX_URL } .cat" )
391- upload_ssh (INDEX_CAT_FILE , f"{ INDEX_PATH } .cat" )
392-
393- print ("Purging" , len (UPLOADS ), "uploaded files" )
394- parents = set ()
395- for i , * _ in UPLOADS :
396- purge (i ["url" ])
397- parents .add (i ["url" ].rpartition ("/" )[0 ] + "/" )
398- for i in parents :
399- purge (i )
400- if MANIFEST_URL :
401- purge (MANIFEST_URL )
402- purge (MANIFEST_URL .rpartition ("/" )[0 ] + "/" )
403- if INDEX_URL :
404- purge (INDEX_URL )
405- purge (INDEX_URL .rpartition ("/" )[0 ] + "/" )
406- missing = find_missing_from_index (INDEX_URL , [i for i , * _ in UPLOADS ])
407- if missing :
408- print ("##[error]Lost a race with another publish step!" )
409- print ("Index at" , INDEX_URL , "does not contain installs:" )
410- for m in missing :
411- print (m ["id" ], m ["sort-version" ])
412- sys .exit (1 )
385+ if MANIFEST_FILE :
386+ print ("Uploading" , MANIFEST_FILE , "to" , MANIFEST_URL )
387+ upload_ssh (MANIFEST_FILE , MANIFEST_PATH )
388+ TO_PURGE .append (MANIFEST_URL )
389+
390+ if INDEX_FILE :
391+ print ("Uploading" , INDEX_FILE , "to" , INDEX_URL )
392+ upload_ssh (INDEX_FILE , INDEX_PATH )
393+ TO_PURGE .append (INDEX_URL )
394+
395+ if INDEX_CAT_FILE :
396+ print ("Uploading" , INDEX_CAT_FILE , "to" , INDEX_CAT_URL )
397+ upload_ssh (INDEX_CAT_FILE , INDEX_CAT_PATH )
398+ TO_PURGE .append (INDEX_CAT_URL )
399+
400+ # Calculate directory parents for all files
401+ TO_PURGE .extend ({i .rpartition ("/" )[0 ] + "/" for i in TO_PURGE })
402+
403+ print ("Purging" , len (TO_PURGE ), "uploaded files, indexes and directories" )
404+
405+ for i in TO_PURGE :
406+ purge (i )
407+
408+ if INDEX_URL :
409+ missing = find_missing_from_index (INDEX_URL , [i for i , * _ in UPLOADS ])
410+ if missing :
411+ print ("##[error]Lost a race with another publish step!" )
412+ print ("Index at" , INDEX_URL , "does not contain installs:" )
413+ for m in missing :
414+ print (m ["id" ], m ["sort-version" ])
415+ sys .exit (1 )
0 commit comments