Skip to content

Commit

Permalink
Update documentation to add hera v5 introduction (#509)
Browse files Browse the repository at this point in the history
Signed-off-by: Sambhav Kothari <[email protected]>
  • Loading branch information
sambhav authored Mar 27, 2023
1 parent b8e2201 commit 4e969e3
Show file tree
Hide file tree
Showing 66 changed files with 4,652 additions and 4,457 deletions.
156 changes: 79 additions & 77 deletions docs/examples/workflows/coinflip.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,105 +4,107 @@



## Hera

```python
from hera.workflows import DAG, Workflow, script
=== "Hera"

```python linenums="1"
from hera.workflows import DAG, Workflow, script

@script()
def flip():
import random

result = "heads" if random.randint(0, 1) == 0 else "tails"
print(result)

@script()
def flip():
import random

@script()
def heads():
print("it was heads")
result = "heads" if random.randint(0, 1) == 0 else "tails"
print(result)


@script()
def tails():
print("it was tails")
@script()
def heads():
print("it was heads")


with Workflow(generate_name="coinflip-", entrypoint="d") as w:
with DAG(name="d") as s:
f = flip()
heads().on_other_result(f, "heads")
tails().on_other_result(f, "tails")
```
@script()
def tails():
print("it was tails")

## YAML

```yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: coinflip-
spec:
entrypoint: d
templates:
- dag:
tasks:
with Workflow(generate_name="coinflip-", entrypoint="d") as w:
with DAG(name="d") as s:
f = flip()
heads().on_other_result(f, "heads")
tails().on_other_result(f, "tails")
```

=== "YAML"

```yaml linenums="1"
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: coinflip-
spec:
entrypoint: d
templates:
- dag:
tasks:
- name: flip
template: flip
- depends: flip
name: heads
template: heads
when: '{{tasks.flip.outputs.result}} == heads'
- depends: flip
name: tails
template: tails
when: '{{tasks.flip.outputs.result}} == tails'
name: d
- name: flip
template: flip
- depends: flip
name: heads
template: heads
when: '{{tasks.flip.outputs.result}} == heads'
- depends: flip
name: tails
template: tails
when: '{{tasks.flip.outputs.result}} == tails'
name: d
- name: flip
script:
command:
- python
image: python:3.7
source: 'import os
import sys
sys.path.append(os.getcwd())
script:
command:
- python
image: python:3.7
source: 'import os

import random
import sys

sys.path.append(os.getcwd())

result = "heads" if random.randint(0, 1) == 0 else "tails"
import random

print(result)

'
- name: heads
script:
command:
- python
image: python:3.7
source: 'import os
result = "heads" if random.randint(0, 1) == 0 else "tails"

import sys
print(result)

sys.path.append(os.getcwd())
'
- name: heads
script:
command:
- python
image: python:3.7
source: 'import os

print("it was heads")
import sys

'
- name: tails
script:
command:
- python
image: python:3.7
source: 'import os
sys.path.append(os.getcwd())

import sys
print("it was heads")

sys.path.append(os.getcwd())
'
- name: tails
script:
command:
- python
image: python:3.7
source: 'import os

print("it was tails")
import sys

sys.path.append(os.getcwd())

print("it was tails")

'
```

'
```
166 changes: 84 additions & 82 deletions docs/examples/workflows/dag_conditional_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,98 +4,100 @@



## Hera

```python
from hera.expr import g
from hera.workflows import DAG, Parameter, Workflow, script
=== "Hera"

```python linenums="1"
from hera.expr import g
from hera.workflows import DAG, Parameter, Workflow, script

@script(add_cwd_to_sys_path=False, image="python:alpine3.6")
def heads():
print("heads")

@script(add_cwd_to_sys_path=False, image="python:alpine3.6")
def heads():
print("heads")

@script(add_cwd_to_sys_path=False, image="python:alpine3.6")
def tails():
print("tails")

@script(add_cwd_to_sys_path=False, image="python:alpine3.6")
def tails():
print("tails")

@script(add_cwd_to_sys_path=False, image="python:alpine3.6")
def flip_coin():
import random

print("heads" if random.randint(0, 1) == 0 else "tails")
@script(add_cwd_to_sys_path=False, image="python:alpine3.6")
def flip_coin():
import random

print("heads" if random.randint(0, 1) == 0 else "tails")

with Workflow(
generate_name="dag-conditional-parameter-",
entrypoint="main",
) as w:
with DAG(name="main") as main_dag:
fc = flip_coin(name="flip-coin")
h = heads(name="heads").on_other_result(fc, "heads")
t = tails(name="tails").on_other_result(fc, "tails")

expression = g.tasks["flip-coin"].outputs.result == "heads"
expression = expression.check(g.tasks.heads.outputs.result, g.tasks.tails.outputs.result) # type: ignore
main_dag.outputs = [Parameter(name="stepresult", value_from={"expression": str(expression)})]
```

## YAML

```yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-conditional-parameter-
spec:
entrypoint: main
templates:
- dag:
tasks:
with Workflow(
generate_name="dag-conditional-parameter-",
entrypoint="main",
) as w:
with DAG(name="main") as main_dag:
fc = flip_coin(name="flip-coin")
h = heads(name="heads").on_other_result(fc, "heads")
t = tails(name="tails").on_other_result(fc, "tails")

expression = g.tasks["flip-coin"].outputs.result == "heads"
expression = expression.check(g.tasks.heads.outputs.result, g.tasks.tails.outputs.result) # type: ignore
main_dag.outputs = [Parameter(name="stepresult", value_from={"expression": str(expression)})]
```

=== "YAML"

```yaml linenums="1"
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-conditional-parameter-
spec:
entrypoint: main
templates:
- dag:
tasks:
- name: flip-coin
template: flip-coin
- depends: flip-coin
name: heads
template: heads
when: '{{tasks.flip-coin.outputs.result}} == heads'
- depends: flip-coin
name: tails
template: tails
when: '{{tasks.flip-coin.outputs.result}} == tails'
name: main
outputs:
parameters:
- name: stepresult
valueFrom:
expression: 'tasks[''flip-coin''].outputs.result == ''heads'' ? tasks.heads.outputs.result
: tasks.tails.outputs.result'
- name: flip-coin
template: flip-coin
- depends: flip-coin
name: heads
template: heads
when: '{{tasks.flip-coin.outputs.result}} == heads'
- depends: flip-coin
name: tails
template: tails
when: '{{tasks.flip-coin.outputs.result}} == tails'
name: main
outputs:
parameters:
- name: stepresult
valueFrom:
expression: 'tasks[''flip-coin''].outputs.result == ''heads'' ? tasks.heads.outputs.result
: tasks.tails.outputs.result'
- name: flip-coin
script:
command:
- python
image: python:alpine3.6
source: 'import random
print("heads" if random.randint(0, 1) == 0 else "tails")
script:
command:
- python
image: python:alpine3.6
source: 'import random


print("heads" if random.randint(0, 1) == 0 else "tails")

'
- name: heads
script:
command:
- python
image: python:alpine3.6
source: 'print("heads")

'
- name: tails
script:
command:
- python
image: python:alpine3.6
source: 'print("tails")

'
```

'
- name: heads
script:
command:
- python
image: python:alpine3.6
source: 'print("heads")
'
- name: tails
script:
command:
- python
image: python:alpine3.6
source: 'print("tails")
'
```
Loading

0 comments on commit 4e969e3

Please sign in to comment.