<commit_before>#!/bin/bash

set -e

mkdir -p $HOME/.ssh
ssh-keyscan github.com >> $HOME/.ssh/known_hosts

eval $(ssh-agent)
echo "$GITHUB_SSH_KEY" > private_key.pem
chmod 0600 private_key.pem
ssh-add private_key.pem > /dev/null
rm private_key.pem

set -x

current_version=$(cat current-terraform-ami-version/number)
next_version=$(cat next-terraform-ami-version/number)
current_ami_commit=$(cat "terraform-ami-commit/ami-commit-v$current_version")
next_ami_commit=$(git -C terraform-image-changes rev-parse -q --verify HEAD)

if [[ $current_ami_commit == $next_ami_commit ]]; then
  echo -n $current_ami_commit > ami-commit-v$current_version
  echo -n $current_version > ami-version-number
  cp "terraform-ami-metadata/ami-metadata-v$current_version" .
  exit 0
fi

git -C terraform-image-changes submodule update --init --recursive
terraform-image-changes/terraform/build -machine-readable -var "version=$next_version" | tee build.log

tail -50 build.log | lattice-ci/tasks/build-terraform-images/parse-build-output.rb > ami-metadata-v${next_version}.tf.json
echo -n $next_ami_commit > ami-commit-v$next_version
echo -n $next_version > ami-version-number

<commit_msg>Fix ami-metadata filename<commit_after>#!/bin/bash

set -e

mkdir -p $HOME/.ssh
ssh-keyscan github.com >> $HOME/.ssh/known_hosts

eval $(ssh-agent)
echo "$GITHUB_SSH_KEY" > private_key.pem
chmod 0600 private_key.pem
ssh-add private_key.pem > /dev/null
rm private_key.pem

set -x

current_version=$(cat current-terraform-ami-version/number)
next_version=$(cat next-terraform-ami-version/number)
current_ami_commit=$(cat "terraform-ami-commit/ami-commit-v$current_version")
next_ami_commit=$(git -C terraform-image-changes rev-parse -q --verify HEAD)

if [[ $current_ami_commit == $next_ami_commit ]]; then
  echo -n $current_ami_commit > ami-commit-v$current_version
  echo -n $current_version > ami-version-number
  cp "terraform-ami-metadata/ami-metadata-v${current_version}.tf.json" .
  exit 0
fi

git -C terraform-image-changes submodule update --init --recursive
terraform-image-changes/terraform/build -machine-readable -var "version=$next_version" | tee build.log

tail -50 build.log | lattice-ci/tasks/build-terraform-images/parse-build-output.rb > ami-metadata-v${next_version}.tf.json
echo -n $next_ami_commit > ami-commit-v$next_version
echo -n $next_version > ami-version-number


{'fraction_non_alphanumeric': 0.13432203389830508, 'fraction_numerical': 0.005932203389830509, 'mean_word_length': 4.844059405940594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4134402', 'n_tokens_mistral': 874, 'n_tokens_neox': 852, 'n_words': 162}