Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.admin
Commits
a5d430db
Commit
a5d430db
authored
7 years ago
by
Pavel KORSHUNOV
Browse files
Options
Downloads
Patches
Plain Diff
making bob release script more robust
parent
575a9f25
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
release/release_bob.py
+28
-35
28 additions, 35 deletions
release/release_bob.py
with
28 additions
and
35 deletions
release/release_bob.py
+
28
−
35
View file @
a5d430db
...
...
@@ -233,77 +233,66 @@ def commit_files(gitpkg, files_dict, message='Updated files', dry_run=False):
gitpkg
.
commits
.
create
(
data
)
def
get_last_
nonskip_
pipeline
(
gitpkg
,
before_last
=
False
):
def
get_last_pipeline
(
gitpkg
):
"""
Returns the last
running
pipeline o
r
the
one before the last.
Returns the last pipeline o
f
the
project
Args:
gitpkg: gitlab package object
before_last: If True, the pipeline before the last is returned
Returns: The gtilab object of the pipeline
"""
#
sleep
for 10 seconds to ensure that if a pipeline was just submitted,
#
wait
for 10 seconds to ensure that if a pipeline was just submitted,
# we can retrieve it
time
.
sleep
(
10
)
if
before_last
:
# take the pipeline before the last
return
gitpkg
.
pipelines
.
list
(
per_page
=
2
,
page
=
1
)[
1
]
else
:
# otherwise take the last pipeline
return
gitpkg
.
pipelines
.
list
(
per_page
=
1
,
page
=
1
)[
0
]
# get the last pipeline
return
gitpkg
.
pipelines
.
list
(
per_page
=
1
,
page
=
1
)[
0
]
def
just_build_package
(
gitpkg
,
dry_run
=
False
):
"""
Restrt the last runnabl
e pipeline
of
the
package
Creates th
e pipeline
with
the
latest tag and starts it
Args:
gitpkg: gitlab package object
dry_run: If True, the pipeline will not be
actually restar
ted on GitLab
dry_run: If True, the pipeline will not be
crea
ted on GitLab
Returns:
"""
# we assume the last pipeline is with commit [skip ci]
# so, we take the pipeline that can be re-built, which the previous to the last one
last_pipeline
=
get_last_nonskip_pipeline
(
gitpkg
,
before_last
=
True
)
#
check that the chosen pipeline is the one we are looking for
#
get the latest tag
latest_tag_name
=
'
v
'
+
get_latest_tag_name
(
gitpkg
)
# the pipeline should be the one built for the latest tag, so check if it is the correct choice
if
last_pipeline
.
ref
!=
latest_tag_name
:
raise
ValueError
(
'
While deploying {0}, found pipeline {1} but it does not match
'
'
the latest tag {2}
'
.
format
(
gitpkg
.
name
,
last_pipeline
.
id
,
latest_tag_name
))
# the pipeline should have succeeded, otherwise we cannot release
if
last_pipeline
.
status
!=
'
success
'
:
raise
ValueError
(
'
While deploying {0}, found pipeline {1} but its status is
"
{2}
"
instead
'
'
of the expected
"
sucess
"'
.
format
(
gitpkg
.
name
,
last_pipeline
.
id
,
last_pipeline
.
status
))
print
(
"
Retrying pipeline {0}
"
.
format
(
last_pipeline
.
id
))
# create the pipeline with this tag and start it
print
(
"
Creating and starting pipeline for tag {0}
"
.
format
(
latest_tag_name
))
if
not
dry_run
:
last_pipeline
.
retry
()
new_pipeline
=
gitpkg
.
pipelines
.
create
({
'
ref
'
:
latest_tag_name
})
return
new_pipeline
.
id
return
None
def
wait_for_pipeline_to_finish
(
gitpkg
,
dry_run
=
False
):
def
wait_for_pipeline_to_finish
(
gitpkg
,
pipeline_id
,
dry_run
=
False
):
"""
Using sleep function, wait for the latest pipeline to finish building.
This function pauses the script until pipeline completes either successfully or with error.
Args:
gitpkg: gitlab package object
pipeline_id: id of the pipeline for which we are waiting to finish
dry_run: If True, print log message and exit. There wil be no waiting.
"""
sleep_step
=
30
max_sleep
=
60
*
60
# one hour
pipeline
=
get_last_nonskip_pipeline
(
gitpkg
,
before_last
=
True
)
pipeline_id
=
pipeline
.
id
# pipeline = get_last_pipeline(gitpkg, before_last=before_last)
print
(
'
Waiting for the pipeline {0} of package {1} to finish. Do not interrupt.
'
.
format
(
pipeline_id
,
gitpkg
.
name
))
if
dry_run
:
return
# retrieve the pipeline we are waiting for
pipeline
=
gitpkg
.
pipelines
.
get
(
pipeline_id
)
# probe and wait for the pipeline to finish
slept_so_far
=
0
while
pipeline
.
status
==
'
running
'
or
pipeline
.
status
==
'
pending
'
:
...
...
@@ -330,7 +319,7 @@ def cancel_last_pipeline(gitpkg):
gitpkg: gitlab package object
"""
pipeline
=
get_last_
nonskip_
pipeline
(
gitpkg
)
pipeline
=
get_last_pipeline
(
gitpkg
)
print
(
'
Cancelling the last pipeline {0} of project {1}
'
.
format
(
pipeline
.
id
,
gitpkg
.
name
))
pipeline
.
cancel
()
...
...
@@ -349,7 +338,7 @@ def release_package(gitpkg, tag_name, tag_comments_list, dry_run=False):
# if there is nothing to release, just rebuild the package
if
tag_name
==
'
none
'
:
print
(
"
Since the tag is
'
none
'
, we just re-build the last pipeline
"
)
return
just_build_package
(
gitpkg
)
return
just_build_package
(
gitpkg
,
dry_run
)
# 1. Replace branch tag in Readme to new tag, change version file to new version tag. Add and commit to gitlab
version_number
=
tag_name
[
1
:]
# remove 'v' in front
...
...
@@ -372,6 +361,9 @@ def release_package(gitpkg, tag_name, tag_comments_list, dry_run=False):
# update tag with comments
tag
.
set_release_description
(
'
\n
'
.
join
(
tag_comments_list
))
# get the pipeline that is actually running with no skips
running_pipeline
=
get_last_pipeline
(
gitpkg
)
# 3. Replace branch tag in Readme to master, change version file to beta version tag. Git add, commit, and push.
readme_content
=
_update_readme
(
readme_content
)
major
,
minor
,
patch
=
version_number
.
split
(
'
.
'
)
...
...
@@ -379,6 +371,7 @@ def release_package(gitpkg, tag_name, tag_comments_list, dry_run=False):
# commit and push changes
commit_files
(
gitpkg
,
{
'
README.rst
'
:
readme_content
,
'
version.txt
'
:
version_number
},
'
Increased latest version to %s [skip ci]
'
%
version_number
,
dry_run
)
return
running_pipeline
.
id
def
parse_and_process_package_changelog
(
gl
,
bob_group
,
pkg_name
,
package_changelog
,
dry_run
=
False
):
...
...
@@ -461,9 +454,9 @@ def main(private_token, group_name='bob', changelog_file='changelog.rst', dry_ru
changelog
[
pkgs
[
i
]
+
1
:
pkgs
[
i
+
1
]],
dry_run
)
# release the package with the found tag and its comments
if
gitpkg
:
release_package
(
gitpkg
,
tag
,
tag_comments
,
dry_run
)
pipeline_id
=
release_package
(
gitpkg
,
tag
,
tag_comments
,
dry_run
)
# now, wait for the pipeline to finish, before we can release the next package
wait_for_pipeline_to_finish
(
gitpkg
,
dry_run
)
wait_for_pipeline_to_finish
(
gitpkg
,
pipeline_id
,
dry_run
)
# if package name is provided and resume is not set, process only this package
if
package
==
cur_package_name
and
not
resume
:
...
...
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