Skip to content

Instantly share code, notes, and snippets.

@gregfenton
Last active January 4, 2022 20:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregfenton/998b9b49d23abfbdb854b340b1b79447 to your computer and use it in GitHub Desktop.
Save gregfenton/998b9b49d23abfbdb854b340b1b79447 to your computer and use it in GitHub Desktop.
a shell script to clone a git repo into the current EAS build container
#!/bin/bash
set -e # exit when any command fails
function LOG() {
printf 'LOG: %s %s\n' "$(date '+%b-%d %T')" "${1}"
}
function CLONE_GITHUB_REPO() {
#
# EAS_SCRT_GITHUB_CONFIG_REPOS_TOKEN is an account-level Secret stored in our Expo account's Settings
#
# It contains the PERSONAL ACCESS TOKEN for the GitHub account so that the `git clone` command below
# has access to the GH repository without need for username & password.
#
# See https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
#
export GITHUB_CONFIG_REPOS_TOKEN="${EAS_SCRT_GITHUB_CONFIG_REPOS_TOKEN}"
if [[ -z ${GITHUB_CONFIG_REPOS_TOKEN} ]]; then
LOG "No value for EAS secret GITHUB_CONFIG_REPOS_TOKEN (${GITHUB_CONFIG_REPOS_TOKEN})"
exit 4
fi
if [[ -z ${GITHUB_URL_NO_SCHEME} ]]; then
LOG "No value for GITHUB_URL_NO_SCHEME (${GITHUB_URL_NO_SCHEME})"
exit 11
fi
if [[ ! -d ${CONFIGS_DIR} ]]; then
LOG "CONFIGS_DIR is not a directory (${CONFIGS_DIR})"
exit 12
fi
GH_URL="https://${GITHUB_CONFIG_REPOS_TOKEN}"
GH_URL="${GH_URL}:x-oauth-basic"
GH_URL="${GH_URL}@${GITHUB_URL_NO_SCHEME}"
CONFIGS_BRANCH="main"
LOG "Cloning ${GITHUB_URL_NO_SCHEME} into ${CONFIGS_DIR}/${CUSTOMER_GROUP_ID}"
git clone -b "${CONFIGS_BRANCH}" "${GH_URL}" "${CONFIGS_DIR}/${CUSTOMER_GROUP_ID}"
if [[ ! -d "${CONFIGS_DIR}/${CUSTOMER_GROUP_ID}" ]]; then
LOG "Clone destination is not a directory: (${CONFIGS_DIR}/${CUSTOMER_GROUP_ID})"
exit 14
fi
LOG "Cloned directory contents:"
ls -l "${CONFIGS_DIR}/${CUSTOMER_GROUP_ID}"
}
function COPY_PROJECT_TO_CURRENT_CONFIG() {
if [[ ! -d "${PROJECT_CONFIG_DIR}" ]]; then
LOG "Not a directory PROJECT_CONFIG_DIR (${PROJECT_CONFIG_DIR})"
exit 21
fi
SRC_BUILD_DIR="${ROOT_DIR}/src/build"
mkdir -p ${SRC_BUILD_DIR}
CURRENT_CONFIG_DIR="${SRC_BUILD_DIR}/current-config"
LOG "cp -pr ${PROJECT_CONFIG_DIR} ${CURRENT_CONFIG_DIR}"
cp -pr "${PROJECT_CONFIG_DIR}" "${CURRENT_CONFIG_DIR}"
LOG "Contents of CURRENT_CONFIG_DIR (${CURRENT_CONFIG_DIR})"
ls -l ${CURRENT_CONFIG_DIR}
}
#
# MAIN part of script
#
if [[ ${EAS_BUILD} == true ]]; then
LOG "EAS_BUILD is true"
export ROOT_DIR=$(pwd)
export CONFIGS_DIR="${ROOT_DIR}/customer-configs"
# EAS_SCRT_CUSTOMER_ID is a project-level Secret in our Expo project
export CUSTOMER_ID="${EAS_SCRT_CUSTOMER_ID}"
# EAS_SCRT_FIREBASE_PROJECT_ID is a project-level Secret in our Expo project
export FIREBASE_PROJECT_ID="${EAS_SCRT_FIREBASE_PROJECT_ID}"
if [[ -z "${CUSTOMER_ID}" || -z "${FIREBASE_PROJECT_ID}" ]]; then
LOG "No value for CUSTOMER_ID ($CUSTOMER_ID) or FIREBASE_PROJECT_ID ($FIREBASE_PROJECT_ID)"
USAGE
exit 5
fi
export PROJECT_CONFIG_DIR="${CONFIGS_DIR}/${CUSTOMER_ID}/${FIREBASE_PROJECT_ID}"
case "$CUSTOMER_ID" in
"developer-configs")
GITHUB_URL_NO_SCHEME="github.com/gregfenton/app-configs-developer"
;;
"qa")
GITHUB_URL_NO_SCHEME="github.com/gregfenton/app-configs-testing"
;;
"customer1")
GITHUB_URL_NO_SCHEME="github.com/gregfenton/app-configs-customer1"
;;
"customer2")
GITHUB_URL_NO_SCHEME="github.com/gregfenton/app-configs-customer2"
;;
*)
LOG "Unknown value for CUSTOMER_ID ($CUSTOMER_ID)"
exit 6
;;
esac
CLONE_GITHUB_REPO
COPY_PROJECT_TO_CURRENT_CONFIG
else
LOG "Not an EAS_BUILD"
fi
LOG "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment