Skip to content

Commit 63416e7

Browse files
authored
adjusted update script to be easier to read (#23)
1 parent 89f530f commit 63416e7

File tree

2 files changed

+22
-36
lines changed

2 files changed

+22
-36
lines changed

Package.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// swift-tools-version:5.4
22
import PackageDescription
33

4+
let checksum = "f69d5c7bcde788d709944bacdeb72888beed1ec6b0a1ad32a092becdc156854b"
5+
let version = "v87.0.0"
6+
let url = "https://github.com/mozilla/application-services/releases/download/\(version)/MozillaRustComponents.xcframework.zip"
7+
48
let package = Package(
59
name: "MozillaRustComponentsSwift",
610
platforms: [.iOS(.v11)],
@@ -41,8 +45,8 @@ let package = Package(
4145
// For release artifacts, reference the MozillaRustComponents as a URL with checksum.
4246
// IMPORTANT: The checksum has to be on the line directly after the `url`
4347
// this is important for our release script so that all values are updated correctly
44-
url: "https://github.com/mozilla/application-services/releases/download/v87.0.0/MozillaRustComponents.xcframework.zip",
45-
checksum: "f69d5c7bcde788d709944bacdeb72888beed1ec6b0a1ad32a092becdc156854b"
48+
url: url,
49+
checksum: checksum
4650

4751
// For local testing, you can point at an (unzipped) XCFramework that's part of the repo.
4852
// Note that you have to actually check it in and make a tag for it to work correctly.

automation/update_package_swift.py

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from github import Github
33
import hashlib
44
import requests
5+
import fileinput
6+
import sys
57

68
GITHUB_REPO = "mozilla/application-services"
79
XC_FRAMEWORK_NAME = "MozillaRustComponents.xcframework.zip"
@@ -12,7 +14,7 @@
1214
def get_xcframework_artifact():
1315
g = Github(github_access_token)
1416
repo = g.get_repo(GITHUB_REPO)
15-
17+
1618
release = repo.get_release(as_version)
1719
for asset in release.get_assets():
1820
if asset.name == XC_FRAMEWORK_NAME:
@@ -22,38 +24,18 @@ def compute_checksum(xc_framework_url):
2224
req = requests.get(xc_framework_url)
2325
return hashlib.sha256(req.content).hexdigest()
2426

25-
def update_package_swift(xc_framework_url, checksum):
26-
old_url = ''
27-
old_checksum = ''
28-
with open(PACKAGE_SWIFT) as fp:
29-
line = fp.readline()
30-
while line:
31-
line = fp.readline()
32-
33-
# If this is the line that has the URL to
34-
# the xcframework
35-
if XC_FRAMEWORK_NAME in line:
36-
url_start = line.find('"') + 1
37-
url_end = line.find('"', url_start)
38-
old_url = line[url_start:url_end]
39-
# NOTE: We assume that the next line is the
40-
# checksum, there is a note in Package.swift
41-
# to make sure we don't change that
42-
line = fp.readline()
43-
checksum_start = line.find('"') + 1
44-
checksum_end = line.find('"', checksum_start)
45-
old_checksum = line[checksum_start:checksum_end]
46-
break
47-
file = open(PACKAGE_SWIFT, "r+")
48-
data = file.read()
49-
data = data.replace(old_url, xc_framework_url)
50-
data = data.replace(old_checksum, checksum)
51-
file.close()
52-
file = open(PACKAGE_SWIFT, "wt")
53-
file.write(data)
54-
file.close()
55-
56-
27+
def update_package_swift(as_version, checksum):
28+
version_line = "let version ="
29+
checksum_line = "let checksum ="
30+
31+
for line in fileinput.input(PACKAGE_SWIFT, inplace=1):
32+
if line.strip().startswith(version_line):
33+
# Replace the line with the new version included
34+
line = f"{version_line} \"{as_version}\"\n"
35+
elif line.strip().startswith(checksum_line):
36+
# Replace the line with the new computed checksum
37+
line = f"{checksum_line} \"{checksum}\"\n"
38+
sys.stdout.write(line)
5739
def main():
5840
'''
5941
Updates `Package.swift` with the latest
@@ -63,7 +45,7 @@ def main():
6345
exit(1)
6446
xc_framework_url = get_xcframework_artifact()
6547
checksum = compute_checksum(xc_framework_url)
66-
update_package_swift(xc_framework_url, checksum)
48+
update_package_swift(as_version, checksum)
6749

6850

6951

0 commit comments

Comments
 (0)