Last active
May 18, 2021 01:08
-
-
Save mariovalney/f5c48b2d3ca655ca6a4fb298622f08e1 to your computer and use it in GitHub Desktop.
Runs a build and publish to WP Engine Git Push
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
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 "[email protected]" | |
- 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 "[email protected]" | |
- git config --global user.name "Your Name" | |
- ./ci/wpengine-deploy.sh production |
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
#!/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" | |
[email protected]: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" | |
[email protected]: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" |
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
Please, check the comments on file.
Remember to create a directory "ci" on root and on
package.json
:Remember to give the permission:
sudo chmod +x ci/wpengine-deploy.sh