Commit d7c3532c authored by Fulcrand Guilhem's avatar Fulcrand Guilhem
Browse files

Merge branch '288-update-the-builder-to-add-default-stage-folder-and-pages-file' into 'latest'

Resolve "Update the builder to add default stage folder and .pages file"

Closes #288

See merge request r2devops/hub!151
parents cab3cbb5 4c40929c
Loading
Loading
Loading
Loading
+51 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import argparse
from tools.utils.utils import Config
utils = Config()


def get_conf(job_path):
    """Parse the YAML config of the job

@@ -344,6 +345,28 @@ def create_job_doc(job):
        logging.error(error)
        sys.exit(1)


def create_pages_placeholder(placeholder_path,stage_key):
    """ Create jobs folder destination folder in docs for the job and .pages fil

    Parameters:
    -----------
    placeholder_path : str
        Path to the stage documentation
    stage_key : boolean
        Name of the stage

    Returns:
    --------
    """
    # Create jobs folder destination folder in docs for the job
    makedirs(placeholder_path,0o777,True)
    # Create the .pages files mandatory to serve documentaiton and display stages
    f = open(placeholder_path + "/.pages", "w+")
    f.write("title: '"+ stage_key +"'")
    f.close()


def add_placeholder():
    """Add a placeholder file for every stage, in case a stage have no job

@@ -364,6 +387,29 @@ def add_placeholder():
                template = env.get_template(utils.TEMPLATE_PLACEHOLDER)
                file_handle.write(template.render())

def create_arrange_pages():
    """ Create arrange .pages for mkdocs to sort the list of stage in job page

    Parameters:
    -----------

    Returns:
    --------
    """
    stages = sorted(utils.INDEX.items(), key=lambda x: x[1]['order'])
    try:
        with open(utils.ARRANGE_PAGES_FILE_PATH, 'w+') as doc_file:
            env = Environment(loader=FileSystemLoader(utils.BUILDER_DIR + "/" + utils.TEMPLATE_DIR))
            template = env.get_template(utils.TEMPLATE_ARRANGE_PAGES)
            doc_file.write(template.render(
                title = utils.TITLE_ARRANGE_PAGES,
                stages = stages
        ))
    except Exception as error:
        logging.error("Failed to create arrange pages file for job %s", doc_file_path)
        logging.error(error)
        sys.exit(1)

def argparse_setup():
    """Setup argparse

@@ -390,13 +436,16 @@ def main():
    # logging
    logging.basicConfig(level=logging.INFO)

    # Verify that there is a .md file for every stage, or mkdocs will break
    add_placeholder()

    create_arrange_pages()
    
    # Iterate over every directories in jobs directory to create their job.md for the documentation
    jobs = listdir(utils.JOBS_DIR)
    for job in jobs:
        create_job_doc(job)

    # Verify that there is a .md file for every stage, or mkdocs will break
    add_placeholder()

    # Using jinja2 with a template to create the index
    env = Environment(loader=FileSystemLoader(utils.BUILDER_DIR + "/" + utils.TEMPLATE_DIR))
+7 −0
Original line number Diff line number Diff line

title: '{{title}}'
arrange:
{%- for stage in stages %}
- {{stage[0]-}}

{% endfor %}
+14 −8
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ class Config():
        self.MARKDOWN_EXTENSION = ".md"
        # Path to images used for the built job documentation
        self.MKDOCS_DIR_JOBS_IMAGES = "images/jobs"
        self.ARRANGE_PAGES_FILE_PATH = "docs/jobs/.pages"
        self.TITLE_ARRANGE_PAGES = 'Jobs'

        # Requests variable & API Variables
        self.GITLAB_BASE_URL = "https://gitlab.com/"
@@ -56,17 +58,21 @@ class Config():
        self.TEMPLATE_PLACEHOLDER = "placeholder.md.j2"
        self.TEMPLATE_LICENSE_DIR = "licenses"
        self.INDEX_FILE = "index.md"
        self.TEMPLATE_ARRANGE_PAGES = "arrange_pages.md.j2"


        # List of stages
        self.INDEX = {
            "static_tests": {"name":"Static_tests","icon":"🔎","content":[], "description":"Static testing of repository files"},
            "build": {"name":"Build","icon":"🧱","content":[], "description":"Building and packaging of software"},
            "dynamic_tests": {"name":"Dynamic_tests","icon":"🔥","content":[], "description":"Dynamic testing of a running version of the software"},
            "provision": {"name":"Provision","icon":"🛠","content":[], "description":"Preparation of the software infrastructure"},
            "review": {"name":"Review","icon":"👌","content":[], "description":"Deployment of the software in an isolated review environment"},
            "release": {"name":"Release","icon":"🏷","content":[], "description":"Releasing and tagging of the software"},
            "deploy": {"name":"Deploy","icon":"🚀","content":[], "description":"Deployment of the software on environments"},
            "others": {"name":"Others","icon":"🦄","content":[], "description":"All other magic jobs not included in previous stages"}
            "static_tests": {"order":1, "name":"Static_tests","icon":"🔎","content":[], "description":"Static testing of repository files"},
            "build": {"order":2, "name":"Build","icon":"🧱","content":[], "description":"Building and packaging of software"},
            "dynamic_tests": {"order":3, "name":"Dynamic_tests","icon":"🔥","content":[], \
            "description":"Dynamic testing of a running version of the software"},
            "provision": {"order":4, "name":"Provision","icon":"🛠","content":[], "description":"Preparation of the software infrastructure"},
            "review": {"order":5, "name":"Review","icon":"👌","content":[], \
            "description":"Deployment of the software in an isolated review environment"},
            "release": {"order":6, "name":"Release","icon":"🏷","content":[], "description":"Releasing and tagging of the software"},
            "deploy": {"order":7, "name":"Deploy","icon":"🚀","content":[], "description":"Deployment of the software on environments"},
            "others": {"order":8, "name":"Others","icon":"🦄","content":[], "description":"All other magic jobs not included in previous stages"}
        }