---
resources:
  - name: baphomet-js-git
    type: git
    icon: git
    source:
      uri: ssh://git@git.nulloctet.com:8437/warricksothr/baphomet-js.git
      private_key: |
        ((pull_key))
      branch: master
  - name: baphomet-js-git-develop
    type: git
    icon: git
    source:
      uri: ssh://git@git.nulloctet.com:8437/warricksothr/baphomet-js.git
      private_key: |
        ((pull_key))
      branch: develop

jobs:
  - name: test
    plan:
      - get: baphomet-js-git
        trigger: true
      - task: run-tests
        config:
          platform: linux
          image_resource:
            type: registry-image
            source: { repository: node, tag: "12.14-stretch" }
          inputs:
            - name: baphomet-js-git
          run:
            path: /bin/sh
            args:
              - -c
              - |
                echo "Node Version: $(node --version)"
                echo "NPM Version: $(npm --version)"
                cd baphomet-js-git
                npm install
                npm test
  - name: test-develop
    plan:
      - get: baphomet-js-git-develop
        trigger: true
      - task: run-tests
        config:
          platform: linux
          image_resource:
            type: registry-image
            source: { repository: node, tag: "12.14-stretch" }
          inputs:
            - name: baphomet-js-git-develop
          run:
            path: /bin/sh
            args:
              - -c
              - |
                echo "Node Version: $(node --version)"
                echo "NPM Version: $(npm --version)"
                cd baphomet-js-git-develop
                npm install
                npm test
  - name: package
    plan:
      - get: baphomet-js-git
        passed: [test]
        trigger: true
      - task: capture-version
        config:
          platform: linux
          image_resource:
            type: registry-image
            source: { repository: bitnami/git, tag: "2-debian-9" }
          inputs:
            - name: baphomet-js-git
          outputs:
            - name: baphomet-js-version
          run:
            path: /bin/sh
            args:
              - -c
              - |
                cd baphomet-js-git
                chmod +x ././scripts/get_*.sh
                echo $(./scripts/get_build.sh) > ../baphomet-js-version/build.info
                echo $(./scripts/get_version.sh) > ../baphomet-js-version/version.info
                cat ../baphomet-js-version/build.info
      - task: package
        config:
          platform: linux
          image_resource:
            type: registry-image
            source: { repository: debian, tag: "stretch-slim" }
          inputs:
            - name: baphomet-js-git
            - name: baphomet-js-version
          outputs:
            - name: package
          run:
            path: /bin/sh
            args:
              - -c
              - |
                mkdir tmp
                cd tmp
                cp ../baphomet-js-version/version.info .
                cp ../baphomet-js-version/build.info .
                cp ../baphomet-js-git/package*.json .
                cp ../baphomet-js-git/index.js .
                cp -r ../baphomet-js-git/assets .
                cp -r ../baphomet-js-git/bot .
                cp -r ../baphomet-js-git/data .
                cp ../baphomet-js-git/README.md .
                cp ../baphomet-js-git/LICENSE.md .
                tar -zcvf ../package/baphomet-js-$(cat version.info).tgz ./*