@@ -12,7 +12,7 @@ import tarfile
12
12
import asyncio
13
13
import json
14
14
from dataclasses import dataclass
15
- from typing import Optional , Tuple
15
+ from typing import Optional , Tuple , List
16
16
from build .build_support .actions import derive_options_from_args , REPO_ROOT
17
17
18
18
@@ -224,6 +224,10 @@ class GitHub:
224
224
"body" : body
225
225
})
226
226
227
+ def update_release_notes (self , release_id : str , body : str ):
228
+ url = (f"https://api.github.com/repos/{ self .repo } /releases/{ release_id } " )
229
+ return self .json_request ("PATCH" , url , body = {"body" : body })
230
+
227
231
def workflow_runs (self , workflow_name : str , branch : str ):
228
232
url = ("https://api.github.com"
229
233
f"/repos/{ self .repo } /actions/workflows/{ workflow_name } "
@@ -395,7 +399,7 @@ class Distribution:
395
399
if not tag_name :
396
400
raise Exception ("Could not determine tag name" )
397
401
398
- release = self .create_tag_and_prerelease (tag_name , options )
402
+ release , swift_version , swiftwasm_build_version = self .create_tag_and_prerelease (tag_name , options )
399
403
400
404
# Move to artifacts directory because "zip" does not have
401
405
# --chdir option unlike "tar"
@@ -424,6 +428,15 @@ class Distribution:
424
428
return
425
429
self .upload_to_release (package , release )
426
430
431
+ # Upload sha256 checksum
432
+ import hashlib
433
+ checksum_path = package + ".sha256"
434
+ with open (package , "rb" ) as f :
435
+ checksum = hashlib .sha256 (f .read ()).hexdigest ()
436
+ with open (checksum_path , "w" ) as f :
437
+ f .write (checksum )
438
+ self .upload_to_release (checksum_path , release )
439
+
427
440
print (f"Packaging { artifact ['name' ]} ..." )
428
441
packaging_tasks .append (
429
442
asyncio .create_task (package_sdk_work (downloaded )))
@@ -436,6 +449,10 @@ class Distribution:
436
449
task .cancel ()
437
450
raise e
438
451
452
+ # Update release notes with checksums
453
+ self .update_release_notes_with_checksums (
454
+ release , downloaded_paths , swift_version , swiftwasm_build_version )
455
+
439
456
if options .only_swift_sdk :
440
457
return
441
458
@@ -646,9 +663,10 @@ class Distribution:
646
663
print (f"Creating prerelease for { tag_name } ..." )
647
664
body = self .make_release_note (swift_version , swiftwasm_build_version )
648
665
print (f"Release note:\n { body } " )
649
- return self .swift_github .create_prerelease (tag_name , body )
666
+ return [ self .swift_github .create_prerelease (tag_name , body ), swift_version , swiftwasm_build_version ]
650
667
651
- def make_release_note (self , swift_version , swiftwasm_build_version ):
668
+ def make_release_note (self , swift_version , swiftwasm_build_version ,
669
+ checksums : Optional [List [tuple ]]= None ):
652
670
projects = [
653
671
["apple/swift" ,
654
672
f"releases/tag/{ swift_version } " ],
@@ -659,8 +677,33 @@ class Distribution:
659
677
body += "|:--|:--|\n "
660
678
for repo , subpath in projects :
661
679
body += f"| `{ repo } ` | https://github.com/{ repo } /{ subpath } |\n "
680
+ if checksums :
681
+ body += "\n "
682
+ body += """\
683
+ ### Installation
684
+
685
+ You can install the toolchain using the following command:
686
+
687
+ """
688
+ for name , download_url , checksum in checksums :
689
+ body += f"**{ name } **\n \n "
690
+ body += "```console\n "
691
+ body += f"$ swift sdk install { download_url } --checksum { checksum } \n "
692
+ body += "```\n "
662
693
return body
663
694
695
+ def update_release_notes_with_checksums (self , release , downloaded_paths , swift_version , swiftwasm_build_version ):
696
+ checksums = []
697
+ for artifact , artifact_path in downloaded_paths :
698
+ if artifact ["name" ].endswith ("-artifactbundle" ):
699
+ name = os .path .basename (artifact_path )
700
+ checksum_path = artifact_path + ".sha256"
701
+ with open (checksum_path , "r" ) as f :
702
+ checksum = f .read ().strip ()
703
+ checksums .append ((name , artifact ["archive_download_url" ], checksum ))
704
+ body = self .make_release_note (swift_version , swiftwasm_build_version , checksums )
705
+ self .swift_github .update_release_notes (release ["id" ], body )
706
+
664
707
def git_push_swift_source (self , options , tag_name ):
665
708
build_repo = "https://github.com/swiftwasm/swiftwasm-build.git"
666
709
build_rev = self .github .revision_at_run (self .run_id )
0 commit comments