1
0
Fork 0
mirror of https://github.com/YunoHost/apps.git synced 2024-09-03 20:06:07 +02:00

ci: Add a proper catalog linter instead of bash mess

This commit is contained in:
Alexandre Aubin 2023-01-20 17:33:33 +01:00
parent bdad939c58
commit 485861e7a8
2 changed files with 31 additions and 18 deletions

View file

@ -1,4 +1,4 @@
name: TOML validation
name: Catalog consistency checks
on: pull_request
@ -19,21 +19,6 @@ jobs:
- name: Check TOML validity for apps.toml
run: |
python3 -c "import toml; toml.load(open('apps.toml'))"
- name: Check all working apps have consistent app id / app url
- name: Check all working apps have consistent app id / app url and categories
run: |
FAULTY_APPS="false";
for LINE in $(python3 -c "import toml; print('\n'.join(app for app, infos in toml.load(open('apps.toml')).items() if infos.get('state') == 'working'))")
do
APP=$(echo $LINE | awk -F'|' '{print $1}')
URL_END=$(echo $LINE | awk -F'/' '{print $NF}')
[ "$APP" == "$(echo $APP | tr [A-Z] [a-z])" ] || { FAULTY_APPS="true"; echo "$APP : app id should be lowercase" >&2; }
[ "$URL_END" == "${APP}_ynh" ] || { FAULTY_APPS="true"; echo "$APP : the url should end with ${APP}_ynh" >&2; }
done
[ $FAULTY_APPS = "false" ]
- name: Check all working apps have a category
run: |
APPS_WITH_NO_CATEGORY=$(python3 -c "import toml; print('\n'.join(app for app, infos in toml.load(open('apps.toml')).items() if infos.get('state') == 'working' and not infos.get('category')))")
[ "$APPS_WITH_NO_CATEGORY" == "" ] || { echo "Some working apps are missing a category: $APPS_WITH_NO_CATEGORY" >&2; false; }
python3 tools/catalog_linter.py

28
tools/catalog_linter.py Normal file
View file

@ -0,0 +1,28 @@
import toml
import sys
catalog = toml.load(open('apps.toml'))
catalog = {app: infos for app, infos in catalog.items() if infos.get('state') == "working"}
categories = toml.load(open('categories.toml')).keys()
def check_apps():
for app, infos in catalog.items():
repo_name = infos.get("url", "").split("/")[-1]
if repo_name != app + "_ynh":
yield f"{app}: repo name should be {app}_ynh, not in {repo_name}"
category = infos.get("category")
if not category:
yield f"{app}: missing category"
if category not in categories:
yield f"{app}: category {category} is not defined in categories.toml"
errors = list(check_apps())
for error in errors:
print(error)
if errors:
sys.exit(1)