diff --git a/CHANGELOG.D/699.feature b/CHANGELOG.D/699.feature new file mode 100644 index 00000000..386a7c49 --- /dev/null +++ b/CHANGELOG.D/699.feature @@ -0,0 +1,6 @@ +This version includes changes to the workflow and project configuration files to enable code completion and validation by adding schema references to Apolo's config yaml files. These changes will improve the development experience by providing better code completion and validation. + +Changes: + +{{cookiecutter.flow_dir}}/.neuro/live.yml: Added schema reference for code completion support in the live workflow configuration file. +{{cookiecutter.flow_dir}}/.neuro/project.yml: Added schema reference for code completion support in the project configuration file. diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 068bc9c2..5b35b928 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -47,8 +47,8 @@ async def get_project_name() -> str: # >>> Optionally clearing comments COMMENTS_STRUCTURE = { - "./.neuro/live.yml": r"(\s*#.*)", - "./.neuro/project.yml": r"(\s*#.*)", + "./.neuro/live.yml": r"(\s*#(?! yaml-language-server).*)", + "./.neuro/project.yml": r"(\s*#(?! yaml-language-server).*)", } PRESERVE_HINTS_VARIANS = { "yes": True, diff --git a/tests/unit/test_bake_project.py b/tests/unit/test_bake_project.py index a5dabf6e..ff7318b8 100644 --- a/tests/unit/test_bake_project.py +++ b/tests/unit/test_bake_project.py @@ -1,4 +1,5 @@ import logging +import re import sys from pathlib import Path @@ -82,12 +83,23 @@ def test_flow_config_with_comments(cookies: Cookies, preserve_comments: str) -> } ) assert result.exit_code == 0 - comment_sign = "#" + comment_regex = re.compile(r"(\s*#(?! yaml-language-server).*)") with inside_dir(str(result.project_path)): live_file_content = Path(".neuro/live.yml").read_text() project_file_content = Path(".neuro/project.yml").read_text() - l_com_exists = comment_sign in live_file_content - p_com_exists = comment_sign in project_file_content + + l_com_exists = any( + [ + comment_regex.match(line) is not None + for line in live_file_content.splitlines() + ] + ) + p_com_exists = any( + [ + comment_regex.match(line) is not None + for line in project_file_content.splitlines() + ] + ) if preserve_comments == "yes": assert l_com_exists, ".neuro/live.yml file does not contain comments" assert p_com_exists, ".neuro/project.yml file does not contain comments" diff --git a/{{cookiecutter.flow_dir}}/.neuro/live.yml b/{{cookiecutter.flow_dir}}/.neuro/live.yml index a79cf141..e1def07d 100644 --- a/{{cookiecutter.flow_dir}}/.neuro/live.yml +++ b/{{cookiecutter.flow_dir}}/.neuro/live.yml @@ -1,3 +1,5 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/neuro-inc/neuro-flow/refs/heads/master/src/apolo_flow/flow-schema.json +## Keep the preceding line to enable code completion for the workflow configuration file. kind: live ## Required. Type of workflow, might be one of the following: ## - 'live' -- full reference at https://docs.apolo.us/apolo-flow-reference/workflow-syntax/live-workflow-syntax diff --git a/{{cookiecutter.flow_dir}}/.neuro/project.yml b/{{cookiecutter.flow_dir}}/.neuro/project.yml index 510188de..aa0ddebf 100644 --- a/{{cookiecutter.flow_dir}}/.neuro/project.yml +++ b/{{cookiecutter.flow_dir}}/.neuro/project.yml @@ -1,3 +1,5 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/neuro-inc/neuro-flow/refs/heads/master/src/apolo_flow/project-schema.json +## Keep the preceding line to enable code completion for the project configuration file. ## Check our full reference documentation at https://docs.apolo.us/apolo-flow-reference/workflow-syntax/project-configuration-syntax id: {{ cookiecutter.flow_id }} ## Could be referenced as $[[ project.id ]] or $[[ flow.project_id ]] contexts.