2017-12-19 17:03:51 +01:00
|
|
|
import json
|
|
|
|
import requests
|
2018-03-10 22:46:33 +01:00
|
|
|
import datetime
|
2017-12-19 17:03:51 +01:00
|
|
|
|
2018-01-29 03:39:04 +01:00
|
|
|
from .. import db
|
2018-11-05 17:17:03 +01:00
|
|
|
from app.models.applists import App
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
class AppCIBranch(db.Model):
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.String(64), unique=True, nullable=False)
|
2018-11-02 01:30:50 +01:00
|
|
|
arch = db.Column(db.String(64), nullable=False)
|
|
|
|
branch = db.Column(db.String(64), nullable=False)
|
2017-12-19 17:03:51 +01:00
|
|
|
display_name = db.Column(db.String(64), unique=True, nullable=False)
|
|
|
|
url = db.Column(db.String(128), nullable=False)
|
2018-12-12 17:33:24 +01:00
|
|
|
url_per_app = db.Column(db.String(128), nullable=False)
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return '<AppCIBranch %r>' % self.name
|
|
|
|
|
|
|
|
def init():
|
|
|
|
yield AppCIBranch(name='stable',
|
2018-11-02 01:30:50 +01:00
|
|
|
arch="x86",
|
|
|
|
branch="stable",
|
2017-12-19 17:03:51 +01:00
|
|
|
display_name='Stable (x86)',
|
2018-11-02 01:30:50 +01:00
|
|
|
url='https://ci-apps.yunohost.org/ci/logs/list_level_stable.json',
|
2018-12-12 17:33:24 +01:00
|
|
|
url_per_app='https://ci-apps.yunohost.org/ci/apps/{}/')
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
yield AppCIBranch(name='arm',
|
2018-11-02 01:30:50 +01:00
|
|
|
arch="arm",
|
|
|
|
branch="stable",
|
2017-12-19 17:03:51 +01:00
|
|
|
display_name='Stable (ARM)',
|
2018-11-02 01:30:50 +01:00
|
|
|
url='https://ci-apps-arm.yunohost.org/ci/logs/list_level_stable.json',
|
2018-12-12 17:33:24 +01:00
|
|
|
url_per_app='https://ci-apps-arm.yunohost.org/ci/apps/{}/')
|
2017-12-19 17:03:51 +01:00
|
|
|
|
2019-04-16 17:26:36 +02:00
|
|
|
yield AppCIBranch(name='testing',
|
|
|
|
arch="x86",
|
|
|
|
branch="testing",
|
|
|
|
display_name='Testing (x86)',
|
|
|
|
url='https://ci-apps-unstable.yunohost.org/ci/logs/list_level_testing.json',
|
|
|
|
url_per_app='https://ci-apps-unstable.yunohost.org/ci/apps/{}/')
|
|
|
|
|
2019-01-25 16:44:55 +01:00
|
|
|
yield AppCIBranch(name='unstable',
|
|
|
|
arch="x86",
|
|
|
|
branch="unstable",
|
|
|
|
display_name='Unstable (x86)',
|
|
|
|
url='https://ci-apps-unstable.yunohost.org/ci/logs/list_level_unstable.json',
|
|
|
|
url_per_app='https://ci-apps-unstable.yunohost.org/ci/apps/{}/')
|
|
|
|
|
2017-12-19 17:03:51 +01:00
|
|
|
def last_build_url(self, app):
|
2018-12-12 17:33:24 +01:00
|
|
|
return self.url_per_app.format(app.name)
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
def most_recent_tests_per_app(self):
|
|
|
|
|
2018-11-05 16:58:15 +01:00
|
|
|
apps = App.query.filter_by(ci_enabled=True).all()
|
2019-01-22 17:07:00 +01:00
|
|
|
most_recent_tests = AppCIResult.query \
|
|
|
|
.filter_by(branch = self) \
|
2019-04-29 22:29:56 +02:00
|
|
|
.order_by(AppCIResult.date.desc()) \
|
2019-01-22 17:07:00 +01:00
|
|
|
.all()
|
|
|
|
|
2017-12-19 17:03:51 +01:00
|
|
|
for app in apps:
|
2019-01-22 17:07:00 +01:00
|
|
|
most_recent_test = [ t for t in most_recent_tests if t.app == app ]
|
2017-12-19 17:03:51 +01:00
|
|
|
if most_recent_test:
|
2019-01-22 17:07:00 +01:00
|
|
|
yield most_recent_test[0]
|
2018-11-02 02:07:16 +01:00
|
|
|
else:
|
|
|
|
yield AppCIResult(app = app,
|
|
|
|
branch = self,
|
|
|
|
level = None,
|
|
|
|
date = datetime.datetime.fromtimestamp(0),
|
2018-11-08 14:48:35 +01:00
|
|
|
results = { t:None for t in AppCI.tests })
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AppCIResult(db.Model):
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
|
|
|
|
app = db.relationship(App, backref='tests', lazy=True, uselist=False)
|
|
|
|
branch = db.relationship(AppCIBranch, backref='tests', lazy=True, uselist=False)
|
|
|
|
|
|
|
|
app_id = db.Column(db.ForeignKey(App.id))
|
|
|
|
branch_id = db.Column(db.ForeignKey(AppCIBranch.id))
|
|
|
|
|
|
|
|
results = db.Column(db.PickleType)
|
|
|
|
|
2018-02-26 14:46:51 +01:00
|
|
|
date = db.Column(db.DateTime, nullable=True)
|
|
|
|
level = db.Column(db.Integer, nullable=True)
|
2018-11-02 01:30:50 +01:00
|
|
|
url = db.Column(db.String(128), nullable=True)
|
2018-02-26 14:46:51 +01:00
|
|
|
commit = db.Column(db.String(64), nullable=True)
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
def __repr__(self):
|
2019-05-14 19:00:37 +02:00
|
|
|
return '<AppCIResult %s>' % self.date
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
def init():
|
|
|
|
pass
|
|
|
|
|
|
|
|
def score(self):
|
|
|
|
s_dict = { True: +1, False: -1, None: 0 }
|
2018-11-08 14:48:35 +01:00
|
|
|
return sum([ s_dict[result] for result in self.results.values() ])
|
2017-12-19 17:03:51 +01:00
|
|
|
|
2020-09-03 19:33:59 +02:00
|
|
|
@property
|
|
|
|
def outdated(self):
|
2020-11-07 18:55:59 +01:00
|
|
|
return (datetime.datetime.now() - self.date).days > 30
|
2020-09-03 19:33:59 +02:00
|
|
|
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
class AppCI():
|
|
|
|
|
|
|
|
tests = [ "Package linter",
|
|
|
|
"Installation",
|
|
|
|
"Deleting",
|
|
|
|
"Installation in a sub path",
|
|
|
|
"Deleting from a sub path",
|
|
|
|
"Installation on the root",
|
|
|
|
"Deleting from root",
|
2019-03-01 11:28:57 +01:00
|
|
|
"Upgrade",
|
2017-12-19 17:03:51 +01:00
|
|
|
"Installation in private mode",
|
|
|
|
"Installation in public mode",
|
|
|
|
"Multi-instance installations",
|
|
|
|
"Malformed path",
|
2019-03-01 11:28:57 +01:00
|
|
|
"Port already used",
|
|
|
|
"Backup",
|
|
|
|
"Restore",
|
|
|
|
"Change URL" ]
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
def update():
|
|
|
|
|
|
|
|
cibranches = AppCIBranch.query.all()
|
|
|
|
|
|
|
|
# Scrap jenkins
|
2018-11-02 01:30:50 +01:00
|
|
|
for cibranch in cibranches:
|
|
|
|
print("> Fetching current CI results for C.I. branch {}".format(cibranch.name))
|
2020-04-15 03:55:50 +02:00
|
|
|
try:
|
|
|
|
result_json = requests.get(cibranch.url).text
|
|
|
|
except:
|
|
|
|
print("Failed to fetch %s" % cibranch.url)
|
|
|
|
continue
|
2018-11-02 01:30:50 +01:00
|
|
|
cleaned_json = [ line for line in result_json.split("\n") if "test_name" in line ]
|
|
|
|
cleaned_json = [ line.replace('"level": ?,', '"level": null,') for line in cleaned_json ]
|
|
|
|
cleaned_json = "[" + ''.join(cleaned_json)[:-1] + "]"
|
2019-04-16 17:26:36 +02:00
|
|
|
cleaned_json = cleaned_json.replace("Binary", '"?"')
|
2018-11-02 01:30:50 +01:00
|
|
|
j = json.loads(cleaned_json)
|
|
|
|
for test_summary in j:
|
2019-05-14 19:00:37 +02:00
|
|
|
if test_summary["app"] is None:
|
|
|
|
print("No app to parse in test_summary ? : %s" % test_summary)
|
|
|
|
continue
|
|
|
|
|
2018-11-02 01:30:50 +01:00
|
|
|
if (test_summary["arch"], test_summary["branch"]) != (cibranch.arch, cibranch.branch):
|
2017-12-19 17:03:51 +01:00
|
|
|
continue
|
2018-11-02 01:30:50 +01:00
|
|
|
|
2018-11-08 14:48:35 +01:00
|
|
|
test_results = { }
|
|
|
|
for test, result in zip(AppCI.tests, test_summary["detailled_success"]):
|
2019-05-14 19:00:37 +02:00
|
|
|
test_results[test] = bool(int(result)) if result in [ "1", "0" ] else None
|
2018-11-08 14:48:35 +01:00
|
|
|
|
2019-01-22 17:07:00 +01:00
|
|
|
app = App.query.filter_by(name=test_summary["app"]).first()
|
2019-05-14 19:00:37 +02:00
|
|
|
if app is None:
|
|
|
|
print("Couldnt found corresponding app object for %s, skipping" % test_summary["app"])
|
|
|
|
continue
|
2019-01-22 17:07:00 +01:00
|
|
|
date = datetime.datetime.fromtimestamp(test_summary["timestamp"])
|
|
|
|
|
|
|
|
existing_test = AppCIResult.query \
|
|
|
|
.filter_by(branch = cibranch) \
|
|
|
|
.filter_by(date = date) \
|
|
|
|
.first()
|
|
|
|
|
2019-05-14 19:00:37 +02:00
|
|
|
if existing_test and existing_test.app is None:
|
|
|
|
print("Uh erasing old weird buggy record")
|
|
|
|
db.session.delete(existing_test)
|
|
|
|
existing_test = None
|
|
|
|
|
2019-01-22 17:07:00 +01:00
|
|
|
if not existing_test:
|
2019-05-14 19:00:37 +02:00
|
|
|
print("New record for app %s" % str(app))
|
2019-01-22 17:07:00 +01:00
|
|
|
results = AppCIResult(app = app,
|
|
|
|
branch = cibranch,
|
|
|
|
level = test_summary["level"],
|
|
|
|
date = date,
|
|
|
|
results = test_results)
|
|
|
|
db.session.add(results)
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
db.session.commit()
|