File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,14 +57,18 @@ def init() -> None:
5757 wf-example:
5858 type: Workflow
5959 desc: |
60- An example workflow template.
60+ An example workflow template that provide the demo of workflow .
6161 params:
6262 name:
6363 type: str
6464 default: "World"
6565 jobs:
6666 first-job:
6767 stages:
68+
69+ - name: "Hello Stage"
70+ echo: "Start say hi to the console"
71+
6872 - name: "Call tasks"
6973 uses: tasks/say-hello-func@example
7074 with:
@@ -232,7 +236,7 @@ def workflow_json_schema(
232236 json_schema = TypeAdapter (template ).json_schema (by_alias = True )
233237 template_schema : dict [str , str ] = {
234238 "$schema" : "http://json-schema.org/draft-07/schema#" ,
235- "title" : "Workflow Configuration Schema" ,
239+ "title" : "Workflow Configuration JSON Schema" ,
236240 "version" : __version__ ,
237241 }
238242 with open (output , mode = "w" , encoding = "utf-8" ) as f :
Original file line number Diff line number Diff line change @@ -284,6 +284,46 @@ def __validate_jobs_need__(self) -> Self:
284284
285285 return self
286286
287+ def md (self ) -> str : # pragma: no cov
288+ """Generate the markdown template."""
289+
290+ def align_newline (value : str ) -> str :
291+ return value .rstrip ("\n " ).replace ("\n " , "\n " )
292+
293+ info : str = (
294+ f"| Author: nobody "
295+ f"| created_at: `{ self .created_at :%Y-%m-%d %H:%M:%S} ` "
296+ f"| updated_at: `{ self .updated_dt :%Y-%m-%d %H:%M:%S} ` |\n "
297+ f"| --- | --- | --- |"
298+ )
299+ jobs : str = ""
300+ for job in self .jobs :
301+ job_model : Job = self .jobs [job ]
302+ jobs += f"### { job } \n { job_model .desc or '' } \n "
303+ stags : str = ""
304+ for stage_model in job_model .stages :
305+ stags += (
306+ f"#### { stage_model .name } \n \n "
307+ f"Stage ID: { stage_model .id or '' } \n "
308+ f"Stage Model: { stage_model .__class__ .__name__ } \n \n "
309+ )
310+ jobs += f"{ stags } \n "
311+ return dedent (
312+ f"""
313+ # Workflow: { self .name } \n
314+ { align_newline (info )} \n
315+ { align_newline (self .desc )} \n
316+ ## Parameters\n
317+ | name | type | default | description |
318+ | --- | --- | --- | : --- : |
319+
320+ ## Jobs\n
321+ { align_newline (jobs )}
322+ """ .lstrip (
323+ "\n "
324+ )
325+ )
326+
287327 def job (self , name : str ) -> Job :
288328 """Return the workflow's Job model that getting by an input job's name
289329 or job's ID. This method will pass an extra parameter from this model
Original file line number Diff line number Diff line change @@ -425,3 +425,14 @@ def test_workflow_parameterize(test_path):
425425 # NOTE: Raise if passing parameter that does not set on the workflow.
426426 with pytest .raises (WorkflowError ):
427427 workflow .parameterize ({"foo" : "bar" })
428+
429+
430+ def test_workflow_markdown (test_path ):
431+ workflow = Workflow .from_conf (
432+ "stream-workflow" , path = test_path / "conf/example"
433+ )
434+ md_file : Path = test_path / "stream-workflow.md"
435+ with md_file .open (mode = "w" ) as f :
436+ f .write (workflow .md ())
437+
438+ md_file .unlink (missing_ok = True )
You can’t perform that action at this time.
0 commit comments