blob: 069a94ea98dfd6cea3cf6b423f4c3c615f0e53fb [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001#! /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
Andrew Geissler2daf84b2023-03-31 09:57:23 -05007import shutil
Brad Bishopbec4ebc2022-08-03 09:55:16 -04008import 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",
Brad Bishopbec4ebc2022-08-03 09:55:16 -040026 "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"])
Andrew Geissler220dafd2023-10-04 10:18:08 -050035 failed = False
Brad Bishopbec4ebc2022-08-03 09:55:16 -040036
37 for repo in repositories:
38 repodir = base_repodir / repo_shortname(repo)
Andrew Geissler2daf84b2023-03-31 09:57:23 -050039
40 if "CI_CLEAN_REPOS" in os.environ:
41 print("Cleaning %s..." % repo)
42 shutil.rmtree(repodir, ignore_errors=True)
43
Brad Bishopbec4ebc2022-08-03 09:55:16 -040044 if repodir.exists():
Andrew Geissler220dafd2023-10-04 10:18:08 -050045 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
Brad Bishopbec4ebc2022-08-03 09:55:16 -040051 else:
52 print("Cloning %s..." % repo)
53 subprocess.run(["git", "clone", "--bare", repo, repodir], check=True)
Andrew Geissler220dafd2023-10-04 10:18:08 -050054
55 if failed:
56 sys.exit(128)