anchors:
  notify_failure_to_pr: &notify_failure_to_pr
    put: chromedriver-helper-pr
    params: {path: chromedriver-helper-pr, status: failure}

groups:
  - name: master
    jobs:
%     RUBIES[:mri].last(2).each do |ruby_version|
      - ruby-<%= ruby_version %>
%     end
%     RUBIES[:jruby].last(2).each do |ruby_version|
      - jruby-<%= ruby_version %>
%     end

  - name: PRs
    jobs:
      - pr-pending
%     RUBIES[:mri].last(1).each do |ruby_version|
      - ruby-<%= ruby_version %>-pr
%     end
%     RUBIES[:jruby].last(1).each do |ruby_version|
      - jruby-<%= ruby_version %>-pr
%     end
      - pr-success

  - name: allow-failure
    jobs:
%     RUBIES[:windows].last(2).each do |ruby_version|
      - win-ruby-<%= ruby_version %>-devkit
%     end

resource_types:
- name: pull-request
  type: docker-image
  source:
    repository: jtarchie/pr

resources:
  - name: ci
    type: git
    source:
      uri: https://github.com/flavorjones/chromedriver-helper/
      branch: master
      disable_ci_skip: true # always get the latest pipeline configuration

  - name: chromedriver-helper
    type: git
    source:
      uri: https://github.com/flavorjones/chromedriver-helper/
      branch: master
      ignore_paths:
        - concourse/**

  - name: chromedriver-helper-pr
    type: pull-request
    source:
      repo: flavorjones/chromedriver-helper
      access_token: {{github-repo-status-access-token}}
      ignore_paths:
        - concourse/**

jobs:
% RUBIES[:mri].last(2).each do |ruby_version|
  - name: ruby-<%= ruby_version %>
    public: true
    plan:
      - get: ci
      - get: chromedriver-helper
        trigger: true
      - task: rake-test
        config:
          platform: linux
          image_resource:
            type: docker-image
            source: {repository: ruby, tag: "<%= ruby_version %>"}
          inputs:
            - name: ci
            - name: chromedriver-helper
          run:
            path: ci/concourse/tasks/rake-test/run.sh
% end

% RUBIES[:windows].last(2).each do |ruby_version|
  - name: win-ruby-<%= ruby_version %>-devkit
    public: true
    plan:
      - get: ci
      - get: chromedriver-helper
        trigger: true
      - task: rake-test
        config:
          platform: windows
          inputs:
            - name: ci
            - name: chromedriver-helper
          params:
            WIN_RUBY_VERSION: "<%= ruby_version %>"
          run:
            path: powershell
            args: ["-File", "ci/concourse/tasks/rake-test/run.ps1"]
% end

% RUBIES[:jruby].last(2).each do |ruby_version|
  - name: jruby-<%= ruby_version %>
    public: true
    plan:
      - get: ci
      - get: chromedriver-helper
        trigger: true
      - task: rake-test
        config:
          platform: linux
          image_resource:
            type: docker-image
            source: {repository: jruby, tag: "<%= ruby_version %>-jdk"}
          inputs:
            - name: ci
            - name: chromedriver-helper
          params:
            JAVA_OPTS: "-Dfile.encoding=UTF8" # https://github.com/docker-library/openjdk/issues/32
          run:
            path: ci/concourse/tasks/rake-test/run.sh
% end

  #
  #  PRs
  #
  - name: pr-pending
    public: true
    plan:
      - get: ci
      - get: chromedriver-helper-pr
        trigger: true
        version: every
      - put: chromedriver-helper-pr
        params: {path: chromedriver-helper-pr, status: pending}

% RUBIES[:mri].last(1).each do |ruby_version|
  - name: ruby-<%= ruby_version %>-pr
    public: true
    max_in_flight: 1
    plan:
      - get: ci
      - get: chromedriver-helper-pr
        trigger: true
        version: every
        passed: [pr-pending]
      - task: rake-test
        config:
          platform: linux
          image_resource:
            type: docker-image
            source: {repository: ruby, tag: "<%= ruby_version %>"}
          inputs:
            - name: ci
            - name: chromedriver-helper-pr
              path: chromedriver-helper
          run:
            path: ci/concourse/tasks/rake-test/run.sh
        on_failure: *notify_failure_to_pr
% end

% RUBIES[:jruby].last(1).each do |ruby_version|
  - name: jruby-<%= ruby_version %>-pr
    public: true
    max_in_flight: 1
    plan:
      - get: ci
      - get: chromedriver-helper-pr
        trigger: true
        version: every
        passed: [pr-pending]
      - task: rake-test
        attempts: 3
        config:
          platform: linux
          image_resource:
            type: docker-image
            source: {repository: jruby, tag: "<%= ruby_version %>-jdk"}
          inputs:
            - name: ci
            - name: chromedriver-helper-pr
              path: chromedriver-helper
          params:
            JAVA_OPTS: "-Dfile.encoding=UTF8" # https://github.com/docker-library/openjdk/issues/32
          run:
            path: ci/concourse/tasks/rake-test/run.sh
        on_failure: *notify_failure_to_pr
% end

  - name: pr-success
    public: true
    disable_manual_trigger: true
    plan:
      - get: chromedriver-helper-pr
        trigger: true
        version: every
        passed:
%         RUBIES[:mri].last(1).each do |ruby_version|
          - ruby-<%= ruby_version %>-pr
%         end
%         RUBIES[:jruby].last(1).each do |ruby_version|
          - jruby-<%= ruby_version %>-pr
%         end
      - put: chromedriver-helper-pr
        params: {path: chromedriver-helper-pr, status: success}
