Skip to content

Instantly share code, notes, and snippets.

@mariovalney
Last active May 18, 2021 01:08
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 mariovalney/f5c48b2d3ca655ca6a4fb298622f08e1 to your computer and use it in GitHub Desktop.
Save mariovalney/f5c48b2d3ca655ca6a4fb298622f08e1 to your computer and use it in GitHub Desktop.
Runs a build and publish to WP Engine Git Push
image: node:lts
pipelines:
default:
- step:
caches:
- node
deployment: staging
name: Deploy to Staging
script:
- npm ci
- npm install --global gulp-cli
- node --version
- npm --version
- gulp --version
- git config --global user.email "youremail@example.com"
- git config --global user.name "Your Name"
- ./ci/wpengine-deploy.sh
- step:
caches:
- node
deployment: production
name: Deploy to Production
trigger: manual
script:
- npm ci
- npm install --global gulp-cli
- node --version
- npm --version
- gulp --version
- git config --global user.email "youremail@example.com"
- git config --global user.name "Your Name"
- ./ci/wpengine-deploy.sh production
#!/usr/bin/env sh
BUILD_DIR=build
# You can change "package.json" to any filename from your too
# or just scape this check if you are sure it will always run on root.
if ! [ -f ./package.json ]; then
echo "You should run wpengine-deploy.sh on root directory"
exit
fi
# Variables
# By default you will put staging site GIT here
WARNING="WILL DEPLOY TO STAGING"
REPO=git@git.wpengine.com:production/examplestaging.git
# Check for production parameter to change repository
# And here the production site GIT
if [ "$1" = "production" ]; then
WARNING="WILL DEPLOY TO PRODUCTION"
REPO=git@git.wpengine.com:production/example.git
fi
echo "\n***************************"
echo "* ATTENTION! *"
echo "***************************"
echo "\n$WARNING"
# I create a directory "ci" to put this script and it creates a
# directory "build" to do its job. You can change it to fit your needs
rm -rf ci/$BUILD_DIR
echo "\n 1 - Preparing release...\n"
# Prepare your release here:
# You can do anything you do on your environment.
#
# In my case, I have a gulp default task to create a build
gulp
echo "\n 2 - Creating repository...\n"
cd ci
git clone $REPO $BUILD_DIR
cd $BUILD_DIR
echo "\n 3 - Building...\n"
echo "Removing old files"
# I remove this files because I only keep in git my theme and my
# "core plugin". You should remove everyting you need to make sure
# only the modified and the new files will be added on new commit.
rm -rf wp-content
# Creating my structure: change as you need.
mkdir --parents wp-content/themes
mkdir --parents wp-content/plugins
echo "Copying new files"
# As I said before, I'm coping back my files.
cp -r ../../www/wp-content/themes/example wp-content/themes
cp -r ../../www/wp-content/plugins/example-core wp-content/plugins
echo "Removing source"
# Here I remove the directories I do not want to send to WPENGINE.
# You can change this using a (different) gitignore.
rm -r wp-content/themes/example/source
echo "\n 4 - Pushing...\n"
echo "Will push to $REPO\n"
# Now you add everyting.
# The unchanged files will not be a problem because we added it back.
#
# The commit message will container the current date and time
git add --all > /dev/null
git commit -m "DEPLOYMENT $(date +'%Y%m%d-%H%M')" > /dev/null
git push $REPO master
echo "\n 5 - Cleaning build\n"
# Returning to root
# Remember to change it if you are not using my structure
cd ../../..
rm -rf ci/$BUILD_DIR
echo "\nFinished"
@mariovalney
Copy link
Author

mariovalney commented Feb 11, 2020

Please, check the comments on file.

Remember to create a directory "ci" on root and on package.json:

"scripts": {
  "deploy": "./ci/wpengine-deploy.sh",
  "deploy:production": "./ci/wpengine-deploy.sh production"
},

Remember to give the permission:

sudo chmod +x ci/wpengine-deploy.sh

@mariovalney
Copy link
Author

Now you can deploy to staging and production environments.

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