From c5b27a3ecdf4799f4f9dee628f9a2b867ca90a8c Mon Sep 17 00:00:00 2001
From: Remi  PLANEL <rplanel@pasteur.fr>
Date: Thu, 23 Nov 2023 13:26:57 +0100
Subject: [PATCH] Front matter linter

---
 .gitlab-ci.yml                                | 41 +++++++++++--------
 .../df-wiki-cli/df_wiki_cli/content/main.py   |  6 ++-
 2 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c44a22fd..1bc41c11 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -4,6 +4,11 @@ workflow:
       when: never
     - when: always
 
+
+
+
+
+
 # Functions that should be executed before the build script is run
 
 variables:
@@ -15,6 +20,8 @@ variables:
   # prod
   HOST_PROD: 'defense-finder.pasteur.cloud'
   MEILI_HOST_PROD: 'defense-finder-meilisearch.pasteur.cloud'
+  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
+
 
 
 cache:
@@ -44,9 +51,17 @@ stages:
 # Build df-wiki-cli package
 
 
+.df-wiki-cli-run:
+  image: python:3.11-bullseye
+  cache:                      # Pip's cache doesn't store the python packages
+    paths:                    # https://pip.pypa.io/en/stable/topics/caching/
+      - .cache/pip
+  before_script:
+    - pip install df-wiki-cli --index-url https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.pasteur.fr/api/v4/projects/5222/packages/pypi/simple
+
 build:df-wiki-cli:
-  stage: build-df-cli
   image: python:3.11-bullseye
+  stage: build-df-cli
   before_script:
     - cd packages/df-wiki-cli/
     - pip install poetry
@@ -165,13 +180,11 @@ delete-meili-helm-release:prod:
 # lint
 
 lint:
-  image: python:3.11-bullseye
+  extends: .df-wiki-cli-run
   stage: lint
-  before_script:
-    - pip install df-wiki-cli --index-url https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.pasteur.fr/api/v4/projects/5222/packages/pypi/simple
-    - cd content/3.defense-systems
   script:
-    - find . -name '*.md' -print0 | xargs -0 -I {} df-wiki-cli content lint --file {}
+    - cd content/3.defense-systems
+    - find . -name '*.md' ! -name '0.index.md' -print0 | xargs -0 -I {} df-wiki-cli content lint --file {}
   when: manual      
   rules: 
     - if: $CI_COMMIT_BRANCH != "main"
@@ -179,12 +192,10 @@ lint:
 # Update Meili search indexes
 
 .update-meilisearch-index:
+  extends: .df-wiki-cli-run
   stage: update-meilisearch-indexes
-  image: python:3.11-bullseye
   variables:
     MEILI_HOST: "http://localhost:7700"
-  before_script:
-    - pip install df-wiki-cli --index-url https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.pasteur.fr/api/v4/projects/5222/packages/pypi/simple
   script:
     - >
       df-wiki-cli
@@ -225,12 +236,10 @@ update-meilisearch-index:prod:
 ############# get-meili-key ###############
 
 .set-meili-env:
-  image: python:3.11-bullseye
+  extends: .df-wiki-cli-run
   stage: get-meili-key
   variables:
     MEILI_HOST: "http://localhost:7700"
-  before_script:
-    - pip install df-wiki-cli --index-url https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.pasteur.fr/api/v4/projects/5222/packages/pypi/simple
   script:
     - > 
       df-wiki-cli 
@@ -262,10 +271,8 @@ set-meili-env:prod:
 
 ##############################
 get-zotero:
-  image: python:3.11-bullseye
+  extends: .df-wiki-cli-run
   stage: get-data
-  before_script:
-    - pip install df-wiki-cli --index-url https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.pasteur.fr/api/v4/projects/5222/packages/pypi/simple
   script:
     - df-wiki-cli articles --key ${ZOTERO_API_KEY} --output public/articles.json
   artifacts:
@@ -275,10 +282,8 @@ get-zotero:
     - if: $CI_COMMIT_BRANCH == "main"
 
 get-pfam:
-  image: python:3.11-bullseye
+  extends: .df-wiki-cli-run
   stage: get-data
-  before_script:
-    - pip install df-wiki-cli --index-url https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.pasteur.fr/api/v4/projects/5222/packages/pypi/simple
   script:
     - df-wiki-cli pfam --output public/pfam-a-hmm.csv
   artifacts:
diff --git a/packages/df-wiki-cli/df_wiki_cli/content/main.py b/packages/df-wiki-cli/df_wiki_cli/content/main.py
index 11113150..b869c668 100644
--- a/packages/df-wiki-cli/df_wiki_cli/content/main.py
+++ b/packages/df-wiki-cli/df_wiki_cli/content/main.py
@@ -1,9 +1,9 @@
 import typer
+import sys
 from typing_extensions import Annotated
 from typing import Optional, List
 from pathlib import Path
 from pydantic import BaseModel, ValidationError
-from pydantic_yaml import parse_yaml_raw_as, to_yaml_str
 import frontmatter
 from enum import Enum
 from rich.console import Console
@@ -70,7 +70,9 @@ def lint(
             # pprint(exc.errors(), expand_all=True)
             for err in exc.errors():
                 console.print(
-                    f"[red]{err['msg']} : {err['type']} {' -> '.join(err['loc'])}"
+                    f"[red]{err['msg']} : {err['type']} {' -> '.join([str(l) for l in err['loc']])}"
                 )
+            # raise
+            sys.exit(1)
         else:
             console.print("[green] Everything is alright")
-- 
GitLab