#!/bin/bash

set -e

APP_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)

if [ -n "$CI" ]; then
  echo "== Installing system packages =="
  sudo apt-get update
  sudo apt-get install -y libcurl4-openssl-dev
  echo

  # Install gettext for I18n msgfmt specs
  sudo apt-get install -y gettext
  echo
fi

if [ -n "$CI" ]; then
  echo "== Setup git config =="
  git config --global user.name "ManageIQ"
  git config --global user.email "contact@manageiq.org"
  echo

  # HACK: Temporarily disable using Gemfile.lock.release until we can figure out how to make it
  #       work properly in Github Actions.
  #
  # # Gemfile.lock.release only applies to non-master branches and PRs to non-master branches
  # if [[ "$GITHUB_REPOSITORY_OWNER" = "ManageIQ" && "$GITHUB_BASE_REF" != "master" && "$GITHUB_REF_NAME" != "master" && "$GITHUB_REF_NAME" != "dependabot/"* ]]; then
  #   echo "== Setup Gemfile.lock.release =="
  #   cp -f "$APP_ROOT/Gemfile.lock.release" "$APP_ROOT/Gemfile.lock"
  #   echo
  # fi
fi
