Skip to content

Commit ed79ff0

Browse files
committed
Update Package.swift tag when manually triggering release.
1 parent e5a9c72 commit ed79ff0

File tree

2 files changed

+68
-24
lines changed

2 files changed

+68
-24
lines changed

.github/workflows/release-framework.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
xcode-version: latest
2828
- name: Checkout
2929
uses: actions/checkout@v2
30+
- name: Update Package.swift tag to ${{ github.event.inputs.tag }}
31+
if: ${{ github.event.inputs.tag != null && github.event.inputs.tag != '' }}
32+
run: |
33+
python3 ./src/scripts/update_swift_package_checksum.py --tag ${{ github.event.inputs.tag }}
3034
- name: Install Dependencies
3135
uses: ./.github/actions/install-dependencies
3236
with:
@@ -38,7 +42,8 @@ jobs:
3842
- name: Update Package.swift checksum
3943
if: ${{ github.event.inputs.tag != null && github.event.inputs.tag != '' }}
4044
run: |
41-
python3 ./src/scripts/update_swift_package_checksum.py `swift package compute-checksum LightningDevKit.xcframework.zip`
45+
CHECKSUM=`swift package compute-checksum LightningDevKit.xcframework.zip`
46+
python3 ./src/scripts/update_swift_package_checksum.py --checksum "${CHECKSUM}"
4247
git commit -m "Update Package.swift for ${{ github.event.inputs.tag }} release." ./Package.swift
4348
git tag ${{ github.event.inputs.tag }}
4449
git push origin HEAD:main --tags
Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,81 @@
1+
import argparse
12
import json
23
import os
34
import re
45
import sys
56

67

7-
def run(new_checksum: str):
8-
print("setting checksum (JSON-serialization):")
9-
print(json.dumps(new_checksum))
10-
11-
if not new_checksum.isalnum():
12-
print('Checksum must be alphanumeric.', file=sys.stderr)
8+
def run(new_checksum: str = None, new_tag: str = None):
9+
if new_checksum is None and new_tag is None:
10+
print('At least one of --checksum or --tag arguments must be provided.', file=sys.stderr)
1311
sys.exit(1)
1412

15-
if not new_checksum.islower():
16-
print('Checksum must be lowercase.', file=sys.stderr)
17-
sys.exit(1)
13+
if new_checksum is not None:
14+
if not new_checksum.isalnum():
15+
print('Checksum must be alphanumeric.', file=sys.stderr)
16+
sys.exit(1)
17+
18+
if not new_checksum.islower():
19+
print('Checksum must be lowercase.', file=sys.stderr)
20+
sys.exit(1)
21+
22+
try:
23+
int(new_checksum, 16)
24+
except:
25+
print('Checksum must be hexadecimal.', file=sys.stderr)
26+
sys.exit(1)
27+
28+
if new_tag is not None:
29+
if new_tag.strip() != new_tag:
30+
print('Tag must not contain any whitespace.', file=sys.stderr)
31+
32+
tag_regex = re.compile("^\d+[.]\d+[.]\d+$")
33+
tag_match = tag_regex.match(new_tag)
34+
if tag_match is None:
35+
print('Tag must adhere to x.x.x major/minor/patch format.', file=sys.stderr)
36+
37+
settings = [
38+
{'variable_name': 'checksum', 'value': new_checksum},
39+
{'variable_name': 'tag', 'value': new_tag},
40+
]
41+
42+
package_file_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '../../Package.swift'))
43+
print(package_file_path)
44+
45+
1846

47+
original_package_file = None
1948
try:
20-
int(new_checksum, 16)
49+
with open(package_file_path, 'r') as package_file_handle:
50+
original_package_file = package_file_handle.read()
2151
except:
22-
print('Checksum must be hexadecimal.', file=sys.stderr)
52+
print('Failed to read Package.swift file.', file=sys.stderr)
2353
sys.exit(1)
2454

55+
package_file = original_package_file
56+
for current_setting in settings:
57+
current_variable_name = current_setting['variable_name']
58+
new_value = current_setting['value']
59+
if new_value is None:
60+
continue
2561

26-
package_file_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '../../Package.swift'))
27-
print(package_file_path)
28-
regex = re.compile("(let[\s]+checksum[\s]*=[\s]*)(.*)")
62+
print(f'setting {current_variable_name} (JSON-serialization):')
63+
print(json.dumps(new_value))
64+
65+
regex = re.compile(f'(let[\s]+{current_variable_name}[\s]*=[\s]*)(.*)')
66+
67+
previous_value = regex.search(package_file).group(2)
68+
# new_package_file = checksum_regex.sub(f'\g<1>"{new_checksum}"', package_file)
69+
package_file = package_file.replace(previous_value, f'"{new_value}"')
2970

30-
with open(package_file_path, 'r') as package_file_handle:
31-
package_file = package_file_handle.read()
32-
previous_checksum = regex.search(package_file).group(2)
33-
# new_package_file = regex.sub(f'\g<1>"{new_checksum}"', package_file)
34-
new_package_file = package_file.replace(previous_checksum, f'"{new_checksum}"')
35-
with open(package_file_path, "w") as f:
36-
f.write(new_package_file)
71+
with open(package_file_path, "w") as f:
72+
f.write(package_file)
3773

3874

3975

4076
if __name__ == '__main__':
41-
new_checksum = sys.argv[1]
42-
run(new_checksum)
77+
parser = argparse.ArgumentParser(description='Process some integers.')
78+
parser.add_argument('--checksum', type=str, help='new checksum of LightningDevKit.xcframework.zip', required=False, default=None)
79+
parser.add_argument('--tag', type=str, help='new release tag', required=False, default=None)
80+
args = parser.parse_args()
81+
run(new_checksum=args.checksum, new_tag=args.tag)

0 commit comments

Comments
 (0)