{{- define "helm-library-build-common" -}}
- name: helm-lint
  taskRef:
    kind: Task
    name: helm-library-lint
  runAfter:
    - get-version
  params:
    - name: CHART_DIR
      value: $(params.CHART_DIR)
    - name: CT_CONFIGS_DIR
      value: $(params.CT_CONFIGS_DIR)
    - name: TARGET_BRANCH
      value: $(params.git-source-revision)
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source

- name: helm-dependency-update
  taskRef:
    kind: Task
    name: helm-library-dependency-update
  runAfter:
    - helm-lint
  params:
    - name: CHART_DIR
      value: $(params.CHART_DIR)
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source

- name: helm-template
  taskRef:
    kind: Task
    name: helm-library-template
  runAfter:
    - helm-dependency-update
  params:
    - name: CHART_DIR
      value: $(params.CHART_DIR)
    - name: release_name
      value: $(params.CODEBASE_NAME)
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source
{{- end -}}

{{- define "helm-library-review-common" -}}
- name: fetch-target-branch
  taskRef:
    kind: Task
    name: git-cli
  runAfter:
    - fetch-repository
  params:
    - name: GIT_USER_EMAIL
      value: edp-ci@edp.ci-user
    - name: GIT_USER_NAME
      value: edp-ci
    - name: GIT_SCRIPT
      value: |
        git fetch --unshallow
        git fetch origin $(params.targetBranch):refs/remotes/origin/$(params.targetBranch)
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source
    - name: ssh-directory
      workspace: ssh-creds

- name: helm-lint
  taskRef:
    kind: Task
    name: helm-library-lint
  runAfter:
    - fetch-target-branch
  params:
    - name: CHART_DIR
      value: $(params.CHART_DIR)
    - name: CT_CONFIGS_DIR
      value: $(params.CT_CONFIGS_DIR)
    - name: TARGET_BRANCH
      value: $(params.targetBranch)
    - name: CHART_VERSION_INCREMENT
      value: $(params.CHART_VERSION_INCREMENT)
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source

- name: helm-dependency-update
  taskRef:
    kind: Task
    name: helm-library-dependency-update
  runAfter:
    - helm-lint
  params:
    - name: CHART_DIR
      value: $(params.CHART_DIR)
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source

- name: helm-template
  taskRef:
    kind: Task
    name: helm-library-template
  runAfter:
    - helm-dependency-update
  params:
    - name: CHART_DIR
      value: $(params.CHART_DIR)
    - name: release_name
      value: $(params.CODEBASE_NAME)
  workspaces:
    - name: source
      workspace: shared-workspace
      subPath: source
{{- end -}}
