apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
  name: unidesk-ci
  namespace: unidesk-ci
  labels:
    app.kubernetes.io/name: unidesk-ci
    app.kubernetes.io/component: triggers
    app.kubernetes.io/part-of: unidesk
spec:
  serviceAccountName: unidesk-ci-runner
  triggers:
    - name: github-push
      interceptors:
        - ref:
            name: cel
          params:
            - name: filter
              value: >-
                body.ref.startsWith('refs/heads/') &&
                body.after.matches('^[0-9a-f]{40}$')
      bindings:
        - ref: unidesk-ci-github-push
      template:
        ref: unidesk-ci
---
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerBinding
metadata:
  name: unidesk-ci-github-push
  namespace: unidesk-ci
  labels:
    app.kubernetes.io/name: unidesk-ci
    app.kubernetes.io/component: triggers
    app.kubernetes.io/part-of: unidesk
spec:
  params:
    - name: repo-url
      value: $(body.repository.clone_url)
    - name: revision
      value: $(body.after)
---
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
  name: unidesk-ci
  namespace: unidesk-ci
  labels:
    app.kubernetes.io/name: unidesk-ci
    app.kubernetes.io/component: triggers
    app.kubernetes.io/part-of: unidesk
spec:
  params:
    - name: repo-url
      default: https://github.com/pikasTech/unidesk
    - name: revision
  resourcetemplates:
    - apiVersion: tekton.dev/v1
      kind: PipelineRun
      metadata:
        generateName: unidesk-ci-
        namespace: unidesk-ci
        labels:
          app.kubernetes.io/name: unidesk-ci
          app.kubernetes.io/part-of: unidesk
          unidesk.ai/revision: $(tt.params.revision)
      spec:
        pipelineRef:
          name: unidesk-ci
        taskRunTemplate:
          serviceAccountName: unidesk-ci-runner
        params:
          - name: repo-url
            value: $(tt.params.repo-url)
          - name: revision
            value: $(tt.params.revision)
        workspaces:
          - name: shared-workspace
            persistentVolumeClaim:
              claimName: unidesk-ci-cache
