version: 37
jobs:
  - name: CI for UAT
    steps:
      - !CheckoutStep
        name: checkout code
        cloneCredential: !DefaultCredential {}
        withLfs: false
        withSubmodules: false
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !GenerateChecksumStep
        name: generate package checksum
        files: package-lock.json yarn.lock
        targetFile: checksum
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !SetupCacheStep
        name: set up npm cache
        key: node_modules_@file:checksum@
        loadKeys:
          - node_modules
        paths:
          - node_modules
        uploadStrategy: UPLOAD_IF_NOT_HIT
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !SetBuildVersionStep
        name: set build version
        buildVersion: "@tag@"
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !CommandStep
        name: build & test
        runInContainer: true
        image: node
        interpreter: !DefaultInterpreter
          commands: |
            npm install
            npm run build
        useTTY: true
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !BuildImageStep
        name: build docker image
        dockerfile: ./docker/Dockerfile
        output: !RegistryOutput
          tags: hrms-git.chin.in.th/bma-hrms/hrms-landing:@build_version@ hrms-git.chin.in.th/bma-hrms/hrms-landing:latest
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
    triggers:
      - !TagCreateTrigger
        tags: uat-*
        branches: main
    retryCondition: never
    maxRetries: 3
    retryDelay: 30
    timeout: 14400
  - name: CI for PROD
    steps:
      - !CheckoutStep
        name: checkout code
        cloneCredential: !DefaultCredential {}
        withLfs: false
        withSubmodules: false
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !GenerateChecksumStep
        name: generate package checksum
        files: package-lock.json yarn.lock
        targetFile: checksum
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !SetupCacheStep
        name: set up npm cache
        key: node_modules_@file:checksum@
        loadKeys:
          - node_modules
        paths:
          - node_modules
        uploadStrategy: UPLOAD_IF_NOT_HIT
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !SetBuildVersionStep
        name: set build version
        buildVersion: "@tag@"
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !CommandStep
        name: build & test
        runInContainer: true
        image: node
        interpreter: !DefaultInterpreter
          commands: |
            npm install
            npm run build
        useTTY: true
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
      - !BuildImageStep
        name: build docker image
        dockerfile: ./docker/Dockerfile
        output: !RegistryOutput
          tags: hrms-git.bangkok.go.th/bma-hrms/hrms-landing:@build_version@ hrms-git.bangkok.go.th/bma-hrms/hrms-landing:latest
        condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
    triggers:
      - !TagCreateTrigger
        tags: prod-*
        branches: main
    retryCondition: never
    maxRetries: 3
    retryDelay: 30
    timeout: 14400
