{{ if has "gerrit" .Values.global.gitProviders }}
{{ if or ( .Values.pipelines.deployableResources.js.angular ) ( .Values.pipelines.deployableResources.js.express ) ( .Values.pipelines.deployableResources.js.next ) ( .Values.pipelines.deployableResources.js.react ) ( .Values.pipelines.deployableResources.js.vue )}}
{{- $registry := include "edp-tekton.registry" . -}}
{{- $raw := include "edp-tekton.resourceMapping.js" . | trimAll "[]" -}}
{{- $resources := $raw | split " " -}}
{{- range $framework := $resources }}
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
  name: gerrit-npm-{{ $framework }}-lib-build-default
  labels:
    app.edp.epam.com/pipelinetype: build
    {{- include "edp-tekton.labels" $ | nindent 4 }}
spec:
  description: "The Build pipeline for building {{ $framework }} library with NPM (default versioning)"
  workspaces:
    - name: shared-workspace
    - name: ssh-creds
  params:
    - name: pipelineUrl
      default: https://portal-{{ $.Release.Namespace }}.{{ $.Values.global.dnsWildCard }}/c/main/pipelines/$(context.pipelineRun.namespace)/$(context.pipelineRun.name)
      type: string
    - name: git-source-url
      default: "https://github.com/epmd-edp/javascript-npm-{{ $framework }}"
      description: git url to clone
      type: string
    - name: git-source-revision
      description: 'git revision to checkout (branch, tag, sha, ref…)'
      default: "edp"
      type: string
    - name: CODEBASE_NAME
      default: '{{ $framework }}-npm-edp-version'
      description: "Project name"
      type: string
    - name: CODEBASEBRANCH_NAME
      description: "Codebasebranch name"
      type: string
    - name: image
      default: '{{ $registry }}/library/node:18.20.3-alpine3.20'
      description: "npm image version"
      type: string
    - name: changeNumber
      description: Change number from Merge Request
    - name: patchsetNumber
      description: Patchset number from Merge Request
    - name: TICKET_NAME_PATTERN
      description: "Ticket name pattern"
      default: ""
    - name: COMMIT_MESSAGE_PATTERN
      description: "Pattern to validate a commit message"
      default: ""
    - name: COMMIT_MESSAGE
      description: "Commit message"
      default: ""
    - name: JIRA_ISSUE_METADATA_PAYLOAD
      description: "Jira Payload"
      default: ""
    - name: JIRA_SERVER
      description: "Jira server name"
      default: ""

{{- include "build-result" $ | nindent 2 }}

  tasks:

{{- include "gerrit-build-start" $ | nindent 4 }}

    - name: get-version
      taskRef:
        kind: Task
        name: get-version-default
      runAfter:
        - init-values
      params:
        - name: BRANCH_NAME
          value: $(params.git-source-revision)
        - name: BASE_IMAGE
          value: $(params.image)

{{- include "get-cache" $ | nindent 4 }}

    - name: update-build-number
      taskRef:
        kind: Task
        name: update-build-number-npm-default
      runAfter:
        - get-version
      params:
        - name: BASE_IMAGE
          value: $(params.image)
        - name: VERSION
          value: $(tasks.get-version.results.VERSION)
      workspaces:
        - name: source
          workspace: shared-workspace
          subPath: source

{{ include "security-edp" . | nindent 4 }}

{{ include "js-npm-build-common" . | nindent 4 }}

{{- include "save-cache" $ | nindent 4 }}

{{ include "build-pipeline-lib-end" . | nindent 4 }}

{{ include "finally-block-default" . | nindent 2 }}

---
{{ end }}
{{ end }}
{{ end }}
