Select Page

This blog post will guide you through setting up an automated workflow to deploy your WordPress plugin to the official WordPress plugin SVN repository directly from GitHub. Using GitHub Actions, you can streamline the release process every time a new tag is pushed to your GitHub repository. Let’s create a build-and-deploy-to-svn.yml file inside your Github repository/.github/workflows directory. Now, let’s follow the following steps:

1. Naming the Workflow

name: Build and Deploy to SVN

This defines the name of the workflow. It will appear under this title in the GitHub Actions tab, making it easy to identify the deployment workflow among others.

2. Triggering the Workflow on Tag Push

on:
  push:
    tag:
    - "*"

This section specifies that the workflow will be triggered whenever a new Git tag is pushed to the repository. The - "*" part means the workflow will run on any tag, no matter the version or format. This is useful when you want to deploy a specific version of your plugin (e.g., v1.0.0) to the WordPress SVN.

3. Defining the Job

jobs:
  build:
    runs-on: ubuntu-latest

Here, we define a job called build, which runs on the latest Ubuntu environment provided by GitHub. This is the virtual machine where all subsequent steps will be executed.

4. Checkout Repository

steps:
  - name: Checkout repository
    uses: actions/checkout@v4

This step checks out your GitHub repository so that the workflow can access the code. The actions/checkout@v4 action is a standard utility to fetch the repository’s content.

5. Set up Node.js

- name: Set up Node.js
  uses: actions/setup-node@v2
  with:
    node-version: '16.17.0'

In this step, Node.js is installed on the virtual machine. The version 16.17.0 is specified here (use whatever version you need), ensuring compatibility with the plugin’s build tools. This is important if your plugin uses Node.js-based tooling like Webpack or Gulp for compiling assets.

6. Install Plugin Dependencies

- name: Install dependencies
  run: npm install

This command installs the required npm dependencies for building your plugin. The --legacy-peer-deps flag is used to bypass potential issues with peer dependencies, which can occur with newer versions of npm.

7. Install Composer

- name: Install Composer
  run: sudo apt-get update && sudo apt-get install -y composer

WordPress development often relies on PHP packages, which are managed by Composer. This step installs Composer, making it available for use in the plugin’s build process.

8. Install WP-CLI

- name: Install WP CLI
  run: |
    curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
    chmod +x wp-cli.phar
    sudo mv wp-cli.phar /usr/local/bin/wp
    wp --info

WP-CLI is a command-line interface that allows interaction with WordPress. This step downloads and installs WP-CLI. The chmod +x command makes it executable, and wp --info verifies that it has been successfully installed by displaying WP-CLI version and environment information.

9. Build the Plugin

- name: Build Plugin
  run: npm run build

In this step, the plugin’s build process is executed by running the npm-run-build script. This script is typically defined in your package.json file and may include tasks like compiling assets, bundling code, or preparing the plugin for distribution.

10. Deploy the Plugin to WordPress SVN

- name: WordPress Plugin Deploy
  id: deploy
  uses: 10up/action-wordpress-plugin-deploy@stable
  with:
    generate-zip: true
  env:
    SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
    SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
    BUILD_DIR: build

This is the core of the deployment process. The 10up/action-wordpress-plugin-deploy@stable action is a predefined GitHub Action built specifically to handle WordPress plugin deployments to the SVN repository.

  • generate-zip: true tells the action to generate a ZIP file of the plugin, which is necessary for deploying to SVN.
  • SVN_USERNAME and SVN_PASSWORD are pulled from GitHub Secrets to securely authenticate with the WordPress SVN repository.
  • BUILD_DIR is the directory where your built plugin resides. In this case, it’s set to build, which should match the output folder of your build process.

11. Create GitHub Release

- name: Create GitHub release
  uses: softprops/action-gh-release@v1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

After deploying to SVN, this step creates a new release in your GitHub repository. It uses the softprops/action-gh-release@v1 action, which automatically tags and releases the current build as a GitHub release. The GITHUB_TOKEN is securely pulled from GitHub Secrets for authorization.

Summary

This workflow provides a powerful, automated way to deploy your WordPress plugin to the official WordPress plugin repository from GitHub. Each time you push a new version (via a Git tag), this workflow:

  1. Checks out your code from the repository.
  2. Installs necessary build tools and dependencies.
  3. Builds your plugin.
  4. Deploys it to the WordPress SVN repository.
  5. Creates a new GitHub release.

By automating the deployment process, you reduce the risk of manual errors and save time when releasing new versions of your plugin.