DSL Examples

Common workflow patterns and examples.

Table of Contents

  1. Simple Workflows
  2. Multi-Stage Pipelines
  3. Approval Workflows
  4. Integration Patterns
  5. Dynamic Workflows
  6. Error Handling

Simple Workflows

Example 1: Hello World

yaml
1apiVersion: xema.dev/workflow/v1alpha1
2kind: Workflow
3metadata:
4  name: hello-world
5  version: 1.0.0
6
7on:
8  workflow_dispatch:
9    inputs:
10      name:
11        type: string
12        required: true
13
14jobs:
15  greet:
16    uses: xema/agent
17    with:
18      task: Say hello to ${{ inputs.name }}

Trigger: Manual dispatch with name input

Example 2: Scheduled Task

yaml
1apiVersion: xema.dev/workflow/v1alpha1
2kind: Workflow
3metadata:
4  name: weekly-report
5  version: 1.0.0
6
7on:
8  schedule:
9    - cron: "0 9 * * MON"           # Monday 9 AM
10      inputs:
11        report_type: weekly
12
13jobs:
14  generate-report:
15    uses: xema/agent
16    with:
17      task: Generate ${{ inputs.report_type }} report

Trigger: Every Monday at 9 AM


Multi-Stage Pipelines

Example 3: Requirements Analysis Pipeline

yaml
1apiVersion: xema.dev/workflow/v1alpha1
2kind: Workflow
3metadata:
4  name: requirements-analysis
5  version: 1.0.0
6
7on:
8  workflow_dispatch:
9    inputs:
10      project_name:
11        type: string
12        required: true
13      scope:
14        type: string
15        enum: [simple, standard, enterprise]
16        required: true
17
18vars:
19  organization: "Acme Corp"
20  max_analysis_days: 5
21
22jobs:
23  # Phase 1: Analyze requirements
24  analyze:
25    title: Analyze Project Requirements
26    uses: xema/agent
27    with:
28      task: Analyze project requirements
29      project_name: ${{ inputs.project_name }}
30      scope: ${{ inputs.scope }}
31      organization: ${{ vars.organization }}
32    outputs:
33      summary: ${{ result.summary }}
34      requirements: ${{ result.requirements }}
35      risks: ${{ result.risks }}
36      effort_estimate: ${{ result.effort_days }}
37
38  # Phase 2: Review by requirements team
39  technical-review:
40    title: Technical Review
41    needs: analyze
42    uses: xema/decision-gate
43    with:
44      approverGroups: [tech-leads]
45      timeout: "3 days"
46      context: ${{ needs.analyze.outputs.summary }}
47
48  # Phase 3: Create specification
49  create-spec:
50    title: Create Specification Document
51    needs: [analyze, technical-review]
52    if: ${{ success() }}
53    uses: xema/agent
54    with:
55      requirements: ${{ needs.analyze.outputs.requirements }}
56      template: requirements-${{ inputs.scope }}
57      estimated_effort: ${{ needs.analyze.outputs.effort_estimate }}
58    outputs:
59      spec_id: ${{ result.artifact_id }}
60      spec_version: ${{ result.version }}
61
62  # Phase 4: PM approval
63  pm-approval:
64    title: Product Manager Approval
65    needs: create-spec
66    uses: xema/decision-gate
67    with:
68      approverGroups: [product-managers]
69      quorum: 1
70      timeout: "2 days"
71      timeoutAction: escalate
72
73  # Phase 5: Publish
74  publish-spec:
75    title: Publish Specification
76    needs: [create-spec, pm-approval]
77    if: ${{ success() }}
78    uses: xema/emit-artifact
79    with:
80      type: requirements_spec
81      content: ${{ needs.create-spec.outputs.spec_content }}
82      metadata:
83        phase: requirements
84        project_name: ${{ inputs.project_name }}
85        scope: ${{ inputs.scope }}
86
87  # Phase 6: Notify
88  notify-completion:
89    title: Notify Stakeholders
90    needs: publish-spec
91    if: ${{ always() }}
92    uses: xema/webhook
93    with:
94      url: https://notifications.acme.com/webhooks
95      payload:
96        event: spec_published
97        spec_id: ${{ needs.publish-spec.outputs.artifact_id }}
98        project: ${{ inputs.project_name }}
99        status: ${{ needs.publish-spec.result.status }}

Features:

  • Sequential pipeline (needs)
  • Inputs with enum
  • Workflow variables
  • Agent invocation
  • Human approvals
  • Conditional execution
  • Artifact emission
  • Webhook notification

Approval Workflows

Example 4: Multi-Level Approval

yaml
1apiVersion: xema.dev/workflow/v1alpha1
2kind: Workflow
3metadata:
4  name: multi-level-approval
5  version: 1.0.0
6
7on:
8  workflow_dispatch:
9    inputs:
10      request_type:
11        type: string
12        enum: [small, standard, large]
13        required: true
14      amount:
15        type: number
16        required: true
17
18jobs:
19  # Route based on amount
20  technical-approval:
21    if: ${{ inputs.amount < 50000 }}
22    uses: xema/decision-gate
23    with:
24      approverGroups: [tech-leads]
25      quorum: 1
26      timeout: "1 day"
27
28  management-approval:
29    if: ${{ inputs.amount >= 50000 && inputs.amount < 250000 }}
30    needs: technical-approval
31    uses: xema/decision-gate
32    with:
33      approverGroups: [managers]
34      quorum: 1
35      timeout: "2 days"
36
37  executive-approval:
38    if: ${{ inputs.amount >= 250000 }}
39    needs: technical-approval
40    uses: xema/decision-gate
41    with:
42      approverGroups: [executives]
43      quorum: 2                      # Requires 2 votes
44      timeout: "3 days"
45      timeoutAction: escalate
46
47  approved:
48    needs: [technical-approval, management-approval, executive-approval]
49    if: ${{ success() }}
50    uses: xema/webhook
51    with:
52      url: https://api.acme.com/process
53      payload:
54        approved: true
55        amount: ${{ inputs.amount }}

Features:

  • Conditional routing
  • Tiered approvals
  • Quorum voting
  • Timeout handling
  • Sequential with conditional needs

Integration Patterns

Example 5: GitHub PR Workflow

yaml
1apiVersion: xema.dev/workflow/v1alpha1
2kind: Workflow
3metadata:
4  name: github-pr-review
5  version: 1.0.0
6
7on:
8  webhook:
9    - event: scm.pull_request
10      filters:
11        state: opened
12
13jobs:
14  analyze-pr:
15    title: Analyze Pull Request
16    uses: xema/agent
17    with:
18      task: Review pull request code
19      pr_title: ${{ trigger.payload.pull_request.title }}
20      pr_number: ${{ trigger.payload.pull_request.number }}
21      diff: ${{ trigger.payload.pull_request.diff }}
22      branch: ${{ trigger.payload.pull_request.branch }}
23    outputs:
24      review: ${{ result.review }}
25      issues: ${{ result.issues }}
26      approved: ${{ result.approved }}
27
28  post-comment:
29    needs: analyze-pr
30    uses: xema/webhook
31    with:
32      url: ${{ trigger.payload.pull_request.comments_url }}
33      method: POST
34      body:
35        body: ${{ needs.analyze-pr.outputs.review }}
36
37  approve-status:
38    needs: analyze-pr
39    if: ${{ needs.analyze-pr.outputs.approved == true }}
40    uses: xema/http
41    with:
42      url: ${{ trigger.payload.pull_request.status_url }}
43      method: POST
44      body:
45        state: success
46        description: "Code review approved"
47
48  request-changes:
49    needs: analyze-pr
50    if: ${{ needs.analyze-pr.outputs.approved == false }}
51    uses: xema/http
52    with:
53      url: ${{ trigger.payload.pull_request.status_url }}
54      method: POST
55      body:
56        state: failure
57        description: "Changes requested in review"

Features:

  • Webhook trigger (GitHub PR)
  • Conditional workflow (approved vs not)
  • HTTP calls to external APIs
  • Webhook notifications

Example 6: Jira Issue to Workflow

yaml
1apiVersion: xema.dev/workflow/v1alpha1
2kind: Workflow
3metadata:
4  name: jira-issue-workflow
5  version: 1.0.0
6
7on:
8  webhook:
9    - event: tracker.issue
10      filters:
11        type: feature
12        priority: high
13
14jobs:
15  analyze-feature:
16    title: Analyze Feature Request
17    uses: xema/agent
18    with:
19      task: Create feature specification
20      issue_key: ${{ trigger.payload.issue.key }}
21      title: ${{ trigger.payload.issue.title }}
22      description: ${{ trigger.payload.issue.description }}
23      priority: ${{ trigger.payload.issue.priority }}
24    outputs:
25      spec_id: ${{ result.spec_id }}
26
27  update-issue:
28    needs: analyze-feature
29    uses: xema/http
30    with:
31      url: https://jira.acme.com/rest/api/3/issues/${{ trigger.payload.issue.key }}
32      method: PUT
33      headers:
34        Authorization: Bearer ${{ secrets.JIRA_TOKEN }}
35      body:
36        fields:
37          labels:
38            - spec-generated
39          customfield_10001: ${{ needs.analyze-feature.outputs.spec_id }}

Features:

  • Jira webhook trigger
  • Feature filter
  • Spec generation
  • Back-reference to Jira

Dynamic Workflows

Example 7: Matrix Test

yaml
1apiVersion: xema.dev/workflow/v1alpha1
2kind: Workflow
3metadata:
4  name: matrix-test
5  version: 1.0.0
6
7on:
8  workflow_dispatch:
9
10jobs:
11  test:
12    strategy:
13      matrix:
14        os: [ubuntu-22.04, windows-2022, macos-13]
15        python-version: [3.10, 3.11, 3.12]
16        include:
17          - os: ubuntu-22.04
18            python-version: "3.13"  # Extra combo
19      maxParallel: 4                # Max 4 jobs at once
20    uses: xema/agent
21    with:
22      os: ${{ matrix.os }}
23      python_version: ${{ matrix.python-version }}
24      task: "Run tests on ${{ matrix.os }} with Python ${{ matrix.python-version }}"
25    outputs:
26      test_result: ${{ result.result }}
27
28  report:
29    needs: test
30    uses: xema/agent
31    with:
32      all_results: ${{ needs.test.outputs[*] }}
33      total_passed: ${{ length(filter(needs.test.outputs, 'passed')) }}
34      task: Generate test report

Features:

  • Static matrix (compile-time)
  • maxParallel limiting
  • include for extra combinations
  • Accessing all matrix outputs

Example 8: Dynamic Discovery

yaml
1apiVersion: xema.dev/workflow/v1alpha1
2kind: Workflow
3metadata:
4  name: dynamic-matrix
5  version: 1.0.0
6
7on:
8  workflow_dispatch:
9
10jobs:
11  discover-services:
12    title: Discover Services
13    uses: xema/agent
14    with:
15      task: List all microservices in the project
16    outputs:
17      services: ${{ result.service_list }}
18
19  deploy-each:
20    title: Deploy Each Service
21    needs: discover-services
22    strategy:
23      dynamic:
24        from: ${{ needs.discover-services.outputs.services }}
25        as: service
26        maxEntries: 100
27    uses: xema/agent
28    with:
29      service_name: ${{ dynamic.service.name }}
30      service_version: ${{ dynamic.service.version }}
31      task: Deploy service ${{ dynamic.service.name }}

Features:

  • Discovery job
  • Dynamic matrix (runtime)
  • Computed from previous output
  • Safe expansion limit

Error Handling

Example 9: Retry and Fallback

yaml
1apiVersion: xema.dev/workflow/v1alpha1
2kind: Workflow
3metadata:
4  name: error-handling
5  version: 1.0.0
6
7defaults:
8  retry:
9    maxAttempts: 3
10    backoffCoefficient: 2.0
11
12on:
13  workflow_dispatch:
14
15jobs:
16  primary-task:
17    uses: xema/agent
18    with:
19      task: Primary processing task
20      timeout: "30m"
21    outputs:
22      result: ${{ result.output }}
23
24  fallback-task:
25    if: ${{ failure() }}
26    uses: xema/agent
27    with:
28      task: Fallback processing
29      previous_error: ${{ result.error }}
30
31  cleanup:
32    if: ${{ always() }}
33    uses: xema/agent
34    with:
35      task: Cleanup resources
36      status: ${{ result.status }}
37
38  notify-failure:
39    needs: [primary-task, fallback-task]
40    if: ${{ failure() }}
41    uses: xema/webhook
42    with:
43      url: https://alerts.acme.com/webhook
44      payload:
45        status: failed
46        reason: Task failed after retries

Features:

  • Default retry policy
  • Failure condition
  • Fallback job
  • Always cleanup
  • Failure notification

Next: Read Best Practices for conventions and tips.