Skip to content

Commit 718c14c

Browse files
Add checksums to release notes
1 parent 5a94d8b commit 718c14c

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

tools/gh-distribute-toolchain

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import tarfile
1212
import asyncio
1313
import json
1414
from dataclasses import dataclass
15-
from typing import Optional, Tuple
15+
from typing import Optional, Tuple, List
1616
from build.build_support.actions import derive_options_from_args, REPO_ROOT
1717

1818

@@ -224,6 +224,10 @@ class GitHub:
224224
"body": body
225225
})
226226

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+
227231
def workflow_runs(self, workflow_name: str, branch: str):
228232
url = ("https://api.github.com"
229233
f"/repos/{self.repo}/actions/workflows/{workflow_name}"
@@ -395,7 +399,7 @@ class Distribution:
395399
if not tag_name:
396400
raise Exception("Could not determine tag name")
397401

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)
399403

400404
# Move to artifacts directory because "zip" does not have
401405
# --chdir option unlike "tar"
@@ -424,6 +428,15 @@ class Distribution:
424428
return
425429
self.upload_to_release(package, release)
426430

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+
427440
print(f"Packaging {artifact['name']}...")
428441
packaging_tasks.append(
429442
asyncio.create_task(package_sdk_work(downloaded)))
@@ -436,6 +449,10 @@ class Distribution:
436449
task.cancel()
437450
raise e
438451

452+
# Update release notes with checksums
453+
self.update_release_notes_with_checksums(
454+
release, downloaded_paths, swift_version, swiftwasm_build_version)
455+
439456
if options.only_swift_sdk:
440457
return
441458

@@ -646,9 +663,10 @@ class Distribution:
646663
print(f"Creating prerelease for {tag_name}...")
647664
body = self.make_release_note(swift_version, swiftwasm_build_version)
648665
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]
650667

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):
652670
projects = [
653671
["apple/swift",
654672
f"releases/tag/{swift_version}"],
@@ -659,8 +677,33 @@ class Distribution:
659677
body += "|:--|:--|\n"
660678
for repo, subpath in projects:
661679
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"
662693
return body
663694

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+
664707
def git_push_swift_source(self, options, tag_name):
665708
build_repo = "https://github.com/swiftwasm/swiftwasm-build.git"
666709
build_rev = self.github.revision_at_run(self.run_id)

0 commit comments

Comments
 (0)