-
Notifications
You must be signed in to change notification settings - Fork 56
/
switch-private-submodules
executable file
·103 lines (84 loc) · 3.12 KB
/
switch-private-submodules
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
#!/usr/bin/env python3
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import argparse
import logging
import os
import subprocess
import sys
DESCRIPTION = "Switch between public and private versions of submodules"
MODULES = [{
"submodule": "aws-encryption-sdk-cpp/tests/test_vectors/aws-encryption-sdk-test-vectors",
"private": "https://github.com/awslabs/private-aws-encryption-sdk-test-vectors-staging.git",
"public": "https://github.com/awslabs/aws-encryption-sdk-test-vectors.git",
}, {
"submodule": "aws-encryption-sdk-specification",
"private": "https://github.com/awslabs/private-aws-encryption-sdk-specification-staging.git",
"public": "https://github.com/awslabs/aws-encryption-sdk-specification.git",
}]
def switch_to(version):
logging.info("Switching to %s version of the submodules", version)
for module in MODULES:
cmd = [
"git", "config",
f'url."{module[version]}".insteadOf',
module["public"],
]
logging.info(" ".join(cmd))
subprocess.run(cmd, check=True)
subprocess.run(["git", "submodule", "sync"], check=True)
subprocess.run([
"git", "submodule", "update", "--init", "--recursive", "--checkout"],
check=True)
def switch_to_env(_):
repo = os.getenv("GITHUB_REPOSITORY")
if not repo:
logging.error(
"Could not determine which submodules to check out "
"($GITHUB_REPOSITORY is not set).")
sys.exit(1)
if repo == "aws/private-aws-encryption-sdk-c-staging":
switch_to("private")
else:
switch_to("public")
OPERATIONS = {
"public": switch_to,
"private": switch_to,
"env": switch_to_env,
}
def main():
pars = argparse.ArgumentParser(description=DESCRIPTION)
for arg in [{
"flags": ["operation"],
"choices": list(OPERATIONS.keys()),
"default": "public",
"help": "Switch to public or private versions of the submodules, "
"or decide which by reading the $GITHUB_REPOSITORY "
"environment variable. Default: %(default)s."
}, {
"flags": ["-v", "--verbose"],
"action": "store_true",
"help": "verbose output",
}]:
flags = arg.pop("flags")
pars.add_argument(*flags, **arg)
args = pars.parse_args()
fmt = "switch-private-submodules: %(message)s"
if args.verbose:
logging.basicConfig(format=fmt, level=logging.INFO)
else:
logging.basicConfig(format=fmt, level=logging.WARNING)
OPERATIONS[args.operation](args.operation)
if __name__ == "__main__":
main()