ci: add more fields to versions.json

Add date and if a commit should be considered for weekly testing.
This will still work with the old format.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2020-10-27 10:01:00 -04:00 committed by Carles Cufí
parent 312429be3c
commit 4cd63abafd
2 changed files with 74 additions and 12 deletions

View file

@ -31,4 +31,5 @@ doc/*
# sanitycheck.
scripts/ci/sanitycheck_ignore.txt
scripts/ci/what_changed.py
scripts/ci/version_mgr.py
scripts/requirements*

View file

@ -2,49 +2,104 @@
# Copyright (c) 2020 Intel Corp.
# SPDX-License-Identifier: Apache-2.0
"""
Syntax of file:
[
{
"version": "<commit>",
"date": "<date>",
"weekly: False,
},
]
"""
import json
import argparse
import urllib.request
import os
from git import Git
from datetime import datetime
VERSIONS_FILE = "versions.json"
def parse_args():
parser = argparse.ArgumentParser(
description="Manage versions to be tested.")
parser.add_argument('-l', '--list', action="store_true",
help="List all published versions")
help="List all published versions")
parser.add_argument('-u', '--update',
help="Update versions file from tree.")
help="Update versions file from tree.")
parser.add_argument('-L', '--latest', action="store_true",
help="Get latest published version")
help="Get latest published version")
parser.add_argument('-w', '--weekly', action="store_true",
help="Mark as weekly")
return parser.parse_args()
def get_versions():
data = None
url = 'https://testing.zephyrproject.org/daily_tests/versions.json'
urllib.request.urlretrieve(url, 'versions.json')
if not os.path.exists('versions.json'):
url = 'https://testing.zephyrproject.org/daily_tests/versions.json'
urllib.request.urlretrieve(url, 'versions.json')
with open("versions.json", "r") as fp:
data = json.load(fp)
return data
def handle_compat(item):
item_compat = {}
if isinstance(item, str):
item_compat['version'] = item
item_compat['weekly'] = False
item_compat['date'] = None
else:
item_compat = item
return item_compat
def show_versions():
data = get_versions()
for v in data:
print(f"- {v}")
for item in data:
item_compat = handle_compat(item)
is_weekly = item_compat.get('weekly', False)
wstr = ""
datestr = ""
if is_weekly:
wstr = "(marked for weekly testing)"
if item_compat.get('date'):
pdate = datetime.strptime(item_compat['date'], '%Y-%m-%dT%H:%M:%S.%f')
date = pdate.strftime("%b %d %Y %H:%M:%S")
datestr = f"published on {date}"
print(f"- {item_compat['version']} {datestr} {wstr}")
def show_latest():
data = get_versions()
print(data[-1])
latest = data[-1]
item_compat = handle_compat(latest)
def update(git_tree):
ver = item_compat.get("version")
date = item_compat.get("date", False)
is_weekly = item_compat.get('weekly')
datestr = ""
if date:
datestr = f"published on {date}"
print(f"Latest version is {ver} {datestr}")
if is_weekly:
print("This version is marked for weekly testing.")
def update(git_tree, is_weekly=False):
g = Git(git_tree)
today = datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')
version = g.describe()
published = False
data = get_versions()
if version in data:
found = list(filter(lambda item: (isinstance(item, dict) and
item.get('version') == version) or item == version, data))
if found:
published = True
print("version already published")
else:
@ -52,17 +107,23 @@ def update(git_tree):
if data and not published:
with open(VERSIONS_FILE, "w") as versions:
data.append(version)
item = {}
item['version'] = version
item['date'] = today
item['weekly'] = is_weekly
data.append(item)
json.dump(data, versions)
def main():
args = parse_args()
if args.update:
update(args.update)
update(args.update, args.weekly)
elif args.list:
show_versions()
elif args.latest:
show_latest()
else:
print("You did not specify any options")
if __name__ == "__main__":
main()