Files
why3/update-submodule.py

44 lines
1.4 KiB
Python
Raw Permalink Normal View History

2025-09-01 09:57:34 +09:00
from e3.auth.gitlab import gen_gitlab_token
import gitlab
import os
2025-11-10 10:05:58 +09:00
# This script assumes that another project (hardcoded here as
# "eng/spark/spark2014") has a submodule pointing to our project. The purpose
# of this script is to create a merge request in that other project, that
# updates the submodule information to the current commit SHA.
2025-11-10 09:53:05 +09:00
base_url = os.environ["CI_SERVER_URL"]
2025-09-01 09:57:34 +09:00
project_name = "eng/spark/spark2014"
2025-11-10 09:53:05 +09:00
target_commit = os.environ["CI_COMMIT_SHORT_SHA"]
target_commit_long = os.environ["CI_COMMIT_SHA"]
target_branch = os.environ["CI_COMMIT_REF_NAME"]
2025-09-01 09:57:34 +09:00
commit_message = "Automatic submodule commit"
mr_title = "Automatic submodule commit"
mr_body = "no-issue-check"
2025-11-10 09:53:05 +09:00
2025-09-01 09:57:34 +09:00
def main():
gl = gitlab.Gitlab(base_url, private_token=gen_gitlab_token()["token"])
project = gl.projects.get(project_name)
mr_branch = f"automated-submodule-update-{target_commit}"
2025-11-11 20:16:58 +09:00
project.branches.create({"branch": mr_branch, "ref": target_branch})
2025-11-10 09:53:05 +09:00
project.update_submodule(
"why3", mr_branch, target_commit_long, commit_message=commit_message
)
mr = project.mergerequests.create(
{
"source_branch": mr_branch,
2025-11-11 20:16:58 +09:00
"target_branch": target_branch,
2025-11-10 09:53:05 +09:00
"title": mr_title,
"description": mr_body,
"labels": ["skip-ci"]
2025-11-10 09:53:05 +09:00
}
)
print(f"Merge request created: {mr.web_url}")
mr.approve()
2025-09-01 09:57:34 +09:00
if __name__ == "__main__":
main()