apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
  annotations:
    chains.tekton.dev/signed: "true"
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"tekton.dev/v1","kind":"PipelineRun","metadata":{"annotations":{"kubernetes.io/ssh-auth":"kubernetes.io/dockerconfigjson"},"name":"pipelinerun-go","namespace":"default"},"spec":{"params":[{"name":"git-repo","value":"https://github.com/jkhelil/gohandler.git"},{"name":"git-revision","value":"main"},{"name":"output-image","value":"quay.io/jkhelil/gohandler"}],"pipelineRef":{"name":"pipeline-go"},"workspaces":[{"name":"shared","volumeClaimTemplate":{"spec":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"1Gi"}}}}},{"name":"docker-credentials","secret":{"secretName":"push-secret"}}]}}
    kubernetes.io/ssh-auth: kubernetes.io/dockerconfigjson
    pipeline.tekton.dev/affinity-assistant: affinity-assistant-a2cc7c241b
    pipeline.tekton.dev/release: eaf7dc1
    results.tekton.dev/childReadyForDeletion: "true"
    results.tekton.dev/record: default/results/78bf41d5-e649-4933-a919-7e5bc2f19d07/records/6296a391-367c-4294-b015-7b886ba7a786
    results.tekton.dev/result: default/results/78bf41d5-e649-4933-a919-7e5bc2f19d07
    results.tekton.dev/stored: "true"
    tekton.dev/categories: Git
    tekton.dev/displayName: git clone
    tekton.dev/pipelines.minVersion: 0.38.0
    tekton.dev/platforms: linux/amd64,linux/s390x,linux/ppc64le,linux/arm64
    tekton.dev/tags: git
  creationTimestamp: "2025-09-10T06:42:56Z"
  finalizers:
  - results.tekton.dev/taskrun
  - chains.tekton.dev
  generation: 1
  labels:
    app.kubernetes.io/managed-by: tekton-pipelines
    app.kubernetes.io/version: "0.10"
    tekton.dev/memberOf: tasks
    tekton.dev/pipeline: pipeline-go
    tekton.dev/pipelineRun: pipelinerun-go
    tekton.dev/pipelineRunUID: 78bf41d5-e649-4933-a919-7e5bc2f19d07
    tekton.dev/pipelineTask: git-clone
    tekton.dev/task: git-clone
  name: pipelinerun-go-git-clone
  namespace: default
  ownerReferences:
  - apiVersion: tekton.dev/v1
    blockOwnerDeletion: true
    controller: true
    kind: PipelineRun
    name: pipelinerun-go
    uid: 78bf41d5-e649-4933-a919-7e5bc2f19d07
  resourceVersion: "24408"
  uid: 6296a391-367c-4294-b015-7b886ba7a786
spec:
  params:
  - name: url
    value: https://github.com/jkhelil/gohandler.git
  - name: revision
    value: main
  serviceAccountName: default
  taskRef:
    params:
    - name: catalog
      value: tekton-catalog-tasks
    - name: type
      value: artifact
    - name: name
      value: git-clone
    - name: version
      value: 0.10.0
    - name: kind
      value: task
    resolver: hub
  timeout: 1h0m0s
  workspaces:
  - name: output
    persistentVolumeClaim:
      claimName: pvc-a7115f3c43
status:
  artifacts: {}
  completionTime: "2025-09-10T06:43:12Z"
  conditions:
  - lastTransitionTime: "2025-09-10T06:43:12Z"
    message: All Steps have completed executing
    reason: Succeeded
    status: "True"
    type: Succeeded
  podName: pipelinerun-go-git-clone-pod
  provenance:
    featureFlags:
      awaitSidecarReadiness: true
      coschedule: workspaces
      enableAPIFields: beta
      enableProvenanceInStatus: true
      enforceNonfalsifiability: none
      maxResultSize: 4096
      resultExtractionMethod: termination-message
      runningInEnvWithInjectedSidecars: true
      verificationNoMatchPolicy: ignore
    refSource:
      digest:
        sha256: 781608e5d52015dda0e397203c163bebfb98899922120bcf554febb679bbab23
      uri: https://artifacthub.io/api/v1/packages/tekton-task/tekton-catalog-tasks/git-clone/0.10.0
  results:
  - name: commit
    type: string
    value: e6d423cdf00c5ea84934429f135dd5a349b3799d
  - name: committer-date
    type: string
    value: "1708347851"
  - name: url
    type: string
    value: https://github.com/jkhelil/gohandler.git
  startTime: "2025-09-10T06:42:56Z"
  steps:
  - container: step-clone
    imageID: ghcr.io/tektoncd-catalog/git-clone@sha256:b7fe6c370322586feb555c807f3fae7ca5d62c20ebbcca987114e69366151957
    name: clone
    terminated:
      containerID: containerd://f6f9f968254d8945f9b8469965a8db94e6dac5024c569cbf61b6a9a5095b49ea
      exitCode: 0
      finishedAt: "2025-09-10T06:43:11Z"
      message: '[{"key":"commit","value":"e6d423cdf00c5ea84934429f135dd5a349b3799d","type":1},{"key":"committer-date","value":"1708347851","type":1},{"key":"url","value":"https://github.com/jkhelil/gohandler.git","type":1}]'
      reason: Completed
      startedAt: "2025-09-10T06:43:03Z"
    terminationReason: Completed
  taskSpec:
    description: |-
      These Tasks are Git tasks to work with repositories used by other tasks in your Pipeline.
      The git-clone Task will clone a repo from the provided url into the output Workspace. By default the repo will be cloned into the root of your Workspace. You can clone into a subdirectory by setting this Task's subdirectory param. This Task also supports sparse checkouts. To perform a sparse checkout, pass a list of comma separated directory patterns to this Task's sparseCheckoutDirectories param.
    params:
    - description: Repository URL to clone from.
      name: url
      type: string
    - default: ""
      description: Revision to checkout. (branch, tag, sha, ref, etc...)
      name: revision
      type: string
    - default: ""
      description: Refspec to fetch before checking out revision.
      name: refspec
      type: string
    - default: "true"
      description: Initialize and fetch git submodules.
      name: submodules
      type: string
    - default: "1"
      description: Perform a shallow clone, fetching only the most recent N commits.
      name: depth
      type: string
    - default: "true"
      description: Set the `http.sslVerify` global git config. Setting this to `false`
        is not advised unless you are sure that you trust your git remote.
      name: sslVerify
      type: string
    - default: ca-bundle.crt
      description: file name of mounted crt using ssl-ca-directory workspace. default
        value is ca-bundle.crt.
      name: crtFileName
      type: string
    - default: ""
      description: Subdirectory inside the `output` Workspace to clone the repo into.
      name: subdirectory
      type: string
    - default: ""
      description: Define the directory patterns to match or exclude when performing
        a sparse checkout.
      name: sparseCheckoutDirectories
      type: string
    - default: "true"
      description: Clean out the contents of the destination directory if it already
        exists before cloning.
      name: deleteExisting
      type: string
    - default: ""
      description: HTTP proxy server for non-SSL requests.
      name: httpProxy
      type: string
    - default: ""
      description: HTTPS proxy server for SSL requests.
      name: httpsProxy
      type: string
    - default: ""
      description: Opt out of proxying HTTP/HTTPS requests.
      name: noProxy
      type: string
    - default: "true"
      description: Log the commands that are executed during `git-clone`'s operation.
      name: verbose
      type: string
    - default: ghcr.io/tektoncd-catalog/git-clone:v1.1.0
      description: The image providing the git-init binary that this Task runs.
      name: gitInitImage
      type: string
    - default: /home/git
      description: |
        Absolute path to the user's home directory.
      name: userHome
      type: string
    results:
    - description: The precise commit SHA that was fetched by this Task.
      name: commit
      type: string
    - description: The precise URL that was fetched by this Task.
      name: url
      type: string
    - description: The epoch timestamp of the commit that was fetched by this Task.
      name: committer-date
      type: string
    steps:
    - computeResources: {}
      env:
      - name: HOME
        value: /home/git
      - name: PARAM_URL
        value: https://github.com/jkhelil/gohandler.git
      - name: PARAM_REVISION
        value: main
      - name: PARAM_REFSPEC
      - name: PARAM_SUBMODULES
        value: "true"
      - name: PARAM_DEPTH
        value: "1"
      - name: PARAM_SSL_VERIFY
        value: "true"
      - name: PARAM_CRT_FILENAME
        value: ca-bundle.crt
      - name: PARAM_SUBDIRECTORY
      - name: PARAM_DELETE_EXISTING
        value: "true"
      - name: PARAM_HTTP_PROXY
      - name: PARAM_HTTPS_PROXY
      - name: PARAM_NO_PROXY
      - name: PARAM_VERBOSE
        value: "true"
      - name: PARAM_SPARSE_CHECKOUT_DIRECTORIES
      - name: PARAM_USER_HOME
        value: /home/git
      - name: WORKSPACE_OUTPUT_PATH
        value: /workspace/output
      - name: WORKSPACE_SSH_DIRECTORY_BOUND
        value: "false"
      - name: WORKSPACE_SSH_DIRECTORY_PATH
      - name: WORKSPACE_BASIC_AUTH_DIRECTORY_BOUND
        value: "false"
      - name: WORKSPACE_BASIC_AUTH_DIRECTORY_PATH
      - name: WORKSPACE_SSL_CA_DIRECTORY_BOUND
        value: "false"
      - name: WORKSPACE_SSL_CA_DIRECTORY_PATH
      image: ghcr.io/tektoncd-catalog/git-clone:v1.1.0
      name: clone
      script: |
        #!/usr/bin/env sh
        set -eu

        if [ "${PARAM_VERBOSE}" = "true" ] ; then
          set -x
        fi

        if [ "${WORKSPACE_BASIC_AUTH_DIRECTORY_BOUND}" = "true" ] ; then
          cp "${WORKSPACE_BASIC_AUTH_DIRECTORY_PATH}/.git-credentials" "${PARAM_USER_HOME}/.git-credentials"
          cp "${WORKSPACE_BASIC_AUTH_DIRECTORY_PATH}/.gitconfig" "${PARAM_USER_HOME}/.gitconfig"
          chmod 400 "${PARAM_USER_HOME}/.git-credentials"
          chmod 400 "${PARAM_USER_HOME}/.gitconfig"
        fi

        if [ "${WORKSPACE_SSH_DIRECTORY_BOUND}" = "true" ] ; then
          cp -R "${WORKSPACE_SSH_DIRECTORY_PATH}" "${PARAM_USER_HOME}"/.ssh
          chmod 700 "${PARAM_USER_HOME}"/.ssh
          chmod -R 400 "${PARAM_USER_HOME}"/.ssh/*
        fi

        if [ "${WORKSPACE_SSL_CA_DIRECTORY_BOUND}" = "true" ] ; then
           export GIT_SSL_CAPATH="${WORKSPACE_SSL_CA_DIRECTORY_PATH}"
           if [ "${PARAM_CRT_FILENAME}" != "" ] ; then
              export GIT_SSL_CAINFO="${WORKSPACE_SSL_CA_DIRECTORY_PATH}/${PARAM_CRT_FILENAME}"
           fi
        fi
        CHECKOUT_DIR="${WORKSPACE_OUTPUT_PATH}/${PARAM_SUBDIRECTORY}"

        cleandir() {
          # Delete any existing contents of the repo directory if it exists.
          #
          # We don't just "rm -rf ${CHECKOUT_DIR}" because ${CHECKOUT_DIR} might be "/"
          # or the root of a mounted volume.
          if [ -d "${CHECKOUT_DIR}" ] ; then
            # Delete non-hidden files and directories
            rm -rf "${CHECKOUT_DIR:?}"/*
            # Delete files and directories starting with . but excluding ..
            rm -rf "${CHECKOUT_DIR}"/.[!.]*
            # Delete files and directories starting with .. plus any other character
            rm -rf "${CHECKOUT_DIR}"/..?*
          fi
        }

        if [ "${PARAM_DELETE_EXISTING}" = "true" ] ; then
          cleandir || true
        fi

        test -z "${PARAM_HTTP_PROXY}" || export HTTP_PROXY="${PARAM_HTTP_PROXY}"
        test -z "${PARAM_HTTPS_PROXY}" || export HTTPS_PROXY="${PARAM_HTTPS_PROXY}"
        test -z "${PARAM_NO_PROXY}" || export NO_PROXY="${PARAM_NO_PROXY}"

        git config --global --add safe.directory "${WORKSPACE_OUTPUT_PATH}"
        /ko-app/git-init \
          -url="${PARAM_URL}" \
          -revision="${PARAM_REVISION}" \
          -refspec="${PARAM_REFSPEC}" \
          -path="${CHECKOUT_DIR}" \
          -sslVerify="${PARAM_SSL_VERIFY}" \
          -submodules="${PARAM_SUBMODULES}" \
          -depth="${PARAM_DEPTH}" \
          -sparseCheckoutDirectories="${PARAM_SPARSE_CHECKOUT_DIRECTORIES}"
        cd "${CHECKOUT_DIR}"
        RESULT_SHA="$(git rev-parse HEAD)"
        EXIT_CODE="$?"
        if [ "${EXIT_CODE}" != 0 ] ; then
          exit "${EXIT_CODE}"
        fi
        RESULT_COMMITTER_DATE="$(git log -1 --pretty=%ct)"
        printf "%s" "${RESULT_COMMITTER_DATE}" > "/tekton/results/committer-date"
        printf "%s" "${RESULT_SHA}" > "/tekton/results/commit"
        printf "%s" "${PARAM_URL}" > "/tekton/results/url"
      securityContext:
        runAsNonRoot: true
        runAsUser: 65532
      volumeMounts:
      - mountPath: /home/git
        name: user-home
    volumes:
    - emptyDir: {}
      name: user-home
    workspaces:
    - description: The git repo will be cloned onto the volume backing this Workspace.
      name: output
    - description: |
        A .ssh directory with private key, known_hosts, config, etc. Copied to
        the user's home before git commands are executed. Used to authenticate
        with the git remote when performing the clone. Binding a Secret to this
        Workspace is strongly recommended over other volume types.
      name: ssh-directory
      optional: true
    - description: |
        A Workspace containing a .gitconfig and .git-credentials file. These
        will be copied to the user's home before any git commands are run. Any
        other files in this Workspace are ignored. It is strongly recommended
        to use ssh-directory over basic-auth whenever possible and to bind a
        Secret to this Workspace over other volume types.
      name: basic-auth
      optional: true
    - description: |
        A workspace containing CA certificates, this will be used by Git to
        verify the peer with when fetching or pushing over HTTPS.
      name: ssl-ca-directory
      optional: true
