Skip to content

Commit 848a78f

Browse files
committed
Merge branch 'topic/update-submodule' into 'master'
Automatic submodule commit For eng/spark/spark2014#338 See merge request eng/spark/why3!95
2 parents c8134ce + 0c77e28 commit 848a78f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

.adacore.gitlab-ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ stages:
2020

2121
.common_test:
2222
stage: build
23+
interruptible: true
2324
rules:
2425
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_PIPELINE_SOURCE == "schedule"
2526
when: always
@@ -47,3 +48,17 @@ windows:
4748
- cpu:2
4849
- mem:4
4950
- disk:100
51+
52+
submodule:
53+
stage: build
54+
interruptible: true
55+
rules:
56+
- if: ($CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_PROTECTED == "true")
57+
when: always
58+
- when: never
59+
services:
60+
- image:pe-base
61+
- cpu:2
62+
script:
63+
- python update-submodule.py
64+

update-submodule.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from e3.auth.gitlab import gen_gitlab_token
2+
import gitlab
3+
import os
4+
5+
# This script assumes that another project (hardcoded here as
6+
# "eng/spark/spark2014") has a submodule pointing to our project. The purpose
7+
# of this script is to create a merge request in that other project, that
8+
# updates the submodule information to the current commit SHA.
9+
10+
base_url = os.environ["CI_SERVER_URL"]
11+
project_name = "eng/spark/spark2014"
12+
target_commit = os.environ["CI_COMMIT_SHORT_SHA"]
13+
target_commit_long = os.environ["CI_COMMIT_SHA"]
14+
target_branch = os.environ["CI_COMMIT_REF_NAME"]
15+
commit_message = "Automatic submodule commit"
16+
mr_title = "Automatic submodule commit"
17+
mr_body = "no-issue-check"
18+
19+
20+
def main():
21+
22+
gl = gitlab.Gitlab(base_url, private_token=gen_gitlab_token()["token"])
23+
project = gl.projects.get(project_name)
24+
mr_branch = f"automated-submodule-update-{target_commit}"
25+
project.branches.create({"branch": mr_branch, "ref": target_branch.name})
26+
project.update_submodule(
27+
"why3", mr_branch, target_commit_long, commit_message=commit_message
28+
)
29+
mr = project.mergerequests.create(
30+
{
31+
"source_branch": mr_branch,
32+
"target_branch": target_branch.name,
33+
"title": mr_title,
34+
"description": mr_body,
35+
}
36+
)
37+
print(f"Merge request created: {mr.web_url}")
38+
39+
40+
if __name__ == "__main__":
41+
main()

0 commit comments

Comments
 (0)