Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gitlab-ci
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Clea OS
infrastructure
gitlab-ci
Commits
06d89fc6
Commit
06d89fc6
authored
3 years ago
by
Jonas Höppner
Browse files
Options
Downloads
Patches
Plain Diff
CI: deploy-gitlab-ci: Cleanup
parent
5c3ac7a2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
deploy_gitlab_ci.py
+52
-48
52 additions, 48 deletions
deploy_gitlab_ci.py
with
52 additions
and
48 deletions
deploy_gitlab_ci.py
+
52
−
48
View file @
06d89fc6
...
@@ -6,7 +6,8 @@ import logging
...
@@ -6,7 +6,8 @@ import logging
import
sys
import
sys
import
os
import
os
from
gitlab
import
Gitlab
from
gitlab
import
Gitlab
from
accept_merge_request
import
accept_merge_request
# from accept_merge_request import accept_merge_request
from
create_merge_request
import
create_merge_request
from
create_merge_request
import
create_merge_request
from
get_merge_requests
import
get_merge_requests
from
get_merge_requests
import
get_merge_requests
from
update_submodule
import
update_submodule
from
update_submodule
import
update_submodule
...
@@ -100,7 +101,9 @@ def update_rev_in_gitlab_ci(repo, submodule_project, submodule_revision):
...
@@ -100,7 +101,9 @@ def update_rev_in_gitlab_ci(repo, submodule_project, submodule_revision):
logging
.
debug
(
fp
.
read
())
logging
.
debug
(
fp
.
read
())
def
deploy_into
(
project
,
submodule
,
revision
,
branch
,
replace_existing_branch
=
False
):
def
deploy_into
(
project
,
submodule
,
revision
,
branch
,
replace_existing_branch
=
False
,
create_mr
=
False
):
"""
Update the submodule and include refs to the submodule in the given project.
"""
Update the submodule and include refs to the submodule in the given project.
Create mergerequest if needed.
Create mergerequest if needed.
...
@@ -116,7 +119,7 @@ def deploy_into(project, submodule, revision, branch, replace_existing_branch=Fa
...
@@ -116,7 +119,7 @@ def deploy_into(project, submodule, revision, branch, replace_existing_branch=Fa
merge_request (gitlab mr): Mergerequest for the integration branch
merge_request (gitlab mr): Mergerequest for the integration branch
"""
"""
# Update submodule
# Update submodule
integration_branch
,
_
,
submodule_project
=
update_submodule
(
integration_branch
,
integration_commit
,
submodule_project
=
update_submodule
(
project
,
project
,
submodule
,
submodule
,
revision
,
revision
,
...
@@ -125,11 +128,13 @@ def deploy_into(project, submodule, revision, branch, replace_existing_branch=Fa
...
@@ -125,11 +128,13 @@ def deploy_into(project, submodule, revision, branch, replace_existing_branch=Fa
replace_existing_branch
=
replace_existing_branch
,
replace_existing_branch
=
replace_existing_branch
,
)
)
logging
.
debug
(
"
Integration branch: %s
"
,
integration_branch
)
logging
.
debug
(
"
Integration branch:
%s,
%s
"
,
integration_branch
,
integration_commit
)
# If submodule is already at specified revision, return directly
# If submodule is already at specified revision, return directly
if
not
integration_branch
:
if
not
integration_branch
or
not
create_mr
:
return
None
,
submodule_project
# No commit needed as the submodule is already up to date (integration_branch == None)
# Or we are done, because no merge request is needed yet
return
integration_branch
,
integration_commit
,
None
# Get source merge request
# Get source merge request
mrs
=
get_merge_requests
(
mrs
=
get_merge_requests
(
...
@@ -145,6 +150,7 @@ def deploy_into(project, submodule, revision, branch, replace_existing_branch=Fa
...
@@ -145,6 +150,7 @@ def deploy_into(project, submodule, revision, branch, replace_existing_branch=Fa
source_mr
=
mrs
[
0
]
source_mr
=
mrs
[
0
]
# Create merge request
# Create merge request
# This should be optional
mr
,
created
=
create_merge_request
(
mr
,
created
=
create_merge_request
(
project
,
integration_branch
,
project
.
default_branch
project
,
integration_branch
,
project
.
default_branch
)
)
...
@@ -153,7 +159,7 @@ def deploy_into(project, submodule, revision, branch, replace_existing_branch=Fa
...
@@ -153,7 +159,7 @@ def deploy_into(project, submodule, revision, branch, replace_existing_branch=Fa
print
(
"
Created new merge request:
\n
%s
"
%
mr
.
web_url
)
print
(
"
Created new merge request:
\n
%s
"
%
mr
.
web_url
)
else
:
else
:
print
(
"
Existing integration merge request:
\n
%s
"
%
mr
.
web_url
)
print
(
"
Existing integration merge request:
\n
%s
"
%
mr
.
web_url
)
return
integration_branch
,
mr
return
integration_branch
,
integration_commit
,
mr
def
main
():
def
main
():
...
@@ -221,38 +227,35 @@ def main():
...
@@ -221,38 +227,35 @@ def main():
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
gitlab
=
Gitlab
(
args
.
gitlab_url
,
private_token
=
args
.
token
)
gitlab
=
Gitlab
(
args
.
gitlab_url
,
private_token
=
args
.
token
)
project
=
common
.
get_project
(
gitlab
,
args
.
project
)
logging
.
debug
(
"
Integrate into: %s
"
,
args
.
project
)
# Update submodule in this project, create MR
integration_branch
,
mr
=
deploy_into
(
project
,
args
.
submodule
,
args
.
revision
,
args
.
branch
,
replace_existing_branch
=
len
(
args
.
projects
)
>
0
,
)
merge_request_manifest
=
mr
merge_requests
=
[]
# If submodule is already at specified revision, exit successfully
project_integration
=
{}
if
not
integration_branch
:
# Update submodule in this project, create MR if needed TODO
sys
.
exit
(
0
)
for
p
in
args
.
projects
+
[
args
.
project
]:
for
p
in
args
.
projects
:
gitlab_p
=
common
.
get_project
(
gitlab
,
p
)
logging
.
debug
(
"
Integrate into: %s
"
,
p
)
logging
.
debug
(
"
Integrate into: %s
"
,
p
)
integration_branch
,
mr
=
deploy_into
(
gitlab_project
=
common
.
get_project
(
gitlab
,
p
)
gitlab_p
,
integration_branch
,
integration_commit
,
mr
=
deploy_into
(
gitlab_project
,
args
.
submodule
,
args
.
submodule
,
args
.
revision
,
args
.
revision
,
args
.
branch
,
args
.
branch
,
replace_existing_branch
=
len
(
args
.
projects
)
>
0
,
)
)
merge_requests
.
append
(
mr
)
if
integration_branch
is
not
None
:
project_integration
[
p
]
=
{
"
project
"
:
gitlab_project
,
"
mr
"
:
mr
,
"
branch
"
:
integration_branch
,
"
commit
"
:
integration_commit
,
}
logging
.
debug
(
"
Integration branch: %s (%s)
"
,
integration_branch
,
integration_commit
)
logging
.
debug
(
"
Integration branch: %s
"
,
integration_branch
)
# If submodule is already at specified revision in all projects, exit successfully
if
not
len
(
project_integration
)
==
0
:
sys
.
exit
(
0
)
if
not
args
.
merge
:
if
not
args
.
merge
:
print
(
print
(
...
@@ -264,23 +267,24 @@ def main():
...
@@ -264,23 +267,24 @@ def main():
sys
.
exit
(
0
)
sys
.
exit
(
0
)
# The manifest needs to be merged at last
# The manifest needs to be merged at last
merge_requests
.
append
(
merge_request_manifest
)
# TODO this is currently not used
for
mr
in
merge_requests
:
# merge_requests.append(merge_request_manifest)
logging
.
debug
(
"
Merge %s
"
,
mr
)
# for mr in merge_requests:
# Wait until GitLab has checked merge status
# logging.debug("Merge %s", mr)
common
.
wait_until_merge_status_is_set
(
project
,
mr
)
# # Wait until GitLab has checked merge status
# common.wait_until_merge_status_is_set(project, mr)
# Attempt to merge
merged
=
accept_merge_request
(
project
,
mr
,
rebase
=
True
)
# # Attempt to merge
# merged = accept_merge_request(project, mr, rebase=True)
if
not
merged
:
sys
.
exit
(
# if not merged:
"
Integration MR could not be merged. You have two possibilities to fix
"
# sys.exit(
"
this:
\n
"
# "Integration MR could not be merged. You have two possibilities to fix "
"
1. Checkout the MR and rebase it on the current master manually, or
\n
"
# "this:\n"
"
2. Delete the MR (Edit -> Delete in the MR UI)
\n
"
# " 1. Checkout the MR and rebase it on the current master manually, or\n"
"
In either case restart this job afterwards in order to get it merged.
"
# " 2. Delete the MR (Edit -> Delete in the MR UI)\n"
)
# "In either case restart this job afterwards in order to get it merged."
# )
print
(
"
Successfully merged
"
)
print
(
"
Successfully merged
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment