Skip to content

Instantly share code, notes, and snippets.

@jamesfacts
Last active April 8, 2021 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamesfacts/45b8726b2b4418285fa3acc37988990c to your computer and use it in GitHub Desktop.
Save jamesfacts/45b8726b2b4418285fa3acc37988990c to your computer and use it in GitHub Desktop.
FOLDER=wp-content/themes/
if [ "production" == "${CI_ENVIRONMENT_NAME}" ]; then
WPE_INSTALL=prod_install
elif [ "staging" == "${CI_ENVIRONMENT_NAME}" ]; then
WPE_INSTALL=staging_install
else
WPE_INSTALL=dev_install
fi
# Make a theme folder
mkdir $THEME_NAME
shopt -s extglob
mv !(${THEME_NAME}) ${THEME_NAME}
mv .editorconfig ${THEME_NAME}/.editorconfig
mv .eslintrc ${THEME_NAME}/.eslintrc
rm -rf .git
rm -rf ${THEME_NAME}/.git
rm .gitignore
rm ${THEME_NAME}/.gitignore
# build a WP install / dir structure EXACTLY like WPE from root
#####################################################################
mkdir -p $FOLDER
mv .gitignoredeploy .gitignore
mv $THEME_NAME $FOLDER
# Git config while still at WP root
#####################################################################
git config --global user.email "${WPE_INSTALL}@${WPE_INSTALL}.com"
git config --global user.name "${WPE_INSTALL}"
git init
git remote add origin git@git.wpengine.com:${WPE_ENVIRONMENT}/${WPE_INSTALL}.git
ssh git@git.wpengine.com info
# build theme
#####################################################################
cd wp-content/themes/${THEME_NAME}
composer install --no-ansi --no-dev --no-interaction --optimize-autoloader --no-progress
yarn
yarn build:production
cd ../../../
# push
#####################################################################
git add .
git status
git ls-tree -r master --name-only
git commit -m "Deployment Commit"
git push origin master --force
@trainoasis
Copy link

trainoasis commented Apr 2, 2021

Hey mate! Was just wondering if deploy commits are the usual approach and why make them?

I'm just working on rewriting my bash-script for Bedrock/Sage project deploys to gitlab's CI and found this gem on https://discourse.roots.io/t/circle-ci-deployment/18066/4 :) My bash script was like this: https://github.com/trainoasis/wp-bedrock-sage-bash-deploy and works, but of course I want CI/CD set-up and have to readjust it.

Also, you are SSHing to the server and building the theme there; all good here, but what about when the project is already there? How do you take care of the "uploads" folder, "languages" folder and other stuff that has to be copied over and is not part of the GIT control?

Looking forward to your answers; I might have just misunderstood what you are achieving here exactly.

@jamesfacts
Copy link
Author

Hey, happy to help, glad you found the thread in the Discourse. I'm actually deploying my themes through Github Actions these days, it's much faster than Gitlab CI (60-120 seconds vs 3-4 minutes).

If I understand correctly, you're running that script / pushing from your local machine? Nothing wrong with that approach but I think it's nicer to run CI remotely, the CI environment is a little closer to production, and you don't have to worry about what's going on with your local packages / config.

No need to deploy any of the uploads or WP core files, I'm just building a file structure that matches the WPE setup. WPE puts the repo reference at the WP app root, so I need to push from that context. Happy to help if you have other questions!

@trainoasis
Copy link

Hey, Indeed, Github is way faster yeah, Gitlab's CI is slow AF unfortunately (especially cache).

Yes, you understood correctly. Of course, CI is meant to run on the server somewhere, that's why I'm rewritting. My other non-WP projects already have CI/CD set-up like this, just wasn't sure about Bedrock/Sage so I chimed in here.

One problem I see is also getting premium composer packages (currently hosted privately) and updated as required. That's why I was doing it from a local machine.

I did rewrite it now using gitlab's CI though, and works as expected. If it helps someone, I'm posting it here: https://github.com/trainoasis/deploy-wp-bedrock-sage-gitlab-ci/

@jamesfacts
Copy link
Author

ah cool, that is a clever solution! Putting this in my back pocket just in case. TBH I just manage premium composer packages manually, it's not a situation I run into often.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment