mirror of
https://git.yoctoproject.org/meta-arm
synced 2026-01-12 03:10:15 +00:00
The update-repos script currently exits immediately if one of the underlying Git commands fails (e.g. because of a network issue). If the repo already exists, then catch this error inside the loop and carrying on attempting to update other repos, as the network error may be upstream. KAS_REPO_REF_DIR is ultimately an optimization and subsequent build stages should be able to continue if one of the updates fail. Therefore, ensure the script returns a special error code if at least of the Git commands fail, and use this to set the allow_failure property of the job. If a repo does not exist, fail immediately as before. Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com> Signed-off-by: Jon Mason <jon.mason@arm.com>
57 lines
1.6 KiB
Python
Executable File
57 lines
1.6 KiB
Python
Executable File
#! /usr/bin/env python3
|
|
|
|
# Update clones of the repositories we need in KAS_REPO_REF_DIR to speed up fetches
|
|
|
|
import sys
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import pathlib
|
|
|
|
def repo_shortname(url):
|
|
# Taken from Kas (Repo.__getattr__) to ensure the logic is right
|
|
from urllib.parse import urlparse
|
|
url = urlparse(url)
|
|
return ('{url.netloc}{url.path}'
|
|
.format(url=url)
|
|
.replace('@', '.')
|
|
.replace(':', '.')
|
|
.replace('/', '.')
|
|
.replace('*', '.'))
|
|
|
|
repositories = (
|
|
"https://git.yoctoproject.org/git/poky",
|
|
"https://git.openembedded.org/meta-openembedded",
|
|
"https://git.yoctoproject.org/git/meta-virtualization",
|
|
"https://github.com/kraj/meta-clang",
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
if "KAS_REPO_REF_DIR" not in os.environ:
|
|
print("KAS_REPO_REF_DIR needs to be set")
|
|
sys.exit(1)
|
|
|
|
base_repodir = pathlib.Path(os.environ["KAS_REPO_REF_DIR"])
|
|
failed = False
|
|
|
|
for repo in repositories:
|
|
repodir = base_repodir / repo_shortname(repo)
|
|
|
|
if "CI_CLEAN_REPOS" in os.environ:
|
|
print("Cleaning %s..." % repo)
|
|
shutil.rmtree(repodir, ignore_errors=True)
|
|
|
|
if repodir.exists():
|
|
try:
|
|
print("Updating %s..." % repo)
|
|
subprocess.run(["git", "-C", repodir, "-c", "gc.autoDetach=false", "fetch"], check=True)
|
|
except subprocess.CalledProcessError as e:
|
|
print(e)
|
|
failed = True
|
|
else:
|
|
print("Cloning %s..." % repo)
|
|
subprocess.run(["git", "clone", "--bare", repo, repodir], check=True)
|
|
|
|
if failed:
|
|
sys.exit(128)
|