diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b014f639..94dc27d1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/tools/catalog_linter.py b/tools/catalog_linter.py new file mode 100644 index 00000000..6e17117e --- /dev/null +++ b/tools/catalog_linter.py @@ -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)