name: '$(Major).$(Minor).$(Patch)-$(SourceBranchName)'

trigger:
  branches:
    include:
      - '*'

variables:
  # Major Version einstellen
  - name: 'Major'
    value: '1'
  # Minor Version einstellen
  - name: 'Minor'
    value: '1'
  - name: 'Patch'
    value: "$[counter(format('{0}.{1}', variables['Major'], variables['Minor']),400)]"

jobs:
  - job: cibuild_fast
    displayName: ISAClient CI Fast
    pool:
      name: 'Default'
      demands:
        - Agent.OS -equals Linux
        - docker
    condition: and(ne(variables['Build.SourceBranch'], 'refs/heads/develop'), ne(variables['Build.SourceBranch'], 'refs/heads/integration'), ne(variables['Build.SourceBranch'], 'refs/heads/master'), not(startsWith(variables['Build.SourceBranch'], 'refs/heads/hotfix/')), not(startsWith(variables['Build.SourceBranch'], 'refs/heads/release/')))
    steps:
      - task: npmAuthenticate@0
        displayName: 'npm auth'
        inputs:
          workingFile: .npmrc
      - task: Docker@2
        displayName: 'build ISAClient Debug'
        inputs:
          command: 'build'
          Dockerfile: Dockerfile
          buildContext:
          tags: '$(Build.BuildNumber)-$(Build.SourceVersion)'
          arguments: '--build-arg SEMVERSION=$(Major).$(Minor).$(Patch)'

  - job: cibuild_debug
    displayName: ISAClient CI Debug
    pool:
      name: 'Default'
      demands:
        - Agent.OS -equals Linux
        - docker
    condition: eq(variables['Build.SourceBranch'], 'refs/heads/develop')
    steps:
      - task: npmAuthenticate@0
        displayName: 'npm auth'
        inputs:
          workingFile: .npmrc
      - task: Docker@2
        displayName: 'build ISAClient Debug'
        inputs:
          containerRegistry: 'Harbor isa'
          repository: isa/ui
          command: 'build'
          Dockerfile: Dockerfile
          buildContext:
          tags: 'debug-$(Build.BuildNumber)-$(Build.SourceVersion)'
          arguments: '--no-cache --build-arg SEMVERSION=$(Major).$(Minor).$(Patch)'

      - task: Docker@2
        displayName: 'push ISAClient Debug'
        inputs:
          containerRegistry: 'Harbor isa'
          repository: 'isa/ui'
          command: 'push'
          tags: 'debug-$(Build.BuildNumber)-$(Build.SourceVersion)'

      - task: PublishBuildArtifacts@1
        displayName: 'Artefakt veröffentlichen: HelmValues'
        inputs:
          PathtoPublish: helmvalues
          ArtifactName: HelmValues

      - task: PublishBuildArtifacts@1
        displayName: 'Artefakt veröffentlichen: ISAClientConfigs'
        inputs:
          PathtoPublish: 'apps/sales/src/assets/config'
          ArtifactName: SalesConfigs

  - job: cibuild_prod
    displayName: ISAClient CI Prod
    pool:
      name: 'Default'
      demands:
        - Agent.OS -equals Linux
        - docker
    condition: or(eq(variables['Build.SourceBranch'], 'refs/heads/integration'), eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/hotfix/'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'))
    steps:
      - task: npmAuthenticate@0
        displayName: 'npm auth'
        inputs:
          workingFile: .npmrc
      - task: Docker@2
        displayName: 'build ISAClient Prod'
        inputs:
          containerRegistry: 'Harbor isa'
          repository: isa/ui
          command: 'build'
          Dockerfile: Dockerfile
          buildContext:
          tags: 'prod-$(Build.BuildNumber)-$(Build.SourceVersion)'
          arguments: '--no-cache --build-arg IS_PRODUCTION=true --build-arg SEMVERSION=$(Major).$(Minor).$(Patch)'

      - task: Docker@2
        displayName: 'push ISAClient Prod'
        inputs:
          containerRegistry: 'Harbor isa'
          repository: 'isa/ui'
          command: 'push'
          tags: 'prod-$(Build.BuildNumber)-$(Build.SourceVersion)'

      - task: PublishBuildArtifacts@1
        displayName: 'Artefakt veröffentlichen: HelmValues'
        inputs:
          PathtoPublish: helmvalues
          ArtifactName: HelmValues

      - task: PublishBuildArtifacts@1
        displayName: 'Artefakt veröffentlichen: ISAClientConfigs'
        inputs:
          PathtoPublish: 'apps/sales/src/assets/config'
          ArtifactName: SalesConfigs
    