D7: Export and Import Rules with Hook Update Deploy Tools

In Drupal 7, Features is one option for deploying Rules and changes to them.  Now there is another alternative.  As of version 7.x-1.10 of Hook Update Deploy Tools, the module adds the ability to use Drush to export an existing rule from a development server, commit it to version control, then deploy it to a production server using hook_update_N().

Of course being a method from HookUpdateDeployTools, it brings with it the standards of the module:

  1. Do what's asked.
  2. Validate that it was done, fail the update hook if it was not done.
  3. Log everything and give meaningful feedback.

The basics look like this:

A) Export the Rule using drush.

drush site-deploy-export-rule MACHINE_NAME_OF_RULE

B) Commit the export file to your repository

C) Import the rule in hook_update_N() in your site_deploy module's .install file

 * Import rules user management.
function site_deploy_update_7012() {
$rules = array('rules-notify-users', 'rules-ban-spammers');
$message = HookUpdateDeployTools\Rules::import($rules);

drush updb or update.php will handle the rest.