#!/bin/bash

set -euo pipefail

git_sha='186dcfc30332c038974128189e62e052039e2214'
repo_url='https://github.com/bazelbuild/buildifier'
buildifier_bin_path='bazel-bin/buildifier/linux_amd64_stripped/buildifier'
buildozer_bin_path='bazel-bin/buildozer/linux_amd64_stripped/buildozer'
temp_dir="$(mktemp --directory)"

git clone "$repo_url" "$temp_dir"
cd "$temp_dir"
git checkout "$git_sha"
bazel build //buildifier //buildozer

cat <<MESSAGE
Buildifier is available here: $temp_dir/$buildifier_bin_path
Buildozer is available here: $temp_dir/$buildozer_bin_path

Run the following command to upload them to Z3/S3:

./scripts/build/upload-to-third-party.sh $temp_dir/$buildifier_bin_path
./scripts/build/upload-to-third-party.sh $temp_dir/$buildozer_bin_path
MESSAGE
