---
version: 2
plan:
  project-key: AJL
  key: HOSTLISTCMPLRBUILD
  name: hostlist-compiler  -  build
variables:
  dockerContainer: adguard/node-ssh:18.13--0

stages:
  - Build:
      manual: false
      final: false
      jobs:
        - Build

Build:
  key: BUILD
  other:
    clean-working-dir: true
  docker:
    image: "${bamboo.dockerContainer}"
    volumes:
      ${system.YARN_DIR}: "${bamboo.cacheYarn}"
  tasks:
    - checkout:
        force-clean-build: true
    - script:
        interpreter: SHELL
        scripts:
          - |-
            set -e
            set -x

            # Fix mixed logs
            exec 2>&1

            # install dependencies at the beginning
            yarn install ${bamboo.varsYarn}

            yarn build-txt
    - inject-variables:
        file: dist/build.txt
        scope: RESULT
        namespace: inject
    - script:
        interpreter: SHELL
        scripts:
          - |-
            #!/bin/bash
            set -e
            set -x

            # Fix mixed logs
            exec 2>&1

            # Fail if version was not bumped
            if [ "$(git tag -l "v${bamboo.inject.version}")" ]; then
              echo "Build failed!"
              echo "Error: Tag v${bamboo.inject.version} already exists. Bump the version in package.json before building"
              exit 1
            fi

            yarn pack --filename hostlist-compiler.tgz

            # clean up at the end
            rm -rf node_modules
    - any-task:
        plugin-key: com.atlassian.bamboo.plugins.vcs:task.vcs.tagging
        configuration:
          selectedRepository: defaultRepository
          tagName: v${bamboo.inject.version}
  artifacts:
    - name: hostlist-compiler.tgz
      location: ./
      pattern: hostlist-compiler.tgz
      shared: true
      required: true
  requirements:
    - adg-docker: true

triggers: []

branches:
  create: manually
  delete: never
  link-to-jira: true

labels: []

other:
  concurrent-build-plugin: system-default
