-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-ci.py
69 lines (54 loc) · 1.88 KB
/
run-ci.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import argparse
import subprocess
import sys
from pathlib import Path
import tbump
import tbump.config
def version_from_git_tag(git_tag: str) -> str:
prefix = "v"
assert git_tag.startswith(prefix), "tag should start with %s" % prefix
cfg_file = tbump.config.get_config_file(Path.cwd())
tbump_cfg = cfg_file.get_config()
regex = tbump_cfg.version_regex
version = git_tag[len(prefix) :] # noqa
match = regex.match(version)
assert match, "Could not parse %s as a valid tag" % git_tag
return version
def deploy(version: str) -> None:
tbump.bump_files(version_from_git_tag(version))
# Note: this commands also re-gerenates the lock as a side-effect since the
# gemspec has changed - keep this before the git commands
subprocess.run(["bundle", "install"], check=True)
# Note: `bundle exec rake build` does not like dirty git repos, so make a
# commit with the new changes first
subprocess.run(["git", "add", "--update", "."], cwd=Path.cwd(), check=True)
subprocess.run(
[
"git",
"-c",
"-c",
"user.name=Tanker tech team",
"commit",
"--message",
f"Bump to {version}",
],
cwd=Path.cwd(),
check=True,
)
subprocess.run(["bundle", "exec", "rake", "build"], check=True)
subprocess.run(["bundle", "exec", "rake", "push"], check=True)
def main() -> None:
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(title="subcommands", dest="command")
deploy_parser = subparsers.add_parser("deploy")
deploy_parser.add_argument("--version", required=True)
args = parser.parse_args()
command = args.command
if command == "deploy":
deploy(args.version)
else:
parser.print_help()
sys.exit(1)
if __name__ == "__main__":
main()