<commit_before>#!/usr/bin/env bash

set -euo pipefail

generate_diff() {
  >&2 echo "Generating diff"

  version="$(cat version/number)"

  tar xf pack/*-linux.tgz -C pack

  gcloud --no-user-output-enabled auth activate-service-account --key-file <(echo "$GCP_SERVICE_ACCOUNT_KEY")
  gcloud --no-user-output-enabled --quiet auth configure-docker

  released_cnb_details="$(./pack/pack --no-color inspect-builder "cloudfoundry/cnb:$TAG" | grep -v 'Cannot connect to the Docker daemon')"
  rc_cnb_details="$(./pack/pack --no-color inspect-builder "gcr.io/cf-buildpacks/builder-rcs:${version}-${TAG}" | grep -v 'Cannot connect to the Docker daemon')"

  set +e
  diff="$(diff -u <(echo "$released_cnb_details") <(echo "$rc_cnb_details") | tail -n +3)"
  set -e

  >&2 echo -e "Diff:\n$diff"
  echo "$diff"
}

create_or_get_story() {
  filter="label:$TAG AND label:builder-release AND -state:accepted"
  response="$(curl -s -X GET \
    -H "X-TrackerToken: $TRACKER_API_TOKEN" \
    -H "Accept: application/json" \
    -G --data-urlencode "filter=$filter" \
    "https://www.pivotaltracker.com/services/v5/projects/$TRACKER_PROJECT_ID/stories"
  )"

  if [[ "$response" == '[]' ]]; then
    >&2 echo "Story does not exist"

    response="$(curl -s -X POST \<commit_msg>Sort cnbs from `pack inspect-builder` to ignore random order changes<commit_after>#!/usr/bin/env bash

set -euo pipefail

generate_diff() {
  >&2 echo "Generating diff"

  version="$(cat version/number)"

  tar xf pack/*-linux.tgz -C pack

  gcloud --no-user-output-enabled auth activate-service-account --key-file <(echo "$GCP_SERVICE_ACCOUNT_KEY")
  gcloud --no-user-output-enabled --quiet auth configure-docker

  set +e
  diff="$(diff -u <(get_cnb_names "cloudfoundry/cnb:$TAG") <(get_cnb_names "gcr.io/cf-buildpacks/builder-rcs:${version}-${TAG}") | tail -n +3)"
  set -e

  >&2 echo -e "Diff:\n$diff"
  echo "$diff"
}

get_cnb_names() {
  ./pack/pack --no-color \
    inspect-builder "$1" \
    | sed -n '/^Buildpacks:$/,/^$/p' \
    | sed '1,2d;$d' \
    | sort
}

create_or_get_story() {
  filter="label:$TAG AND label:builder-release AND -state:accepted"
  response="$(curl -s -X GET \
    -H "X-TrackerToken: $TRACKER_API_TOKEN" \
    -H "Accept: application/json" \
    -G --data-urlencode "filter=$filter" \
    "https://www.pivotaltracker.com/services/v5/projects/$TRACKER_PROJECT_ID/stories"
  )"

  if [[ "$response" == '[]' ]]; then
    >&2 echo "Story does not exist"

    response="$(curl -s -X POST \
{'fraction_non_alphanumeric': 0.18028169014084508, 'fraction_numerical': 0.005231388329979879, 'mean_word_length': 3.447227191413238, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '5144942', 'n_tokens_mistral': 971, 'n_tokens_neox': 914, 'n_words': 208}