apiVersion: tekton.dev/v1alpha1
kind: Condition
metadata:
  name: verify-no-file-exists-without-resource
spec:
  params:
    - name: "path"
  resources:
    - name: optional-workspace
      type: git
      optional: true
  check:
    image: alpine
    script: 'test ! -f $(resources.optional-workspace.path)/$(params.path)'
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: pipeline-git-repo
spec:
  type: git
  params:
    - name: revision
      value: master
    - name: url
      value: https://github.com/tektoncd/pipeline
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: list-pipeline-repo-files
spec:
  resources:
    inputs:
      - name: optional-workspace
        type: git
        optional: true
  steps:
    - name: run-ls
      image: ubuntu
      script: 'ls -al $(inputs.resources.optional-workspace.path)'
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: pipeline-list-pipeline-repo-files
spec:
  resources:
    - name: pipeline-source-repo
      type: git
  params:
    - name: "path"
      default: "README.md"
  tasks:
    - name: list-pipeline-repo-files-1
      taskRef:
        name: list-pipeline-repo-files
      conditions:
        - conditionRef: "verify-no-file-exists-without-resource"
          params:
            - name: "path"
              value: "$(params.path)"
# NOTE: Resource "optional-workspace" is declared as optional in Condition
# No resource specified for the condition here since its optional
# "DO NOT UNCOMMENT THE FOLLOWING RESOURCE"
#          resources:
#            - name: optional-workspace
#              resource: pipeline-source-repo
      resources:
        inputs:
          - name: optional-workspace
            resource: pipeline-source-repo
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: demo-condtional-pr-without-condition-resource
spec:
  pipelineRef:
    name: pipeline-list-pipeline-repo-files
  serviceAccountName: 'default'
  resources:
    - name: pipeline-source-repo
      resourceRef:
        name: pipeline-git-repo
