#!/bin/sh

set -e

echo "  Step ==> 1"
echo "  Generate build info"

sleep 1

npx git-last -f ./build.json

echo "  Print build.json"

if [ "$CIRCLECI" == "true" ]; then
  cat build.json | jq --arg branch $CIRCLE_BRANCH -rM '. + {branch: $branch}' > /tmp/build.json
  cat /tmp/build.json > build.json
fi

if [ "$GITLAB_CI" == "true" ]; then
  cat build.json | jq --arg branch $CI_COMMIT_REF_NAME -rM '. + {branch: $branch}' > /tmp/build.json
  cat /tmp/build.json > build.json
fi

cat ./build.json
