How to Deploy a WordPress Plugin From TravisCI to WordPress.org

Not everyone likes subversion. If you use Git to manage WordPress plugin development, keeping your Git repo and the WordPress.org SVN repo in sync is tedious. Luckily, we can use TravisCI deployment provider to automate SVN deployment after tests.

Connecting TravisCI

Connect your GitHub repository with TravisCI by going to your TravisCI account page and switching on your repository. Click Sync account in the upper right corner if your newly created repository doesn't show up in the list.

You're all set. Every time you push new commits or someone makes pull requests to GitHub, it will trigger a build on TravisCI.

First Build on TravisCI

TravisCI uses a YAML file named .travis.yml in the root of your repository to customize the builds. Learn more from the build customizing document to see how you can control the build lifecycle.

This is a basic configuration file that instructs TravisCI to run builds on PHP 7.0 and 7.1. Since testing is out of the scope of this tutorial, I replaced the actual test commands with echo 'Tested'.

Adding Deployment Provider Configuration

Deployment providers run if the tests passed and pre-defined conditionals (the on section) are met. TravisCI provides nearly 40 official deployment providers. Sadly, none of them support WordPress.org subversion repositories. Thus, I made my own custom provider. You can find it on GitHub and its pull request.

Configuration Explanation

before_deploy

The before_deploy section copies three files into the build directory which is to be checked into the WordPress.org subversion repository. In the real world, this is where you want to run gulp or grunt tasks to prepare the production-ready plugin.

Don't copy test files or any unnecessary files into build as the whole build directory is released to users, and users don't need your test files.

slug

username

Your WordPress.org account username with which you submitted the plugin for review approval.

password

The password of the WordPress.org account. Never save this password in the .travis.yml in plain text!

In the above example, we use the $WORDPRESS_ORG_PASSWORD environment variable, which can be set on the TravisCI web dashboard. Choose Settings from the cog menu, and click on Add in the Environment Variables section. Never enable the "Display value in build log" option!

build_dir

Everything in this directory will be committed to the WordPress.org subversion repository, i.e. will be included in the downloadable zip file.

We set this to build because we have copied plugin files into build during before_deploy.

Tagging

Assume that we have fixed some bugs and are ready to publish a new version to WordPress.org.

These commands commit the changes to the master branch but do not trigger a deployment:

Caveats

svn commit Twice

Since TravisCI ships with an old version of subversion which doesn't play well with subdirectories, I do svn commit twice.

The first svn commit removes everything inside trunk. The second svn commit copies everything from build_dir to trunk.

Experimental

This provider is still experimental and is not merged to TravisCI's official repo yet. You can keep track of TravisCI's feedback on its pull request.

Using edge doesn't merge my branch into the upstream master. There is a chance that my branch is behind the official repo. When it happens, you can fork my branch and rebase it, and then change source in .travis.yml to your GitHub repository.

Wrapping Up

I hope all the above helps you deploy plugins to WordPress.org faster.

WordPress has an incredibly active economy. There are themes, plugins, libraries, and many other products that help you build out your site and project. The open-source nature of the platform also makes it a great option for you to improve your programming skills. Whatever the case, you can see everything we have available in the Envato Marketplace.