xref: /openbmc/openbmc/meta-arm/ci/update-repos (revision 220dafdb)
1#! /usr/bin/env python3
2
3# Update clones of the repositories we need in KAS_REPO_REF_DIR to speed up fetches
4
5import sys
6import os
7import shutil
8import subprocess
9import pathlib
10
11def repo_shortname(url):
12    # Taken from Kas (Repo.__getattr__) to ensure the logic is right
13    from urllib.parse import urlparse
14    url = urlparse(url)
15    return ('{url.netloc}{url.path}'
16            .format(url=url)
17            .replace('@', '.')
18            .replace(':', '.')
19            .replace('/', '.')
20            .replace('*', '.'))
21
22repositories = (
23    "https://git.yoctoproject.org/git/poky",
24    "https://git.openembedded.org/meta-openembedded",
25    "https://git.yoctoproject.org/git/meta-virtualization",
26    "https://github.com/kraj/meta-clang",
27)
28
29if __name__ == "__main__":
30    if "KAS_REPO_REF_DIR" not in os.environ:
31        print("KAS_REPO_REF_DIR needs to be set")
32        sys.exit(1)
33
34    base_repodir = pathlib.Path(os.environ["KAS_REPO_REF_DIR"])
35    failed = False
36
37    for repo in repositories:
38        repodir = base_repodir / repo_shortname(repo)
39
40        if "CI_CLEAN_REPOS" in os.environ:
41            print("Cleaning %s..." % repo)
42            shutil.rmtree(repodir, ignore_errors=True)
43
44        if repodir.exists():
45            try:
46                print("Updating %s..." % repo)
47                subprocess.run(["git", "-C", repodir, "-c", "gc.autoDetach=false", "fetch"], check=True)
48            except subprocess.CalledProcessError as e:
49                print(e)
50                failed = True
51        else:
52            print("Cloning %s..." % repo)
53            subprocess.run(["git", "clone", "--bare", repo, repodir], check=True)
54
55    if failed:
56        sys.exit(128)
57