Skip to content

Instantly share code, notes, and snippets.

@pwenzel
Last active October 12, 2021 13:29
  • Star 9 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pwenzel/6091976 to your computer and use it in GitHub Desktop.
Wordpress Makefile Workflow

Wordpress Makefile Workflow Example

This makefile automates the process of setting up a development environment from a shared Git repository. In this workflow, only your theme files are included with the projects.

All dependencies, including Wordpress core and supporting plugins, are installed via the Makefile. It also bundles WP-Cli and PHPUnit in your project directory.

This workflow is a work in progress and offers a lot of room for improvement.

Run the following shell commands:
DIR=$HOME/Sites/example-site.dev;
git clone git@github.com:username/example.git ${DIR};
cd ${DIR};
make;
git config user.name "Your name";
git config user.email "you@example.com";

mysql -u root -p;
CREATE DATABASE example_site;
Automated Install:

Run make db to configure wordpress, activate theme, plugins, and set options.

Final Steps:
  • Log in to Wordpress via wp-admin.
  • From Settings → Permalinks, set the structure to Month and Name. This also creates an .htaccess file for you.
  • Import content from a production environment using a Wordpress WXR file.
  • Run make test to run unit tests.
FAQ:

Why not use Composer?

I haven't found a good way to automate changes with Composer when doing automated Git deployments. Perhaps down the road.

How do I use the bundled copy of WP-Cli?

/wp-cli/bin/wp is symlinked to ./wp. You can use either command.

How do I use the bundled copy of PHPUnit?

It is included as a .PHAR file. Just run ./phpunit or make test.

.PHONY: install
install: clean wordpress phpunit wp-cli
git submodule init;
@echo "\n\nNOTICE: You may need to configure a MySQL database for your Wordpress installation. Just run:"
@echo " mysql -u root -p;"
@echo " CREATE DATABASE example_site; \n"
wordpress: latest.tar.gz
tar -zxvf latest.tar.gz;
rm -rf wordpress/wp-content;
mv wordpress/* ./;
rm -rf latest.tar.gz wordpress license.txt readme.html wp-content/plugins/akismet wp-content/plugins/hello.php;
mkdir -p wp-content/plugins;
latest.tar.gz:
curl -O http://wordpress.org/latest.tar.gz;
db:
./wp core config --dbname=example_site --dbuser=root --dbpass=root;
./wp core install --url="http://example-site.dev" --title="Example Site DEV" --admin_name=exampleadmin --admin_email=exampleadmin@example-site.com --admin_password=w00t;
./wp theme activate example-site;
./wp plugin install wp-less --activate;
./wp rewrite structure "/%year%/%monthnum%/%postname%/";
wp-cli:
@mkdir -p wp-cli;
@curl http://wp-cli.org/installer.sh > installer.sh;
@INSTALL_DIR='./wp-cli' bash installer.sh;
@rm installer.sh;
ln -s ./wp-cli/bin/wp wp
phpunit:
curl -O http://pear.phpunit.de/get/phpunit.phar;
mv phpunit.phar phpunit;
chmod +x phpunit;
test:
./phpunit
clean:
rm -rf wp-admin wp-includes readme.html license.txt .htaccess wp-activate.php wp-config-sample.php wp-login.php wp-trackback.php wp-blog-header.php wp-cron.php wp-mail.php wp-comments-post.php wp-links-opml.php wp-settings.php wp-load.php wp-signup.php xmlrpc.php index.php;
rm -rf latest.tar.gz wordpress;
rm -rf wp wp-cli phpunit;
deploy:
git checkout master && git merge development && git checkout development && git push --all
help:
@echo "Makefile usage:"
@echo " make \t\t Get Wordpress application files"
@echo " make clean \t Delete Wordpress files"
@echo " make test \t Run unit tests"
@echo " make deploy \t Merge development branch into master and push all"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment