Skip to content

Instantly share code, notes, and snippets.

@davidneedham
Created March 29, 2018 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidneedham/3849ccf61bb2952c931c090424151084 to your computer and use it in GitHub Desktop.
Save davidneedham/3849ccf61bb2952c931c090424151084 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# d8-composer-github-ci-site-create.sh <slug> <email> <github>
ORG_NAME='@TODO'
TERMINUS_TOKEN='@TODO'
export GITHUB_TOKEN='@TODO'
export CIRCLE_TOKEN='@TODO'
GITHUB_API_URL="https://api.github.com/repos/@TODO"
if [[ -z "$1" ]]
then
echo -e "User slug is required. Use first initial, last name - e.g. ataylor.\n"
exit 1
else
SITE_NAME="${1}-${ORG_NAME}"
fi
if [[ -z "$2" ]]
then
echo -e "User email is required.\n"
exit 1
else
USER_EMAIL=${2}
fi
if [[ -z "$3" ]]
then
echo -e "GitHub username is required.\n"
exit 1
else
GH_USERNAME=${3}
fi
echo -e "Logging into Terminus.\n"
terminus auth:login --machine-token=${TERMINUS_TOKEN}
echo -e "Creating the site ${SITE_NAME} via Termius...\n"
terminus build-env:create-project \
--team="${ORG_NAME}" d8 ${SITE_NAME} \
--pantheon-site="${SITE_NAME}" \
--org="${ORG_NAME}" \
--admin-email="${USER_EMAIL}" \
--admin-password="texascamp"
echo -e "Site creation complete.\n\n"
echo -e "Getting site UUID...\n"
SITE_UUID=$(terminus site:lookup ${SITE_NAME} --field=id)
echo -e "Site UUID is ${SITE_UUID}.\n\n"
echo -e "Updating Terminus site list, this may take a while...\n"
terminus site:list 2>&1 >/dev/null
echo -e "Site list updated.\n\n"
echo -e "Adding the Pantheon user ${USER_EMAIL} to the site...\n"
terminus site:team:add ${SITE_UUID} ${USER_EMAIL} team_member
echo -e "User added.\n\n"
echo -e "Adding user to GitHub repository.\n"
GITHUB_API_URL="https://api.github.com/repos/$ORG_NAME/$SITE_NAME"
curl -X PUT -u "davidneedham:$GITHUB_TOKEN" -d "{\"permission\": \"push\"}" $GITHUB_API_URL/collaborators/$GH_USERNAME
echo -e "Creation of site for ${1} is complete...\n"
echo -e "=============================================================================================\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment