-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-ci.py
170 lines (143 loc) · 5.21 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import argparse
import os
import sys
from pathlib import Path
from typing import Optional
import tankerci
import tankerci.bump
import tankerci.conan
import tankerci.git
import tankerci.gitlab
from tankerci.conan import Profile, TankerSource
def prepare(
tanker_source: TankerSource,
host_profile: Profile,
update: bool,
tanker_ref: Optional[str],
) -> None:
tanker_deployed_ref = tanker_ref
if tanker_source == TankerSource.DEPLOYED and not tanker_deployed_ref:
tanker_deployed_ref = "tanker/latest-stable@"
tankerci.conan.install_tanker_source(
tanker_source,
output_path=Path.cwd() / "conan",
host_profiles=[host_profile],
build_profile=tankerci.conan.get_build_profile(),
tanker_deployed_ref=tanker_deployed_ref,
)
tankerci.run("bundle", "install")
tankerci.run("bundle", "exec", "rake", "tanker_libs")
def build(test: bool):
tankerci.run("bundle", "install")
if test:
tankerci.run("bundle", "exec", "rake", "spec")
def lint() -> None:
tankerci.run("bundle", "install")
tankerci.run("bundle", "exec", "rake", "rubocop")
def set_credentials() -> None:
gem_folder = Path.home() / ".gem"
gem_folder.mkdir(exist_ok=True)
api_key = os.environ["GEM_HOST_API_KEY"]
credential_file = gem_folder / "credentials"
credential_file.touch(mode=0o600)
credential_file.write_text(f":rubygems_api_key: {api_key}")
def deploy(version: str) -> None:
expected_libs = [
"vendor/tanker/linux-x86_64/libctanker.so",
"vendor/tanker/darwin-x86_64/libctanker.dylib",
"vendor/tanker/darwin-aarch64/libctanker.dylib",
]
for lib in expected_libs:
expected_path = Path(lib)
if not expected_path.exists():
sys.exit(f"Error: {expected_path} does not exist!")
tankerci.bump.bump_files(version)
set_credentials()
# NOTE: this commands also re-gerenates the lock as a side-effect since the
# gemspec has changed - keep this before the git commands
tankerci.run("bundle", "install")
# NOTE: `bundle exec rake build` does not like dirty git repos, so make a
# commit with the new changes first
tankerci.git.run(Path.cwd(), "add", "--update", ".")
tankerci.git.run(Path.cwd(), "commit", "--message", f"Bump to {version}")
tankerci.run("bundle", "exec", "rake", "build")
tankerci.run("bundle", "exec", "rake", "push")
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"--isolate-conan-user-home",
action="store_true",
dest="home_isolation",
default=False,
)
parser.add_argument("--remote", default="artifactory")
subparsers = parser.add_subparsers(title="subcommands", dest="command")
build_parser = subparsers.add_parser("build")
build_parser.add_argument("--test", action="store_true")
prepare_parser = subparsers.add_parser("prepare")
prepare_parser.add_argument(
"--use-tanker",
type=TankerSource,
default=TankerSource.EDITABLE,
dest="tanker_source",
)
prepare_parser.add_argument(
"--profile", dest="profiles", nargs="+", type=str, required=True
)
prepare_parser.add_argument("--tanker-ref")
prepare_parser.add_argument(
"--update",
action="store_true",
default=False,
dest="update",
)
download_artifacts_parser = subparsers.add_parser("download-artifacts")
download_artifacts_parser.add_argument("--project-id", required=True)
download_artifacts_parser.add_argument("--pipeline-id", required=True)
download_artifacts_parser.add_argument("--job-name", required=True)
deploy_parser = subparsers.add_parser("deploy")
deploy_parser.add_argument("--version", required=True)
subparsers.add_parser("lint")
args = parser.parse_args()
command = args.command
user_home = None
if args.home_isolation:
user_home = Path.cwd() / ".cache" / "conan" / args.remote
if command == "prepare":
# Because of GitLab issue https://gitlab.com/gitlab-org/gitlab/-/issues/254323
# the downstream deploy jobs will be triggered even if upstream has failed
# By removing the cache we ensure that we do not use a
# previously built (and potentially broken) release candidate to deploy a binding
tankerci.conan.run("remove", "tanker/*", "--force")
ctx = tankerci.conan.ConanContextManager(
[args.remote],
conan_home=user_home,
)
if command == "build":
with ctx:
build(args.test)
elif command == "prepare":
profiles = Profile(args.profiles)
with ctx:
prepare(
args.tanker_source,
profiles,
args.update,
args.tanker_ref,
)
elif command == "deploy":
with ctx:
deploy(args.version)
elif command == "lint":
lint()
elif command == "download-artifacts":
tankerci.gitlab.download_artifacts(
project_id=args.project_id,
pipeline_id=args.pipeline_id,
job_name=args.job_name,
)
else:
parser.print_help()
sys.exit(1)
if __name__ == "__main__":
main()