Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Managetests
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gruppo Web
Managetests
Commits
5c457290
Commit
5c457290
authored
Dec 09, 2016
by
Pietro Albini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for reporting build status to GitLab
Fixes:
#2
parent
68f3d069
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
5 deletions
+74
-5
managetests/__main__.py
managetests/__main__.py
+2
-0
managetests/app.py
managetests/app.py
+9
-2
managetests/branches.py
managetests/branches.py
+42
-2
managetests/gitlab.py
managetests/gitlab.py
+20
-0
managetests/utils.py
managetests/utils.py
+1
-1
No files found.
managetests/__main__.py
View file @
5c457290
...
@@ -83,6 +83,8 @@ def init_command(ctx, git_url):
...
@@ -83,6 +83,8 @@ def init_command(ctx, git_url):
with
(
root
/
"config.json"
).
open
(
"w"
)
as
f
:
with
(
root
/
"config.json"
).
open
(
"w"
)
as
f
:
content
=
{
content
=
{
"base-url"
:
"http://wwwtest.ubuntu-it.org"
,
"update-commit-status"
:
False
,
"git-url"
:
git_url
,
"git-url"
:
git_url
,
"gitlab-url"
:
"http://code.ubuntu-it.org"
,
"gitlab-url"
:
"http://code.ubuntu-it.org"
,
"gitlab-project"
:
"ubuntu-it-web/www"
,
"gitlab-project"
:
"ubuntu-it-web/www"
,
...
...
managetests/app.py
View file @
5c457290
...
@@ -84,14 +84,19 @@ class TestsManager:
...
@@ -84,14 +84,19 @@ class TestsManager:
def
sync_branches_jobs
(
self
):
def
sync_branches_jobs
(
self
):
"""Get the jobs needed to sync branches"""
"""Get the jobs needed to sync branches"""
jobs
=
[]
for
branch
in
list
(
self
.
branches
.
values
()):
for
branch
in
list
(
self
.
branches
.
values
()):
if
branch
.
active
:
if
branch
.
active
:
if
not
branch
.
present
():
if
not
branch
.
present
():
# Set the branch status to "pending"
branch
.
update_status
(
"pending"
)
# Deploy the branch and load it
# Deploy the branch and load it
def
deploy
(
branch
=
branch
):
def
deploy
(
branch
=
branch
):
branch
.
deploy
()
branch
.
deploy
()
self
.
instances
.
load_branch
(
branch
)
self
.
instances
.
load_branch
(
branch
)
yield
deploy
jobs
.
append
(
deploy
)
else
:
else
:
if
branch
.
present
():
if
branch
.
present
():
# Unload the branch, destroy and forget about it
# Unload the branch, destroy and forget about it
...
@@ -102,7 +107,9 @@ class TestsManager:
...
@@ -102,7 +107,9 @@ class TestsManager:
if
branch
.
name
in
self
.
details
[
"branches"
]:
if
branch
.
name
in
self
.
details
[
"branches"
]:
del
self
.
details
[
"branches"
]
del
self
.
details
[
"branches"
]
self
.
save_details
()
self
.
save_details
()
yield
destroy
jobs
.
append
(
destroy
)
return
jobs
def
save_details
(
self
):
def
save_details
(
self
):
"""Save details on disk"""
"""Save details on disk"""
...
...
managetests/branches.py
View file @
5c457290
...
@@ -135,10 +135,17 @@ class Branch:
...
@@ -135,10 +135,17 @@ class Branch:
file
=
self
.
manager
.
root
/
"branches"
/
self
.
name
/
"commit"
file
=
self
.
manager
.
root
/
"branches"
/
self
.
name
/
"commit"
if
file
.
exists
():
if
file
.
exists
():
if
hasattr
(
self
,
"_gitlab_commit_cache"
):
delattr
(
self
,
"_gitlab_commit_cache"
)
with
file
.
open
()
as
f
:
with
file
.
open
()
as
f
:
return
f
.
read
().
strip
()
return
f
.
read
().
strip
()
else
:
else
:
return
""
# Ask GitLab about the commit
if
not
hasattr
(
self
,
"_gitlab_commit_cache"
):
self
.
_gitlab_commit_cache
=
self
.
manager
.
gitlab
\
.
branch_commit
(
self
.
name
)
return
self
.
_gitlab_commit_cache
def
commit_url
(
self
):
def
commit_url
(
self
):
"""Get the URL of a commit"""
"""Get the URL of a commit"""
...
@@ -216,7 +223,7 @@ class Branch:
...
@@ -216,7 +223,7 @@ class Branch:
def
log
(
msg
):
def
log
(
msg
):
"""Utility function to log a message to the build log"""
"""Utility function to log a message to the build log"""
with
log_file
.
open
(
"a"
)
as
f
:
with
log_file
.
open
(
"a"
)
as
f
:
f
.
write
(
msg
)
f
.
write
(
msg
+
"
\
n
"
)
# Create subdirectories
# Create subdirectories
build_dir
.
mkdir
()
build_dir
.
mkdir
()
...
@@ -238,6 +245,8 @@ class Branch:
...
@@ -238,6 +245,8 @@ class Branch:
self
.
name
self
.
name
],
stdout
=
commit_file
.
open
(
"w"
),
stderr
=
log_file
.
open
(
"a"
))
],
stdout
=
commit_file
.
open
(
"w"
),
stderr
=
log_file
.
open
(
"a"
))
self
.
update_status
(
"running"
)
# Copy and load the configuration file
# Copy and load the configuration file
if
not
(
build_dir
/
"managetests.json"
).
exists
():
if
not
(
build_dir
/
"managetests.json"
).
exists
():
log
(
"[!] No managetests.json found in the branch!"
)
log
(
"[!] No managetests.json found in the branch!"
)
...
@@ -272,6 +281,15 @@ class Branch:
...
@@ -272,6 +281,15 @@ class Branch:
if
total
==
0
:
if
total
==
0
:
log
(
"[!] Warning: no artifact was installed!"
)
log
(
"[!] Warning: no artifact was installed!"
)
# Check if the branch was successifully built
popen_args
=
self
.
command_popen_args
(
self
.
config
[
"run"
])
if
os
.
path
.
exists
(
popen_args
[
0
][
0
][
0
]):
log
(
"[!] Info: build seems to be successful"
)
self
.
update_status
(
"success"
)
else
:
log
(
"[!] Warning: build seems to have failed"
)
self
.
update_status
(
"failed"
)
# Delete the build directory
# Delete the build directory
shutil
.
rmtree
(
str
(
build_dir
))
shutil
.
rmtree
(
str
(
build_dir
))
...
@@ -291,8 +309,30 @@ class Branch:
...
@@ -291,8 +309,30 @@ class Branch:
ignore_errors
=
True
ignore_errors
=
True
)
)
# Delete the commit cache
if
hasattr
(
self
,
"_gitlab_commit_cache"
):
delattr
(
self
,
"_gitlab_commit_cache"
)
try
:
try
:
del
self
.
manager
.
details
[
"branches"
][
self
.
name
]
del
self
.
manager
.
details
[
"branches"
][
self
.
name
]
except
KeyError
:
except
KeyError
:
pass
pass
self
.
manager
.
save_details
()
self
.
manager
.
save_details
()
def
update_status
(
self
,
state
,
log
=
True
):
"""Update the commit status"""
# Don't update status hooks on development instances
if
not
self
.
manager
.
config
[
"update-commit-status"
]:
return
if
log
:
url
=
"%s/+logs/%s/build.log"
%
(
self
.
manager
.
config
[
"base-url"
],
self
.
name
)
else
:
url
=
None
# Update the commit status in GitLab
self
.
manager
.
gitlab
.
commit_status
(
self
.
commit
(),
state
,
self
.
name
,
url
)
managetests/gitlab.py
View file @
5c457290
...
@@ -66,3 +66,23 @@ class GitLabAPI:
...
@@ -66,3 +66,23 @@ class GitLabAPI:
"""Post a comment on a merge request"""
"""Post a comment on a merge request"""
return
self
.
call
(
"post"
,
"projects/%s/merge_request/%s/comments"
%
(
return
self
.
call
(
"post"
,
"projects/%s/merge_request/%s/comments"
%
(
self
.
project
,
id
),
data
=
{
"note"
:
text
})
self
.
project
,
id
),
data
=
{
"note"
:
text
})
def
commit_status
(
self
,
commit
,
state
,
ref
,
url
=
None
):
"""Update the status of a commit"""
data
=
{
"state"
:
state
,
"ref"
:
ref
,
"name"
:
"managetests"
,
}
if
url
is
not
None
:
data
[
"target_url"
]
=
url
return
self
.
call
(
"post"
,
"projects/%s/statuses/%s"
%
(
self
.
project
,
commit
),
data
=
data
)
def
branch_commit
(
self
,
branch
):
"""Get the commit ID of a branch"""
return
self
.
call
(
"get"
,
"projects/%s/repository/branches/%s"
%
(
self
.
project
,
branch
))[
"commit"
][
"id"
]
managetests/utils.py
View file @
5c457290
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
import
pathlib
import
pathlib
ROOT_DIR_VERSION
=
"
2
"
ROOT_DIR_VERSION
=
"
3
"
def
is_root_valid
(
path
):
def
is_root_valid
(
path
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment