##########################################################
resource_types:
- name: s3-multi
  type: docker-image
  source:
    repository: kdvolder/s3-resource-simple
- name: slack-notification
  type: docker-image
  source:
    repository: cfcommunity/slack-notification-resource
    tag: latest
#########################################################
resources:
- name: docker-git
  type: git
  source:
    uri: git@github.com:spring-projects/sts4.git
    branch: {{branch}}
    private_key: {{rsa_id}}
    paths:
    - concourse/docker
- name: sts4
  type: git
  source:
    uri: git@github.com:spring-projects/sts4.git
    branch: {{branch}}
    private_key: {{rsa_id}}
- name: tasks
  type: git
  source:
    uri: git@github.com:spring-projects/sts4.git
    branch: {{branch}}
    paths:
    - concourse/tasks
    private_key: {{rsa_id}}
- name: sts4-out
  type: git
  source:
    uri: git@github.com:spring-projects/sts4.git
    branch: {{branch}}
    private_key: {{rsa_id}}
- name: s3-boot-properties-vsix-snapshot
  type: s3
  source:
    bucket: {{s3_bucket}}
    access_key_id: {{s3_accesskey}}
    secret_access_key: {{s3_secretkey}}
    region_name: {{s3_region}}
    regexp: sts4/vscode-extensions/snapshots/vscode-boot-properties-(.*).vsix
- name: s3-boot-java-vsix-snapshot
  type: s3
  source:
    bucket: {{s3_bucket}}
    access_key_id: {{s3_accesskey}}
    secret_access_key: {{s3_secretkey}}
    region_name: {{s3_region}}
    regexp: sts4/vscode-extensions/snapshots/vscode-boot-java-(.*).vsix
- name: s3-concourse-vsix-snapshot
  type: s3
  source:
    bucket: {{s3_bucket}}
    access_key_id: {{s3_accesskey}}
    secret_access_key: {{s3_secretkey}}
    region_name: {{s3_region}}
    regexp: sts4/vscode-extensions/snapshots/vscode-concourse-(.*).vsix
- name: s3-bosh-vsix-snapshot
  type: s3
  source:
    bucket: {{s3_bucket}}
    access_key_id: {{s3_accesskey}}
    secret_access_key: {{s3_secretkey}}
    region_name: {{s3_region}}
    regexp: sts4/vscode-extensions/snapshots/vscode-bosh-(.*).vsix
- name: s3-manifest-yaml-vsix-snapshot
  type: s3
  source:
    bucket: {{s3_bucket}}
    access_key_id: {{s3_accesskey}}
    secret_access_key: {{s3_secretkey}}
    region_name: {{s3_region}}
    regexp: sts4/vscode-extensions/snapshots/vscode-manifest-yaml-(.*).vsix
- name: s3-manifest-yaml-fatjar-snapshot
  type: s3
  source:
    bucket: {{s3_bucket}}
    access_key_id: {{s3_accesskey}}
    secret_access_key: {{s3_secretkey}}
    region_name: {{s3_region}}
    regexp: sts4/fatjars/snapshots/manifest-yaml-language-server-(.*).jar
- name: snapshot-website
  type: s3-multi
  source:
    bucket: {{s3_prod_bucket}}
    access_key_id: {{s3_prod_accesskey}}
    secret_access_key: {{s3_prod_secretkey}}
    region_name: {{s3_region}}
    path: snapshot/STS4/vscode-extensions
    options:
    - "--acl public-read"
- name: slack-notification
  type: slack-notification
  source:
    url: {{slack_webhook}}
- name: docker-image
  type: docker-image
  source:
    username: {{docker_hub_username}}
    password: {{docker_hub_password}}
    repository: kdvolder/sts4-build-env
- name: maven-cache
  type: s3
  source:
    bucket: {{s3_bucket}}
    access_key_id: {{s3_accesskey}}
    secret_access_key: {{s3_secretkey}}
    region_name: {{s3_region}}
    regexp: mvn-caches/sts4-(.*).tar.gz
- name: version
  type: semver
  source:
    driver: s3
    bucket: {{s3_bucket}}
    key: versions/vscode-extensions
    access_key_id: {{s3_accesskey}}
    secret_access_key: {{s3_secretkey}}
    region_name: {{s3_region}}
    initial_version: 0.0.5-RC.6
########################################################################################
jobs:
- name: build-docker-image
  serial: true
  plan:
  - get: docker-git
    trigger: true
  - put: docker-image
    params:
      build: docker-git/concourse/docker
    get_params: 
      skip_download: true
- name: build-mvn-cache
  serial: true
  plan:
  - get: sts4
    trigger: true
  - task: build-mvn-cache
    file: sts4/concourse/tasks/build-mvn-cache.yml
  - put: maven-cache
    params:
      file: out/*.tar.gz
- name: build-boot-properties-vsix-snapshot
  plan:
  - aggregate:
    - get: sts4
      trigger: true
    - get: maven-cache
  - task: build-boot-properties-vsix-snapshot
    attempts: 3 #Because its a bit flaky with the maven bits
    file: sts4/concourse/tasks/build-vsix.yml
    params:
      extension_id: vscode-boot-properties
    on_failure:
      put: slack-notification
      params:
        text: |
           Concourse ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME} has failed!
  - put: s3-boot-properties-vsix-snapshot
    params: 
      file: out/vscode-boot-properties-*.vsix
      acl: public-read
- name: build-boot-java-vsix-snapshot
  plan:
  - aggregate:
    - get: sts4
      trigger: true
    - get: maven-cache
  - task: build-boot-java-vsix-snapshot
    attempts: 3 #Because its a bit flaky with the maven bits
    file: sts4/concourse/tasks/build-vsix.yml
    params:
      extension_id: vscode-boot-java
    on_failure:
      put: slack-notification
      params:
        text: |
           Concourse ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME} has failed!
  - put: s3-boot-java-vsix-snapshot
    params: 
      file: out/vscode-boot-java-*.vsix
      acl: public-read
- name: build-consourse-vsix-snapshot
  plan:
  - aggregate:
    - get: sts4
      trigger: true
    - get: maven-cache
  - task: build-consourse-vsix-snapshot
    file: sts4/concourse/tasks/build-vsix.yml
    params:
      extension_id: vscode-concourse
    on_failure:
      put: slack-notification
      params:
        text: |
           Concourse ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME} has failed!
  - put: s3-concourse-vsix-snapshot
    params: 
      file: out/vscode-concourse-*.vsix
      acl: public-read
- name: build-bosh-vsix-snapshot
  plan:
  - aggregate:
    - get: sts4
      trigger: true
    - get: maven-cache
  - task: build-bosh-vsix-snapshot
    file: sts4/concourse/tasks/build-vsix.yml
    params:
      extension_id: vscode-bosh
    on_failure:
      put: slack-notification
      params:
        text: |
           Concourse ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME} has failed!
  - put: s3-bosh-vsix-snapshot
    params: 
      file: out/vscode-bosh-*.vsix
      acl: public-read
- name: build-manifest-yaml-vsix-snapshot
  plan:
  - aggregate:
    - get: sts4
      trigger: true
    - get: maven-cache
  - task: build-manifest-yaml-vsix-snapshot
    file: sts4/concourse/tasks/build-vsix.yml
    params:
      extension_id: vscode-manifest-yaml
    on_failure:
      put: slack-notification
      params:
        text: |
           Concourse ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME} has failed!
  - aggregate:
    - put: s3-manifest-yaml-vsix-snapshot
      params: 
        file: out/vscode-manifest-yaml-*.vsix
        acl: public-read
    - put: s3-manifest-yaml-fatjar-snapshot
      params: 
        file: out/*.jar
        acl: public-read
- name: trigger-rc-build
  serial: true
  plan: 
  - aggregate:
    - get: sts4
      passed:
      - build-manifest-yaml-vsix-snapshot
      - build-consourse-vsix-snapshot
    - do:
      - get: version
        params:
          pre: RC
      - put: version
        params:
          file: version/version
  - put: sts4-out
    params:
      repository: sts4
      only_tag: true
      tag_prefix: V_
      tag: version/version
- name: build-concourse-rc
  plan:
  - aggregate:
    - get: maven-cache
      passed:
      - build-consourse-vsix-snapshot
    - get: sts4
      passed: 
      - trigger-rc-build
    - get: version
      trigger: true
      passed: 
      - trigger-rc-build
  - task: build-concourse-rc
    file: sts4/concourse/tasks/rc-build.yml
    params:
      extension_id: vscode-concourse
    on_failure:
      put: slack-notification
      params:
        text: |
           Concourse ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME} has failed!      
  - put: s3-concourse-vsix-snapshot
    params: 
      file: out/vscode-concourse-*.vsix
      acl: public-read
    on_success:
      put: slack-notification
      params:
        text_file: s3-concourse-vsix-snapshot/url
        icon_url: https://raw.githubusercontent.com/spring-projects/sts4/master/vscode-extensions/vscode-concourse/icon.png
        text: |
          Concourse ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME} has succeed!
          Release candidate available for testing $TEXT_FILE_CONTENT
- name: build-manifest-yaml-rc
  plan:
  - aggregate:
    - get: maven-cache
      passed:
      - build-manifest-yaml-vsix-snapshot
    - get: sts4
      passed: 
      - trigger-rc-build
    - get: version
      trigger: true
      passed: 
      - trigger-rc-build
  - task: build-manifest-yaml-rc
    file: sts4/concourse/tasks/rc-build.yml
    params:
      extension_id: vscode-manifest-yaml
    on_failure:
      put: slack-notification
      params:
        text: |
           Concourse ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME} has failed!      
  - put: s3-manifest-yaml-vsix-snapshot
    params: 
      file: out/vscode-manifest-yaml-*.vsix
      acl: public-read
    on_success:
      put: slack-notification
      params:
        text_file: s3-manifest-yaml-vsix-snapshot/url
        icon_url: https://raw.githubusercontent.com/spring-projects/sts4/master/vscode-extensions/vscode-manifest-yaml/icon.png
        text: |
          Concourse ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME} has succeed!
          Release candidate available for testing $TEXT_FILE_CONTENT
- name: publish-release
  serial: true
  plan:
  - aggregate:
    - get: tasks
    - get: sts4
      passed:
      - build-manifest-yaml-rc
      - build-concourse-rc
    - get: s3-concourse-vsix-snapshot
      passed:
      - build-concourse-rc
    - get: s3-manifest-yaml-vsix-snapshot
      passed:
      - build-manifest-yaml-rc
    - get: version
      passed:
      - build-concourse-rc
      - build-manifest-yaml-rc
      params:
        bump: final
  - task: publish-vsix-releases
    file: tasks/concourse/tasks/publish-vsix-releases.yml
    input_mapping:
      sts4: tasks
    params:
      vsce_token: {{vsce_token}}
    on_failure:
      put: slack-notification
      params:
        channel: "@kdvolder"
        text: |
           Concourse ${BUILD_PIPELINE_NAME}/${BUILD_JOB_NAME}/${BUILD_NAME} has failed!      
    on_success:
      put: slack-notification
      params:
        channel: "#tooling-projects"
        text_file: version/version
        text: |
          STS 4 VScode Extensions $TEXT_FILE_CONTENT released
          Releases now available on Vscode Marketplace:
           • <https://marketplace.visualstudio.com/items?itemName=Pivotal.vscode-manifest-yaml|Cloudfoundry Manifest YML Support>
           • <https://marketplace.visualstudio.com/items?itemName=Pivotal.vscode-concourse|Concourse CI Pipeline Editor>
  - aggregate:
    - put: sts4-out
      params:
        repository: sts4
        only_tag: true
        tag: version/version
        tag_prefix: V_
    - put: version
      params:
        file: version/version
- name: post-release
  serial: true
  plan:
  - aggregate:
    - get: sts4
    - get: version
      params:
        bump: patch
      trigger: true
      passed:
      - publish-release
  - task: bump-package-json-versions
    file: sts4/concourse/tasks/bump-package-json-versions.yml
  - put: sts4-out
    params:
      repository: out
      rebase: true
  - put: version
    params:
      file: version/version    
- name: build-snapshot-website
  serial: true
  plan:
  - aggregate:
    - get: sts4
    - get: s3-bosh-vsix-snapshot
      trigger: true
      passed:
      - build-bosh-vsix-snapshot
    - get: s3-manifest-yaml-vsix-snapshot
      trigger: true
      passed:
      - build-manifest-yaml-vsix-snapshot
    - get: s3-boot-properties-vsix-snapshot
      trigger: true
      passed:
      - build-boot-properties-vsix-snapshot
    - get: s3-boot-java-vsix-snapshot
      trigger: true
      passed:
      - build-boot-java-vsix-snapshot
    - get: s3-concourse-vsix-snapshot
      trigger: true
      passed:
      - build-consourse-vsix-snapshot
  - task: build-website
    file: sts4/concourse/tasks/build-website.yml
  - put: snapshot-website
    params:
      path: website
