Skip to content

Commit 9e65af2

Browse files
committed
ci(swift): guard release workflow
1 parent 1cc93d8 commit 9e65af2

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

.github/workflows/swift-release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ jobs:
2929
fi
3030
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
3131
32+
- name: Ensure workflow runs on a branch
33+
run: |
34+
if [[ "${GITHUB_REF_TYPE}" != "branch" ]]; then
35+
echo "This workflow must run on a branch ref."
36+
exit 1
37+
fi
38+
3239
- name: Check for existing tag or release
3340
env:
3441
GH_TOKEN: ${{ github.token }}

scripts/swift_update_package_checksum.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,21 @@ def run(new_checksum: str = None, new_tag: str = None):
6262
print(f"setting {current_variable_name} (JSON-serialization):")
6363
print(json.dumps(new_value))
6464

65-
regex = re.compile(rf"(let\s+{current_variable_name}\s*=\s*)(.*)")
66-
match = regex.search(updated_package_file)
67-
if match is None:
65+
regex = re.compile(
66+
rf"^(\s*let\s+{current_variable_name}\s*=\s*).*$",
67+
re.MULTILINE,
68+
)
69+
updated_package_file, replacements = regex.subn(
70+
rf'\1"{new_value}"',
71+
updated_package_file,
72+
)
73+
if replacements != 1:
6874
print(
69-
f"Failed to find {current_variable_name} in Package.swift.",
75+
f"Failed to update {current_variable_name} in Package.swift.",
7076
file=sys.stderr,
7177
)
7278
sys.exit(1)
7379

74-
previous_value = match.group(2)
75-
updated_package_file = updated_package_file.replace(previous_value, f'"{new_value}"')
76-
7780
with open(package_file_path, "w") as package_file_handle:
7881
package_file_handle.write(updated_package_file)
7982

0 commit comments

Comments
 (0)