Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize git submodules automatically #114

Open
Biswa96 opened this issue May 16, 2023 · 0 comments
Open

Synchronize git submodules automatically #114

Biswa96 opened this issue May 16, 2023 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Biswa96
Copy link
Collaborator

Biswa96 commented May 16, 2023

I use a python script to shallow clone the git submodules manually. I wonder if it is possible to use GitHub Actions for that.

Click here to see the python script
#!/usr/bin/env python
# https://github.com/KuYaki/gitmodules/blob/master/gitmodules/gitmodules.py

"""
Clone a specific tag of git submodules with .gitmodules file
"""

import base64
import os
import sys
import subprocess
import requests

cwd = sys.path[0]
git_modules_file_path = os.path.join(cwd, ".gitmodules")
git_tag = "platform-tools-34.0.1"

if os.path.exists(git_modules_file_path):
    with open(git_modules_file_path) as f:
        path = None
        url = None
        for line in f.readlines():
            if "path = " in line:
                path = line.split("path = ")[-1][:-1]
            if "url = " in line:
                url = line.split("url = ")[-1][:-1]
            if path and url:
                if "boringssl" in path:
                    boring_url = f'https://android.googlesource.com/platform/external/boringssl/+/refs/tags/{git_tag}/BORINGSSL_REVISION?format=TEXT'
                    boring_sha = str(base64.b64decode(requests.get(boring_url, timeout=30).text), 'UTF-8').strip("\n")
                    print(f'git clone --filter=blob:none https://boringssl.googlesource.com/boringssl.git {path}')
                    subprocess.run(f'git clone --filter=blob:none https://boringssl.googlesource.com/boringssl.git {path}'.split(), check=True)
                    previous_dir = os.getcwd()
                    os.chdir(path)
                    print(f'git checkout {boring_sha}')
                    subprocess.run(f'git checkout {boring_sha}'.split(), check=True)
                    os.chdir(previous_dir)
                else:
                    print(f'git clone --depth=1 {url} {path} -b {git_tag}')
                    subprocess.run(f'git clone --depth=1 {url} {path} -b {git_tag}'.split(), check=True)
                path = None
                url = None

⚠️ Seek medical advice after seeing the python code.

  • What I can not do yet

    • Write correct python script.
    • Pass the submodules tag version to python script.
  • What I can try to do but need some guidance

    • Plug that python script in cmake with custom target.
    • Run that custom target in CI when invoked manually.
  • The plan

    • The python script will shallow clone each submodules using the .gitignore. The boringssl repository is an exception there as mentioned in cmake file.
    • After cloning, git diff --exit-code vendor command will check if there is any change.
    • If yes, tell developer to update submodules. Or CI can commit the changes when we become confident about that.
    • If there is no change in vendor directory, compile the project as usual.

Please share your ideas and thoughts about this.

@Biswa96 Biswa96 added enhancement New feature or request help wanted Extra attention is needed labels Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant