Skip to content

Commit 8793d88

Browse files
authored
docs: Add clarity to events.md that the .spec.event.selector field is in expr syntax (#14360)
Signed-off-by: Oliver Isaac <[email protected]>
1 parent 1097d45 commit 8793d88

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed

docs/events.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ The name, Annotation and Label expression must evaluate to a string and follow t
152152

153153
## Event Expression Syntax and the Event Expression Environment
154154

155-
**Event expressions** are [expressions](variables.md#expression) that are evaluated over the **event expression environment**.
155+
**Event expressions**, such as the `.spec.event.selector` or `...valueFrom.event` fields, are [expressions](variables.md#expression) that are evaluated over the **event expression environment**.
156156

157157
### Expression Syntax
158158

docs/fields.md

+44
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ WorkflowTemplate is the definition of a workflow template resource
425425

426426
- [`event-consumer-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workflowtemplate.yaml)
427427

428+
- [`github-path-filter-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workflowtemplate.yaml)
429+
428430
- [`templates.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/templates.yaml)
429431
</details>
430432

@@ -444,6 +446,8 @@ WorkflowEventBinding is the definition of an event resource
444446
<summary>Examples (click to open)</summary>
445447

446448
- [`event-consumer-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workfloweventbinding.yaml)
449+
450+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
447451
</details>
448452

449453
### Fields
@@ -815,6 +819,10 @@ WorkflowSpec is the specification of a Workflow.
815819

816820
- [`event-consumer-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workflowtemplate.yaml)
817821

822+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
823+
824+
- [`github-path-filter-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workflowtemplate.yaml)
825+
818826
- [`workflow-of-workflows.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-of-workflows.yaml)
819827

820828
- [`dag.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/dag.yaml)
@@ -1267,6 +1275,10 @@ CronWorkflowSpec is the specification of a CronWorkflow
12671275

12681276
- [`event-consumer-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workflowtemplate.yaml)
12691277

1278+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
1279+
1280+
- [`github-path-filter-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workflowtemplate.yaml)
1281+
12701282
- [`workflow-of-workflows.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-of-workflows.yaml)
12711283

12721284
- [`dag.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/dag.yaml)
@@ -1505,6 +1517,10 @@ Arguments to a template
15051517

15061518
- [`event-consumer-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workflowtemplate.yaml)
15071519

1520+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
1521+
1522+
- [`github-path-filter-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workflowtemplate.yaml)
1523+
15081524
- [`workflow-of-workflows.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-of-workflows.yaml)
15091525

15101526
- [`dag.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/dag.yaml)
@@ -1824,6 +1840,8 @@ WorkflowTemplateRef is a reference to a WorkflowTemplate resource.
18241840

18251841
- [`event-consumer-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workfloweventbinding.yaml)
18261842

1843+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
1844+
18271845
- [`workflow-of-workflows.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-of-workflows.yaml)
18281846

18291847
- [`workflow-template-ref-with-entrypoint-arg-passing.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/workflow-template-ref-with-entrypoint-arg-passing.yaml)
@@ -2048,6 +2066,8 @@ _No description available_
20482066
<summary>Examples with this field (click to open)</summary>
20492067

20502068
- [`event-consumer-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workfloweventbinding.yaml)
2069+
2070+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
20512071
</details>
20522072

20532073
### Fields
@@ -2063,6 +2083,8 @@ _No description available_
20632083
<summary>Examples with this field (click to open)</summary>
20642084

20652085
- [`event-consumer-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workfloweventbinding.yaml)
2086+
2087+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
20662088
</details>
20672089

20682090
### Fields
@@ -2357,6 +2379,10 @@ Parameter indicate a passed string parameter to a service template with an optio
23572379

23582380
- [`event-consumer-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workflowtemplate.yaml)
23592381

2382+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
2383+
2384+
- [`github-path-filter-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workflowtemplate.yaml)
2385+
23602386
- [`workflow-of-workflows.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-of-workflows.yaml)
23612387

23622388
- [`dag.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/dag.yaml)
@@ -2918,6 +2944,8 @@ Inputs are the mechanism for passing parameters, artifacts, volumes from one tem
29182944

29192945
- [`event-consumer-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workflowtemplate.yaml)
29202946

2947+
- [`github-path-filter-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workflowtemplate.yaml)
2948+
29212949
- [`workflow-of-workflows.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-of-workflows.yaml)
29222950

29232951
- [`templates.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/templates.yaml)
@@ -3250,6 +3278,8 @@ WorkflowStep is a reference to a template to execute in a series of step
32503278

32513279
- [`event-consumer-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workflowtemplate.yaml)
32523280

3281+
- [`github-path-filter-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workflowtemplate.yaml)
3282+
32533283
- [`workflow-of-workflows.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-of-workflows.yaml)
32543284

32553285
- [`hello-world.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/hello-world.yaml)
@@ -3712,6 +3742,8 @@ ValueFrom describes a location in which to obtain the value to a parameter
37123742
- [`suspend-template-outputs.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/suspend-template-outputs.yaml)
37133743

37143744
- [`event-consumer-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workfloweventbinding.yaml)
3745+
3746+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
37153747
</details>
37163748

37173749
### Fields
@@ -4619,6 +4651,8 @@ _No description available_
46194651
- [`suspend-template-outputs.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/suspend-template-outputs.yaml)
46204652

46214653
- [`event-consumer-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workfloweventbinding.yaml)
4654+
4655+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
46224656
</details>
46234657

46244658
### Fields
@@ -5045,6 +5079,10 @@ ObjectMeta is metadata that all persisted resources must have, which includes al
50455079

50465080
- [`event-consumer-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workflowtemplate.yaml)
50475081

5082+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
5083+
5084+
- [`github-path-filter-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workflowtemplate.yaml)
5085+
50485086
- [`workflow-of-workflows.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-of-workflows.yaml)
50495087

50505088
- [`dag.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/dag.yaml)
@@ -5640,6 +5678,8 @@ A single application container that you want to run within a pod.
56405678

56415679
- [`event-consumer-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workflowtemplate.yaml)
56425680

5681+
- [`github-path-filter-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workflowtemplate.yaml)
5682+
56435683
- [`templates.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/templates.yaml)
56445684

56455685
- [`workflow-archive-logs.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/workflow-archive-logs.yaml)
@@ -6638,6 +6678,8 @@ ImageVolumeSource represents a image volume resource.
66386678

66396679
- [`event-consumer-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workflowtemplate.yaml)
66406680

6681+
- [`github-path-filter-workflowtemplate.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workflowtemplate.yaml)
6682+
66416683
- [`templates.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/templates.yaml)
66426684

66436685
- [`workflow-archive-logs.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-template/workflow-archive-logs.yaml)
@@ -6882,6 +6924,8 @@ EnvVarSource represents a source for the value of an EnvVar.
68826924
- [`suspend-template-outputs.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/suspend-template-outputs.yaml)
68836925

68846926
- [`event-consumer-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/event-consumer-workfloweventbinding.yaml)
6927+
6928+
- [`github-path-filter-workfloweventbinding.yaml`](https://github.com/argoproj/argo-workflows/blob/main/examples/workflow-event-binding/github-path-filter-workfloweventbinding.yaml)
68856929
</details>
68866930

68876931
### Fields
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# This is an example WorkflowEventBinding with a compplex event selector.
2+
# Both event selectors and parameters's valueFrom use expr-lang syntax
3+
#
4+
# In this example, the Workflow will only be run if the commit affects files
5+
# that are either in `subpath/A/` or `subpath/B/`
6+
apiVersion: argoproj.io/v1alpha1
7+
kind: WorkflowEventBinding
8+
metadata:
9+
name: github-path-filter
10+
spec:
11+
event:
12+
selector: |
13+
metadata["x-github-event"] == ["push"]
14+
15+
// The discriminator is the last subpath of URL path
16+
&& discriminator == "github-path-filter"
17+
18+
// for each of these file paths
19+
&& any([ "subpath/A/", "subpath/B/" ], {
20+
let prefix = #;
21+
22+
// loop over every commit
23+
any(payload.commits ?? [], {
24+
let commit = #;
25+
26+
// loop over each file action in the commit
27+
any(["added", "removed", "modified"], {
28+
let file_action = #;
29+
30+
// Loop over each of the files in the file action
31+
any(commit[file_action] ?? [], {
32+
let filepath = #;
33+
34+
// return true if the given file is in our subpath
35+
hasPrefix(filepath, prefix)
36+
})
37+
})
38+
})
39+
})
40+
submit:
41+
workflowTemplateRef:
42+
name: github-path-filter
43+
arguments:
44+
parameters:
45+
- name: files
46+
valueFrom:
47+
event: |
48+
// Use the reduce function to collect all files affeccted by commits in this push
49+
reduce(
50+
payload.commits ?? [],
51+
{
52+
let commit = #;
53+
concat(#acc, commit["added"], commit["removed"], commit["modified"])
54+
},
55+
[]
56+
)
57+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: WorkflowTemplate
3+
metadata:
4+
name: github-path-filter
5+
spec:
6+
entrypoint: main
7+
arguments:
8+
parameters:
9+
- name: files
10+
value: []
11+
templates:
12+
- name: main
13+
steps:
14+
- - name: a
15+
template: argosay
16+
arguments:
17+
parameters:
18+
- name: files
19+
value: "{{workflow.parameters.files}}"
20+
21+
- name: argosay
22+
inputs:
23+
parameters:
24+
- name: files
25+
container:
26+
image: argoproj/argosay:v2
27+
args: [ echo, "Files affected by commit: {{inputs.parameters.files}}" ]

0 commit comments

Comments
 (0)