Skip to content

Commit 751e5da

Browse files
committed
improve publish script
1 parent a9b7465 commit 751e5da

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

publish.py

+22-16
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ def check_staged_changes() -> bool:
5353
return len(subprocess.run(["git", "diff", "--name-only", "--cached"], capture_output=True).stdout) > 0
5454

5555

56+
def push():
57+
print("[Info]\tPulling to check... ", end="")
58+
59+
pull_process = subprocess.run(
60+
["git", "pull"], capture_output=True)
61+
62+
if "up to date." in str(pull_process.stdout):
63+
print("ok.")
64+
else:
65+
print("warning.")
66+
print(
67+
"Remote contains changes not present in local. Make sure remote is update before bumping")
68+
exit(1)
69+
70+
print("[Info]\tPushing to origin...")
71+
subprocess.check_output(["git", "push", "origin", "main", "--tags"])
72+
73+
5674
# Main:
5775
try:
5876
subprocess.check_output(['cargo', 'bump', '--version'])
@@ -66,6 +84,7 @@ def check_staged_changes() -> bool:
6684

6785
bump_parser = sub_parsers.add_parser(name="bump")
6886
undo_parser = sub_parsers.add_parser(name="undo")
87+
push_parser = sub_parsers.add_parser(name="push")
6988

7089
bump_parser.add_argument("-t", "--type", choices=bump_types, default="",
7190
help="Whether to bump patch, minor, or major versions.")
@@ -154,21 +173,7 @@ def check_staged_changes() -> bool:
154173
args.push = True
155174

156175
if args.push:
157-
print("[Info]\tPulling to check... ", end="")
158-
159-
pull_process = subprocess.run(
160-
["git", "pull"], capture_output=True)
161-
162-
if "Already up to date." in str(pull_process.stdout):
163-
print("ok.")
164-
else:
165-
print("warning.")
166-
print(
167-
"Remote contains changes not present in local. Make sure remote is update before bumping")
168-
exit(1)
169-
170-
print("[Info]\tPushing to origin...")
171-
subprocess.check_output(["git", "push", "origin", "main", "--tags"])
176+
push()
172177
else:
173178
print("[Info]\tApplied changes locally. Run 'git push origin main --tags' to push tags to remote and trigger a workflow.")
174179

@@ -211,7 +216,8 @@ def check_staged_changes() -> bool:
211216
print("[Error]\tUnable to undo. Previous commit isn't tagged.")
212217

213218
exit(1)
214-
219+
elif args.command == "push":
220+
push()
215221
elif args.command is None:
216222
parser.print_help()
217223
exit(0)

0 commit comments

Comments
 (0)