resources:
  - name: code
    type: git
    source:
      branch: {{GIT_BRANCH}}
      skip_ssl_verification: true
      uri: git@github.com:myorg/myapp.git
      private_key: {{GIT_PK}}

  - name: pipeline
    type: git
    source:
      branch: master
      skip_ssl_verification: true
      uri: git@github.com:myorg/myapp.git
      private_key: {{GIT_PK}}
  - name: pcf
    type: cf
    source:
      api: {{CF_API}}
      organization: {{CF_ORG}}
      password: {{CF_PASSWORD}}
      skip_cert_check: true
      space: {{CF_SPACE}}
      username: {{CF_USER}}


jobs:
- name: unit-test
  public: true
  plan:
  - get: code
    trigger: true
  - task: build-and-test
    config:
      platform: windows
      run:
        path: powershell
        args:
        - ./build.ps1
        - -mode test -targetFramework 4.6.1
        dir: code
      inputs:
      - name: code

- name: publish
  public: true
  plan:
  - get: pipeline
    trigger: true
  - get: code
    passed:
    - unit-test
    trigger: true
  - task: assemble-services
    file: pipeline/assemble-services.yml
    params:
      TERM: xterm
      PCF_API: {{CF_API}}
      PCF_USER: {{CF_USER}}
      PCF_PASSWORD: {{CF_PASSWORD}}
      PCF_ORG: {{CF_ORG}}
      PCF_SPACE:  {{CF_SPACE}}
      BUILD_ENV: {{BUILD_ENV}}
  - task: build-and-publish
    config:
      platform: windows
      run:
        path: powershell
        args:
        - ./build.ps1
        - -mode publish
        dir: code
      inputs:
      - name: code
        path: ""
      outputs:
      - name: publish
        path: ""
  - put: pcf
    params:
      manifest: pipeline/dev/manifest.yml
      path: publish/Pivotal.Security.Entitlements

- name: smoke-test
  public: true
  plan:
  - get: code
    passed:
    - publish
  - get: pcf
    passed:
    - publish
    trigger: true
  - task: run-tests
    config:
      platform: linux
      image_resource:
        type: docker-image
        source:
          repository: postman/newman_ubuntu1404
      run:
        path: sh
        args:
        - ./run_newman.sh
        - {{BUILD_ENV}}
        dir: ./code/tests/smoke-tests
      inputs:
      - name: code
      outputs:
      - name: stamp