resource_types:
- name: artifactory-resource
  type: docker-image
  source:
    repository: springio/artifactory-resource
    tag: 0.0.11
- name: pull-request
  type: docker-image
  source:
    repository: jtarchie/pr
- name: github-status-resource
  type: docker-image
  source:
    repository: dpb587/github-status-resource
    tag: master
- name: slack-notification
  type: docker-image
  source:
    repository: cfcommunity/slack-notification-resource
    tag: latest
resources:
- name: git-repo
  type: git
  source:
    uri: ((github-repo))
    username: ((github-username))
    password: ((github-password))
    branch: ((branch))
    ignore_paths: ["ci/images/*"]
- name: git-repo-windows
  type: git
  source:
    uri: ((github-repo))
    username: ((github-username))
    password: ((github-password))
    branch: ((branch))
    ignore_paths: ["ci/images/*"]
    git_config:
    - name: core.autocrlf
      value: true
- name: git-pull-request
  type: pull-request
  source:
    access_token: ((github-ci-pull-request-token))
    repo: spring-io/initializr
    base: ((branch))
    ignore_paths: ["ci/*"]
- name: ci-images-git-repo
  type: git
  source:
    uri: ((github-repo))
    branch: ((branch))
    paths: ["ci/images/*"]
- name: initializr-ci-image
  type: docker-image
  source:
    repository: springci/initializr-ci-image
    username: ((docker-hub-username))
    password: ((docker-hub-password))
    tag: ((branch))
- name: artifactory-repo
  type: artifactory-resource
  source:
    uri: ((artifactory-server))
    username: ((artifactory-username))
    password: ((artifactory-password))
    build_name: ((build-name))
- name: slack-alert
  type: slack-notification
  source:
    url: ((slack-webhook-url))
- name: repo-status-build
  type: github-status-resource
  source:
    repository: spring-io/initializr
    access_token: ((github-ci-status-token))
    branch: ((branch))
    context: build
- name: github-release
  type: github-release
  source:
    owner: spring-io
    repository: initializr
    access_token: ((github-ci-release-token))
    pre_release: false
- name: 24h
  type: time
  source: {interval: 24h}
jobs:
- name: build-initializr-ci-image
  plan:
  - get: ci-images-git-repo
    trigger: true
  - put: initializr-ci-image
    params:
      build: ci-images-git-repo/ci/images
      dockerfile: ci-images-git-repo/ci/images/initializr-ci-image/Dockerfile
- name: build
  serial: true
  public: true
  plan:
  - get: git-repo
    trigger: true
  - get: initializr-ci-image
  - put: repo-status-build
    params: { state: "pending", commit: "git-repo" }
  - do:
    - task: build-project
      image: initializr-ci-image
      file: git-repo/ci/tasks/build-project.yml
    - put: artifactory-repo
      params: &artifactory-params
        repo: libs-snapshot-local
        folder: distribution-repository
        build_uri: "https://ci.spring.io/teams/${BUILD_TEAM_NAME}/pipelines/${BUILD_PIPELINE_NAME}/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME}"
        build_number: "${BUILD_PIPELINE_NAME}-${BUILD_JOB_NAME}-${BUILD_NAME}"
        disable_checksum_uploads: true
        exclude:
        - "**/*.effective-pom"
        - "**/initializr-service-sample/**"
    on_failure:
      do:
      - put: repo-status-build
        params: { state: "failure", commit: "git-repo" }
      - put: slack-alert
        params:
          text: ":concourse-failed: <https://ci.spring.io/teams/${BUILD_TEAM_NAME}/pipelines/${BUILD_PIPELINE_NAME}/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME}|failure: ${BUILD_PIPELINE_NAME} ${BUILD_JOB_NAME}>"
          silent: true
          icon_emoji: ":concourse:"
          username: concourse-ci
  - put: repo-status-build
    params: { state: "success", commit: "git-repo" }
  - put: slack-alert
    params:
      text: ":concourse-succeeded: <https://ci.spring.io/teams/${BUILD_TEAM_NAME}/pipelines/${BUILD_PIPELINE_NAME}/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME}|success: ${BUILD_PIPELINE_NAME} ${BUILD_JOB_NAME}>"
      silent: true
      icon_emoji: ":concourse:"
      username: concourse-ci
- name: windows-build
  serial: true
  public: true
  plan:
  - get: 24h
    trigger: true
  - get: git-repo
    resource: git-repo-windows
  - task: build-project
    tags: [WIN64]
    file: git-repo/ci/tasks/build-project-windows.yml
- name: build-pull-requests
  serial: true
  public: true
  plan:
  - get: initializr-ci-image
  - get: git-repo
    resource: git-pull-request
    trigger: true
    version: every
  - do:
    - put: git-pull-request
      params:
        path: git-repo
        status: pending
    - task: build-project
      image: initializr-ci-image
      file: git-repo/ci/tasks/build-pr-project.yml
      on_success:
        put: git-pull-request
        params:
          path: git-repo
          status: success
      on_failure:
        put: git-pull-request
        params:
          path: git-repo
          status: failure
- name: stage-release
  serial: true
  plan:
  - get: initializr-ci-image
  - get: git-repo
    trigger: false
  - task: stage
    image: initializr-ci-image
    file: git-repo/ci/tasks/stage.yml
  - put: artifactory-repo
    params:
      <<: *artifactory-params
      repo: libs-staging-local
  - put: git-repo
    params:
      repository: stage-git-repo
- name: promote-release
  serial: true
  plan:
  - get: initializr-ci-image
  - get: git-repo
    trigger: false
  - get: artifactory-repo
    trigger: false
    passed: [stage-release]
    params:
      save_build_info: true
  - task: promote
    image: initializr-ci-image
    file: git-repo/ci/tasks/promote.yml
    params:
      ARTIFACTORY_SERVER: ((artifactory-server))
      ARTIFACTORY_USERNAME: ((artifactory-username))
      ARTIFACTORY_PASSWORD: ((artifactory-password))
  - task: generate-release-notes
    file: git-repo/ci/tasks/generate-release-notes.yml
    params:
      GITHUB_ORGANIZATION: spring-io
      GITHUB_REPO: initializr
      GITHUB_USERNAME: ((github-username))
      GITHUB_TOKEN: ((github-ci-release-token))
  - put: github-release
    params:
      name: generated-release-notes/version
      tag: generated-release-notes/version
      body:  generated-release-notes/body
groups:
- name: "Build"
  jobs:
  - build
- name: "Windows Build"
  jobs:
  - windows-build
- name: "Build Pull Requests"
  jobs:
  - "build-pull-requests"
- name: "CI Images"
  jobs:
  - build-initializr-ci-image
- name: "Release"
  jobs:
  - stage-release
  - promote-release
