-
Notifications
You must be signed in to change notification settings - Fork 43
/
pull_submodules.py
executable file
·61 lines (46 loc) · 1.66 KB
/
pull_submodules.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
#! /usr/bin/env python3
import os
import subprocess
modules_dir = 'modules'
modules = {
'luatest': 'INPUT_LUATEST',
'tntcxx': 'INPUT_CPP_DRIVER',
}
workdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'modules')
def main():
"""
set -x
mkdir -p ~/.ssh/
ssh-keyscan github.com >> ~/.ssh/known_hosts
git submodule update --init
git fetch --recurse-submodules
git submodule update --remote --checkout
"""
in_ci = os.environ.get("CI")
if not in_ci:
mkdir_p("~/.ssh/")
commands = "set -ex ;" \
"ssh-keyscan github.com >> ~/.ssh/known_hosts ;" \
"git submodule update --init ;" \
"git fetch --recurse-submodules"
subprocess.check_call(commands, shell=True)
for directory, git_ref_variable in modules.items():
git_ref = os.environ.get(git_ref_variable, 'origin/master')
checkout_submodule(directory, git_ref)
def checkout_submodule(directory, git_ref='origin/master'):
print(f'Checking out {directory} module into {git_ref}')
path = os.path.join(workdir, directory)
print(path)
subprocess.check_call('set -ex ; git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', shell=True,
cwd=path)
git_checkout = f'set -ex ; git remote update ; git checkout {git_ref}'
subprocess.check_call(git_checkout, shell=True,
cwd=path)
def mkdir_p(path):
"""
Creates a directory with subdirectories, just like `mkdir -p path`
"""
import pathlib
pathlib.Path(path).mkdir(parents=True, exist_ok=True)
if __name__ == "__main__":
main()