Created
November 15, 2017 17:28
-
-
Save jamiechong/86bc355ffa66e2fd5975d185b5e9f39a to your computer and use it in GitHub Desktop.
WPE Bedrock Deploy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Modifed to work with bedrock. Note the hardcoded theme (search for my-theme-name), which could probably be changed to use | |
# a command line argument. | |
# Usage: | |
# ./wpe-deploy.sh wpe-remote-name bedrock-folder | |
# | |
# Place this file at the same level as your trellis and bedrock-folder | |
# | |
# Version: 2.1 | |
# Last Update: October 15, 2016 | |
# | |
# Description: Bash script to deploy a Bedrock WordPress project to WP Engine's hosting platform | |
# Repository: https://github.com/hello-jason/bedrock-deploy-to-wpengine.git | |
# README: https://github.com/hello-jason/bedrock-deploy-to-wpengine/blob/master/README.md | |
# | |
# Tested Bedrock Version: 1.7.2 | |
# Tested bash version: 4.3.42 | |
# Author: Jason Cross | |
# Author URL: http://hellojason.net/ | |
######################################## | |
# Usage | |
######################################## | |
# bash wpedeploy.sh nameOfRemote | |
######################################## | |
# Thanks | |
######################################## | |
# Thanks to [schrapel](https://github.com/schrapel/wpengine-bedrock-build) for | |
# providing some of the foundation for this script. | |
# Also thanks to [cmckni3](https://github.com/cmckni3) for guidance and troubleshooting | |
######################################## | |
# Set variables | |
######################################## | |
# WP Engine remote to deploy to | |
wpengineRemoteName=$1 | |
# Get current branch user is on | |
currentLocalGitBranch=`git rev-parse --abbrev-ref HEAD` | |
# Temporary git branch for building and deploying | |
tempDeployGitBranch="wpedeployscript/${currentLocalGitBranch}" | |
gitLocal=`pwd` | |
bedrockLocal=$2 | |
if [ -z "$bedrockLocal" ]; then | |
bedrockLocal="." | |
fi | |
######################################## | |
# Perform checks before running script | |
######################################## | |
# Halt if there are uncommitted files | |
function check_uncommited_files () { | |
if [[ -n $(git status -s) ]]; then | |
echo -e "[\033[31mERROR\e[0m] Found uncommitted files on current branch \"$currentLocalGitBranch\".\n Review and commit changes to continue." | |
git status | |
exit 1 | |
fi | |
} | |
# Check if specified remote exists | |
function check_remote_exists () { | |
echo "Checking if specified remote exists..." | |
git ls-remote "$wpengineRemoteName" &> /dev/null | |
if [ "$?" -ne 0 ]; then | |
echo -e "[\033[31mERROR\e[0m] Unknown git remote \"$wpengineRemoteName\"\n Visit \033[32mhttps://wpengine.com/git/\e[0m to set this up." | |
echo "Available remotes:" | |
git remote -v | |
exit 1 | |
fi | |
} | |
# Gets current timestamp when called | |
function timestamp () { | |
date | |
} | |
######################################## | |
# Begin deploy process | |
######################################## | |
function deploy () { | |
# Checkout new temporary branch | |
echo -e "Preparing theme on branch ${tempDeployGitBranch}..." | |
git checkout -b "$tempDeployGitBranch" &> /dev/null | |
cd "$bedrockLocal" | |
# Run composer | |
composer install | |
cd "$gitLocal" | |
# Setup directory structure | |
mkdir wp-content && mkdir wp-content/themes && mkdir wp-content/plugins && mkdir wp-content/mu-plugins | |
# Copy meaningful contents of web/app into wp-content | |
cp -rp $bedrockLocal/web/app/plugins wp-content && cp -rp $bedrockLocal/web/app/themes wp-content && cp -rp $bedrockLocal/web/app/mu-plugins wp-content && cp -rp $bedrockLocal/web/app/public/* . | |
######################################## | |
# Push to WP Engine | |
######################################## | |
# WPE-friendly gitignore | |
echo -e "# Ignore everything\n/*\n\n# Except this...\n!wp-content/\n!wp-content/**/*" > .gitignore | |
echo -e "!apple-app-site-association" >> .gitignore | |
echo -e "!ic_launcher-1x.png" >> .gitignore | |
echo -e "!ic_launcher-2x.png" >> .gitignore | |
echo -e "!ic_launcher-4x.png" >> .gitignore | |
echo -e "!manifest.json" >> .gitignore | |
git rm -r --cached . &> /dev/null | |
# Find and remove nested git repositories | |
rm -rf $(find wp-content -name ".git") | |
rm -rf $(find wp-content -name ".github") | |
echo -e "!dist" >> wp-content/themes/my-theme-name/.gitignore | |
git add --all | |
git commit -m "Automated deploy of \"$tempDeployGitBranch\" branch on $(timestamp)" | |
echo "Pushing to WP Engine..." | |
# Push to a remote branch with a different name | |
# git push remoteName localBranch:remoteBranch | |
git push "$wpengineRemoteName" "$tempDeployGitBranch":master --force | |
######################################## | |
# Back to a clean slate | |
######################################## | |
git checkout "$currentLocalGitBranch" &> /dev/null | |
rm -rf wp-content/ &> /dev/null | |
git branch -D "$tempDeployGitBranch" &> /dev/null | |
echo -e "[\033[32mDone\e[0m] Deployed \"$tempDeployGitBranch\" to \"$wpengineRemoteName\"" | |
} | |
######################################## | |
# Execute | |
######################################## | |
# Checks | |
check_uncommited_files | |
check_remote_exists | |
# Uncomment the following line for debugging | |
# set -x | |
# Deploy process | |
deploy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment