<commit_before><%
  require 'yaml'
  config = YAML.load_file(File.join(__dir__, '..', 'config', 'cnb-builder.yml'))

  stacks = config['stacks']
  builders = config['builders']
%>
---
resources:
  - name: buildpack-acceptance-tests
    type: git
    source:
      uri: https://github.com/cloudfoundry/buildpack-acceptance-tests
      branch: master

  - name: buildpacks-ci
    type: git
    source:
      uri: {{buildpacks-ci-git-uri-public}}
      branch: {{buildpacks-ci-git-uri-public-branch}}

  - name: cnb-tools-git
    type: git
    source:
      uri: <EMAIL>:cloudfoundry/cnb-tools.git
      private_key: {{cf-buildpacks-eng-github-ssh-key}}
      branch: master

  - name: cnb2cf
    type: git
    source:
      uri: <EMAIL>:cloudfoundry/cnb2cf
      branch: master
      private_key: {{cf-buildpacks-eng-github-ssh-key}}

  - name: repo
    type: git
    source:
      uri: git@github.com:cloudfoundry/<%= language %>-cnb
      branch: master
      private_key: {{cf-buildpacks-eng-github-ssh-key}}

  - name: buildpack-github-release
    type: github-release
    source:
      user: {{buildpacks-github-org}}
      repository: <%= language %>-cnb
      access_token: {{buildpacks-github-token}}

  - name: v2-release-candidate
    type: s3
    source:
      bucket: {{buildpack-release-candidates-bucket}}
      regexp: shims/<%= language %>/<%= language %>-buildpack-v(\d+\.\d+\.\d+-rc\.\d+).zip
      access_key_id: {{pivotal-offline-buildpacks-s3-access-key}}
      secret_access_key: {{pivotal-offline-buildpacks-s3-secret-key}}

<% if language == "dotnet-core" %>
  <% stacks.each do |stack, stack_data| %>
    <% if stack != "tiny" %>
  - name: <%= stack %>-version
    type: semver
    source:
      initial_version: 0.0.1
      bucket: cnb-versions
      key: builder/<%= stack %>
      access_key_id: {{pivotal-offline-buildpacks-s3-access-key}}
      secret_access_key: {{pivotal-offline-buildpacks-s3-secret-key}}
    <% end %>
  <% end %>

  - name: packager
    type: git
    source:
      uri: https://github.com/cloudfoundry/libcfbuildpack
      branch: master

  - name: cnb-lifecycle-release
    type: github-release
    source:
      repository: lifecycle
      user: buildpacks
      access_token: {{buildpacks-github-token}}

  - name: pack-release
    type: github-release
    source:
      user: buildpacks
      repository: pack
      access_token: {{buildpacks-github-token}}
      globs: ['*-linux.tgz']

<% end %>

  - name: <%= language %>-cnb-version
    type: semver
    source:
      initial_version: 0.0.1
      driver: gcs
      bucket: artifacts.cf-buildpacks.appspot.com
      key: cnb-versions/<%= language %>-family-version
      json_key: {{gcp-service-account-key}}

  - name: edge-environments
    type: pool
    source:
      branch: master
      pool: edge-environments
      private_key: {{public-buildpacks-ci-robots-private-key}}
      uri: git@github.com:cloudfoundry/public-buildpacks-ci-robots

  - name: edge-buildpack-specs-pool
    type: pool
    source:
      branch: master
      pool: edge-shared-environments
      private_key: {{public-buildpacks-ci-robots-private-key}}
      uri: git@github.com:cloudfoundry/public-buildpacks-ci-robots

  - name: env-repo
    type: git
    source:
      uri: <EMAIL>@github.<EMAIL>:cloudfoundry/buildpacks-envs
      branch: master
      private_key: {{buildpacks-envs-private-key}}

  - name: ci-image
    type: registry-image
    source:
      repository: cfbuildpacks/ci
      username: {{buildpacks-docker-username}}
      password: {{<PASSWORD>-docker-password}}

jobs:
  # Updates
  - name: update-cnb-tools
    public: true
    serial: true
    serial_groups: [ update ]
    plan:
      - in_parallel:
          - get: buildpacks-ci
          - get: cnb-tools-git
            trigger: true
          - get: buildpack
            resource: repo
      - task: update-cnb-tools
        file: buildpacks-ci/tasks/update-cnb-tools/task.yml
      - put: repo
        params:
          repository: buildpack-artifacts
          rebase: true

<% tested_stacks = [] %>
<% if language == "dotnet-core" %>
<% builders.each do |builder_name, builder_data|%>
  <% if builder_data['stack']!= "tiny" && !builder_data['private'] %>
    <% tested_stacks.push("specs-integration-#{builder_data['stack']}") %>
  - name: specs-integration-<%= builder_data['stack'] %>
    plan:
      - in_parallel:
        - get: repo
          trigger: true
          passed: [create-rc]
        - get: pack
          resource: pack-release
          trigger: true
        - get: buildpacks-ci
        - get: ci-image
        - get: version
          params: {pre: "rc"}
          resource: <%= builder_data["version-key"] %>-version
        - get: packager
        - get: v2-release-candidate
          trigger: true
          passed: [create-rc]
        - get: lifecycle # use lifecycle version in order.toml instead?
          resource: cnb-lifecycle-release
          trigger: true
      - task: get-cnb-sources
        image: ci-image
        config:
          platform: linux
          inputs:
            - name: repo
          outputs:
            - name: sources
          run:
            path: bash
            args:
              - -cl
              - |
                cp -r repo sources/<%= language %>-cnb
      - task: write-order-toml
        image: ci-image
        config:
          platform: linux
          outputs:
            - name: cnb-builder
          run:
            path: bash
            args:
              - -cl
              - |
                echo -e "\ndescription = 'test-builder for <%= language %>-cnb'\n[[order]]\ngroup = [{ id = 'org.cloudfoundry.<%= language %>' }]\n" > cnb-builder/<%= builder_data['stack'] %>-order.toml
      - task: create-builder-image
        image: ci-image
        file: buildpacks-ci/tasks/create-builder/task.yml
        privileged: true
        params:
          <% (builder_data['builder-image-params'] || []).each do |key, value| %>
          <%= key %>: <%= value%>
          <% end %>
      - task: generate-test-config
        image: ci-image
        file: buildpacks-ci/tasks/set-test-configuration/task.yml
        params:
          STACK: <%= builder_data["stack"] %>

      - task: metabuildpack-integration
        image: ci-image
        file: buildpacks-ci/tasks/metabuildpack-integration/task.yml
        privileged: true
        params:
          CNB_RUN_IMAGE: <%= builder_data['builder-image-params']['RUN_IMAGE'] %>
          CNB_BUILD_IMAGE: <%= builder_data['builder-image-params']['BUILD_IMAGE'] %>
          GIT_TOKEN: {{buildpacks-github-token}}
    <% end %>
  <% end %>
<% end %>


  - name: create-rc
    serial: true
    public: true
    plan:
      - in_parallel:
          - get: buildpacks-ci
          - get: ci-image
          - get: version
            resource: <%= language %>-cnb-version
            params:
              pre: rc
          - get: repo
            trigger: true
          - get: cnb2cf
      - task: create-v2-candidate
        image: ci-image
        file: buildpacks-ci/tasks/cnb/build-v2/task.yml
      - task: promote-candidate-to-rc
        image: ci-image
        file: buildpacks-ci/tasks/cnb/promote-v2-to-rc/task.yml
        params:
          LANGUAGE: <%= language %>
      - put: v2-release-candidate
        params:
          file: release-candidate/*.zip
      - put: version
        resource: <%= language %>-cnb-version
        params:
          file: version/version

  - name: test-rc
    serial: true
    public: true
    plan:
      - in_parallel:
          - get: buildpack-acceptance-tests
          - get: ci-image
          - put: edge-environments
            params:
              acquire: true
          - put: edge-buildpack-specs-pool
            params:
              claim: <%= language %>
          - get: buildpacks-ci
          - get: version
            resource: <%= language %>-cnb-version
            passed: [create-rc]
            params:
              pre: rc
          - get: repo
            <% if language == "dotnet-core" %>
            passed: <%= tested_stacks %>
            <% else %>
            passed: [create-rc]
            <% end %>
          - get: env-repo
          - get: v2-release-candidate
            <% if language == "dotnet-core" %>
            passed: <%= tested_stacks %>
            trigger: true
            <% else %>
            passed: [create-rc]
            trigger: true
            <% end %>
      - task: create-cf-space
        image: ci-image
        file: buildpacks-ci/tasks/create-cf-space/task.yml
        output_mapping: {cf-space: cf-space-cflinuxfs3}
        params:
          ENV_POOL_RESOURCE: edge-environments
          ENVS_DIR: env-repo
          ORG: pivotal
          SYSTEM_DOMAIN: buildpacks-gcp.ci.cf-app.com
          USERNAME: admin
      - task: v2-candidate-acceptance
        image: ci-image
        privileged: true
        file: buildpacks-ci/tasks/run-buildpack-acceptance/task.yml
        input_mapping:
          cf-space: cf-space-cflinuxfs3
          candidate: v2-release-candidate
        params:
          GIT_TOKEN: {{buildpacks-github-token}}
          BUILDPACK_ARTIFACT: release-candidate
          LANGUAGE: <%= language %>
    ensure:
      in_parallel:
        - task: delete-cf-space
          file: buildpacks-ci/tasks/delete-cf-space/task.yml
          input_mapping:
            cf-space: cf-space-cflinuxfs3
        - put: edge-environments
          params:
            release: edge-environments
        - put: edge-buildpack-specs-pool
          params:
            release: edge-buildpack-specs-pool

  - name: ship-it
    serial: true
    public: true
    plan:
      - in_parallel:
          - get: buildpacks-ci
          - get: buildpack
            resource: repo
            passed: [ test-rc ]
          - get: v2-release-candidate
            passed: [ test-rc ]
          - get: version
            resource: <%= language %>-cnb-version
            passed: [ test-rc ]
            params:
              bump: final
      - task: check-tag-not-already-added
        file: buildpacks-ci/tasks/check-tag-not-already-added/task.yml
      - put: repo
        params:
          repository: buildpack
          tag: version/version
          tag_prefix: v
          only_tag: true

  - name: buildpack-to-github
    serial: true
    public: true
    plan:
      - in_parallel:
          - get: buildpacks-ci
          - get: v2-release-candidate
            passed:
              - ship-it
          - get: version
            resource: <%= language %>-cnb-version
            params:
              bump: final
          - get: buildpack
            resource: repo
            passed:
              - ship-it
            trigger: true
      - task: collect-release-artifacts
        privileged: true
        file: buildpacks-ci/tasks/collect-release-artifacts/task.yml
        params:
          REPO: <%= language %>-cnb
          STACK: cflinuxfs3
          GITHUB_ACCESS_TOKEN: {{buildpacks-github-token}}
      - put: buildpack-github-release
        params:
          name: buildpack-artifacts/tag
          tag: buildpack-artifacts/tag
          body: buildpack-artifacts/release_notes
          globs:
            - buildpack-artifacts/*-v*.zip
            - buildpack-artifacts/*-v*.SHA256SUM.txt
      - put: version
        resource: <%= language %>-cnb-version
        params:
          bump: patch
<commit_msg>add job to create release stories on Sunday night<commit_after><%
  require 'yaml'
  config = YAML.load_file(File.join(__dir__, '..', 'config', 'cnb-builder.yml'))

  stacks = config['stacks']
  builders = config['builders']
%>
---
resource_types:
  - name: cron
    type: docker-image
    source:
      repository: cfbuildpacks/cron-resource

resources:
  - name: buildpack-acceptance-tests
    type: git
    source:
      uri: https://github.com/cloudfoundry/buildpack-acceptance-tests
      branch: master

  - name: buildpacks-ci
    type: git
    source:
      uri: {{buildpacks-ci-git-uri-public}}
      branch: {{buildpacks-ci-git-uri-public-branch}}

  - name: cnb-tools-git
    type: git
    source:
      uri: <EMAIL>:cloudfoundry/cnb-tools.git
      private_key: {{cf-buildpacks-eng-github-ssh-key}}
      branch: master

  - name: cnb2cf
    type: git
    source:
      uri: <EMAIL>:cloudfoundry/cnb2cf
      branch: master
      private_key: {{cf-buildpacks-eng-github-ssh-key}}

  - name: repo
    type: git
    source:
      uri: <EMAIL>:cloudfoundry/<%= language %>-cnb
      branch: master
      private_key: {{cf-buildpacks-eng-github-ssh-key}}

  - name: buildpack-github-release
    type: github-release
    source:
      user: {{buildpacks-github-org}}
      repository: <%= language %>-cnb
      access_token: {{buildpacks-github-token}}

  - name: v2-release-candidate
    type: s3
    source:
      bucket: {{buildpack-release-candidates-bucket}}
      regexp: shims/<%= language %>/<%= language %>-buildpack-v(\d+\.\d+\.\d+-rc\.\d+).zip
      access_key_id: {{pivotal-offline-buildpacks-s3-access-key}}
      secret_access_key: {{pivotal-offline-buildpacks-s3-secret-key}}

<% if language == "dotnet-core" %>
  <% stacks.each do |stack, stack_data| %>
    <% if stack != "tiny" %>
  - name: <%= stack %>-version
    type: semver
    source:
      initial_version: 0.0.1
      bucket: cnb-versions
      key: builder/<%= stack %>
      access_key_id: {{pivotal-offline-buildpacks-s3-access-key}}
      secret_access_key: {{pivotal-offline-buildpacks-s3-secret-key}}
    <% end %>
  <% end %>

  - name: packager
    type: git
    source:
      uri: https://github.com/cloudfoundry/libcfbuildpack
      branch: master

  - name: cnb-lifecycle-release
    type: github-release
    source:
      repository: lifecycle
      user: buildpacks
      access_token: {{buildpacks-github-token}}

  - name: pack-release
    type: github-release
    source:
      user: buildpacks
      repository: pack
      access_token: {{buildpacks-github-token}}
      globs: ['*-linux.tgz']

<% end %>

  - name: <%= language %>-cnb-version
    type: semver
    source:
      initial_version: 0.0.1
      driver: gcs
      bucket: artifacts.cf-buildpacks.appspot.com
      key: cnb-versions/<%= language %>-family-version
      json_key: {{gcp-service-account-key}}

  - name: edge-environments
    type: pool
    source:
      branch: master
      pool: edge-environments
      private_key: {{public-buildpacks-ci-robots-private-key}}
      uri: <EMAIL>:cloudfoundry/public-buildpacks-ci-robots

  - name: edge-buildpack-specs-pool
    type: pool
    source:
      branch: master
      pool: edge-shared-environments
      private_key: {{public-buildpacks-ci-robots-private-key}}
      uri: <EMAIL>:cloudfoundry/public-buildpacks-ci-robots

  - name: env-repo
    type: git
    source:
      uri: git@github.com:cloudfoundry/buildpacks-envs
      branch: master
      private_key: {{buildpacks-envs-private-key}}

  - name: ci-image
    type: registry-image
    source:
      repository: cfbuildpacks/ci
      username: {{buildpacks-docker-username}}
      password: {{<PASSWORD>}}


  - name: sunday-night
    type: cron
    source:
      expression: 0 18 * * 0
      location: {{current-timezone}}

  - name: feller
    type: git
    source:
      uri: <EMAIL>:pivotal/feller
      branch: master
      private_key: {{feller-deploy-key}}

jobs:
  - name: create-<%= language %>-release-story
    public: true
    serial: true
    plan:
      - get: sunday-night
        trigger: true
      - in_parallel:
        - get: buildpacks-ci
        - get: feller
      - task: create-<%= language %>-release-story
        file: buildpacks-ci/tasks/metabuildpack-release-story/task.yml
        params:
          LANGUAGE: <%= language %>
          TRACKER_PROJECT_ID: {{cf-buildpacks-public-tracker-id}}
          TRACKER_API_TOKEN: {{pivotal-tracker-api-token}}
          GITHUB_TOKEN: {{buildpacks-github-token}}

  # Updates
  - name: update-cnb-tools
    public: true
    serial: true
    serial_groups: [ update ]
    plan:
      - in_parallel:
          - get: buildpacks-ci
          - get: cnb-tools-git
            trigger: true
          - get: buildpack
            resource: repo
      - task: update-cnb-tools
        file: buildpacks-ci/tasks/update-cnb-tools/task.yml
      - put: repo
        params:
          repository: buildpack-artifacts
          rebase: true

<% tested_stacks = [] %>
<% if language == "dotnet-core" %>
<% builders.each do |builder_name, builder_data|%>
  <% if builder_data['stack']!= "tiny" && !builder_data['private'] %>
    <% tested_stacks.push("specs-integration-#{builder_data['stack']}") %>
  - name: specs-integration-<%= builder_data['stack'] %>
    plan:
      - in_parallel:
        - get: repo
          trigger: true
          passed: [create-rc]
        - get: pack
          resource: pack-release
          trigger: true
        - get: buildpacks-ci
        - get: ci-image
        - get: version
          params: {pre: "rc"}
          resource: <%= builder_data["version-key"] %>-version
        - get: packager
        - get: v2-release-candidate
          trigger: true
          passed: [create-rc]
        - get: lifecycle # use lifecycle version in order.toml instead?
          resource: cnb-lifecycle-release
          trigger: true
      - task: get-cnb-sources
        image: ci-image
        config:
          platform: linux
          inputs:
            - name: repo
          outputs:
            - name: sources
          run:
            path: bash
            args:
              - -cl
              - |
                cp -r repo sources/<%= language %>-cnb
      - task: write-order-toml
        image: ci-image
        config:
          platform: linux
          outputs:
            - name: cnb-builder
          run:
            path: bash
            args:
              - -cl
              - |
                echo -e "\ndescription = 'test-builder for <%= language %>-cnb'\n[[order]]\ngroup = [{ id = 'org.cloudfoundry.<%= language %>' }]\n" > cnb-builder/<%= builder_data['stack'] %>-order.toml
      - task: create-builder-image
        image: ci-image
        file: buildpacks-ci/tasks/create-builder/task.yml
        privileged: true
        params:
          <% (builder_data['builder-image-params'] || []).each do |key, value| %>
          <%= key %>: <%= value%>
          <% end %>
      - task: generate-test-config
        image: ci-image
        file: buildpacks-ci/tasks/set-test-configuration/task.yml
        params:
          STACK: <%= builder_data["stack"] %>

      - task: metabuildpack-integration
        image: ci-image
        file: buildpacks-ci/tasks/metabuildpack-integration/task.yml
        privileged: true
        params:
          CNB_RUN_IMAGE: <%= builder_data['builder-image-params']['RUN_IMAGE'] %>
          CNB_BUILD_IMAGE: <%= builder_data['builder-image-params']['BUILD_IMAGE'] %>
          GIT_TOKEN: {{buildpacks-github-token}}
    <% end %>
  <% end %>
<% end %>


  - name: create-rc
    serial: true
    public: true
    plan:
      - in_parallel:
          - get: buildpacks-ci
          - get: ci-image
          - get: version
            resource: <%= language %>-cnb-version
            params:
              pre: rc
          - get: repo
            trigger: true
          - get: cnb2cf
      - task: create-v2-candidate
        image: ci-image
        file: buildpacks-ci/tasks/cnb/build-v2/task.yml
      - task: promote-candidate-to-rc
        image: ci-image
        file: buildpacks-ci/tasks/cnb/promote-v2-to-rc/task.yml
        params:
          LANGUAGE: <%= language %>
      - put: v2-release-candidate
        params:
          file: release-candidate/*.zip
      - put: version
        resource: <%= language %>-cnb-version
        params:
          file: version/version

  - name: test-rc
    serial: true
    public: true
    plan:
      - in_parallel:
          - get: buildpack-acceptance-tests
          - get: ci-image
          - put: edge-environments
            params:
              acquire: true
          - put: edge-buildpack-specs-pool
            params:
              claim: <%= language %>
          - get: buildpacks-ci
          - get: version
            resource: <%= language %>-cnb-version
            passed: [create-rc]
            params:
              pre: rc
          - get: repo
            <% if language == "dotnet-core" %>
            passed: <%= tested_stacks %>
            <% else %>
            passed: [create-rc]
            <% end %>
          - get: env-repo
          - get: v2-release-candidate
            <% if language == "dotnet-core" %>
            passed: <%= tested_stacks %>
            trigger: true
            <% else %>
            passed: [create-rc]
            trigger: true
            <% end %>
      - task: create-cf-space
        image: ci-image
        file: buildpacks-ci/tasks/create-cf-space/task.yml
        output_mapping: {cf-space: cf-space-cflinuxfs3}
        params:
          ENV_POOL_RESOURCE: edge-environments
          ENVS_DIR: env-repo
          ORG: pivotal
          SYSTEM_DOMAIN: buildpacks-gcp.ci.cf-app.com
          USERNAME: admin
      - task: v2-candidate-acceptance
        image: ci-image
        privileged: true
        file: buildpacks-ci/tasks/run-buildpack-acceptance/task.yml
        input_mapping:
          cf-space: cf-space-cflinuxfs3
          candidate: v2-release-candidate
        params:
          GIT_TOKEN: {{buildpacks-github-token}}
          BUILDPACK_ARTIFACT: release-candidate
          LANGUAGE: <%= language %>
    ensure:
      in_parallel:
        - task: delete-cf-space
          file: buildpacks-ci/tasks/delete-cf-space/task.yml
          input_mapping:
            cf-space: cf-space-cflinuxfs3
        - put: edge-environments
          params:
            release: edge-environments
        - put: edge-buildpack-specs-pool
          params:
            release: edge-buildpack-specs-pool

  - name: ship-it
    serial: true
    public: true
    plan:
      - in_parallel:
          - get: buildpacks-ci
          - get: buildpack
            resource: repo
            passed: [ test-rc ]
          - get: v2-release-candidate
            passed: [ test-rc ]
          - get: version
            resource: <%= language %>-cnb-version
            passed: [ test-rc ]
            params:
              bump: final
      - task: check-tag-not-already-added
        file: buildpacks-ci/tasks/check-tag-not-already-added/task.yml
      - put: repo
        params:
          repository: buildpack
          tag: version/version
          tag_prefix: v
          only_tag: true

  - name: buildpack-to-github
    serial: true
    public: true
    plan:
      - in_parallel:
          - get: buildpacks-ci
          - get: v2-release-candidate
            passed:
              - ship-it
          - get: version
            resource: <%= language %>-cnb-version
            params:
              bump: final
          - get: buildpack
            resource: repo
            passed:
              - ship-it
            trigger: true
      - task: collect-release-artifacts
        privileged: true
        file: buildpacks-ci/tasks/collect-release-artifacts/task.yml
        params:
          REPO: <%= language %>-cnb
          STACK: cflinuxfs3
          GITHUB_ACCESS_TOKEN: {{buildpacks-github-token}}
      - put: buildpack-github-release
        params:
          name: buildpack-artifacts/tag
          tag: buildpack-artifacts/tag
          body: buildpack-artifacts/release_notes
          globs:
            - buildpack-artifacts/*-v*.zip
            - buildpack-artifacts/*-v*.SHA256SUM.txt
      - put: version
        resource: <%= language %>-cnb-version
        params:
          bump: patch

{'fraction_non_alphanumeric': 0.12422334172963896, 'fraction_numerical': 0.0028547439126784214, 'mean_word_length': 1.741827808471455, 'pattern_counts': {'":': 0, '<': 126, '<?xml version=': 0, '>': 128, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5991869', 'n_tokens_mistral': 7733, 'n_tokens_neox': 7334, 'n_words': 1467}