{{- define "dockerbuild-verify-go" -}}
- name: dockerbuild-verify
  taskRef:
    kind: Task
    name: dockerbuild-verify
  runAfter:
    - sonar
    - dockerfile-lint
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source
{{- end -}}

{{- define "build-pipeline-golang-image-build-push-common" -}}
- name: kaniko-build
  taskRef:
    kind: Task
    name: kaniko
  runAfter:
    - sonar
    - get-version
    - build
  params:
    - name: codebase-name
      value: "$(params.CODEBASE_NAME)"
    - name: image-tag
      value: "$(tasks.get-version.results.IS_TAG)"
    - name: image-tar
      value: "$(params.CODEBASE_NAME)_$(tasks.get-version.results.IS_TAG)"
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source
{{- end -}}

{{- define "golang-build-common" -}}

# we don't need subPath for the source workspace, since we need to have access to both folders
# /source and /cache
- name: build
  taskRef:
    kind: Task
    name: golang
  runAfter:
    - get-cache
  params:
    - name: BASE_IMAGE
      value: $(params.image)
    - name: EXTRA_COMMANDS
      value: |
        # we checkout the source code in the /source directory
        # and hold cache in the /cache directory
        cd source
        make build
        make test
  workspaces:
    - name: source
      workspace: shared-workspace

- name: sonar
  taskRef:
    kind: Task
    name: sonarqube-general
  runAfter:
    - build
  params:
    - name: SONAR_PROJECT_KEY
      value: $(params.CODEBASE_NAME)
    - name: SONAR_PROJECT_NAME
      value: $(params.CODEBASE_NAME)
    - name: branch
      value: $(params.git-source-revision)
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source

{{- end -}}

{{- define "golang-review-common" -}}

# we don't need subPath for the source workspace, since we need to have access to both folders
# /source and /cache
- name: build
  taskRef:
    kind: Task
    name: golang
  runAfter:
    - get-cache
  params:
    - name: BASE_IMAGE
      value: $(params.image)
    - name: EXTRA_COMMANDS
      value: |
        # we checkout the source code in the /source directory
        # and hold cache in the /cache directory
        cd source
        make build
        make test
  workspaces:
    - name: source
      workspace: shared-workspace

- name: sonar
  taskRef:
    kind: Task
    name: sonarqube-general
  runAfter:
    - build
  params:
    - name: SONAR_PROJECT_KEY
      value: $(params.CODEBASE_NAME)
    - name: SONAR_PROJECT_NAME
      value: $(params.CODEBASE_NAME)
    - name: target-branch
      value: $(params.targetBranch)
    - name: source-branch
      value: $(params.git-source-revision)
    - name: key-id
      value: $(params.changeNumber)
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source

{{- end -}}
