#!/bin/sh
#
# Execute the Circle CI jobs locally
#
# @author      Steve Talbot
# @copyright   Copyright (c) Solviq Ltd 2019-2020
# @license     MIT

echo CircleCI CLI:
if ! circleci version; then
  echo
  echo The CircleCI local CLI does not appear to be installed.
  echo
  echo Please follow the installation instructions at:
  echo https://circleci.com/docs/2.0/local-cli/
  echo
  exit 1
fi
echo

# CircleCI checkout is based on git ls-files
if [ -f .circleci/local.env ]; then
    git add -f .circleci/local.env
fi

mkdir -p .tmp
circleci config process .circleci/config.yml >.tmp/circleci-config.yml

# This needs to match the job name in config.yml, and be duplicated if there is more than one job
circleci local execute --skip-checkout --job build-php74 --config .tmp/circleci-config.yml

# Ensure local.env is not committed by accident
if [ -f .circleci/local.env ]; then
    git rm --cached .circleci/local.env
fi
