If your WordPress plugin uses composer or npm, or has any other build step, getting a zip file for testing isn’t as simple as downloading the repo from Github. This makes it harder for folks who are not developers to test plugins, or to provide “beta” versions of plugins to customers to test.
Using the Plugin Machine CLI, you can attach an installable ZIP file to your plugin’s pull requests. This page documents how to use a Github action that will run every time changes are pushed to a pull request. It will build the plugin, create a zip file and then leave a comment on the pull request with a link to the built zip file of your plugin.
Setting Up The Workflow
Finding Your API Token
You will need your API token. Go here when logged in. Find and copy the token.
- Login to Plugin Machine
- Click on the kitten in the top right corner to show the menu.
- Click on “API Tokens”
- Copy the token.
Create A Secret
The workflow relies on one secret set for your repository. Call this secret “PLUGIN_MACHINE_TOKEN” and set it to the value of your plu
- See: https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository
Add Workflow To Github Repo
Plugin Machine will generated this file for you (soon).
Before you add this Github Action to your plugin’s git repo, please make these changes:
- Change “plugin-slug.zip” to your plugin’s slug
- This must be the same as in the “slug” key of your pluginMachine.json file.
This Github Action will do the following to your WordPress plugin.
- Install Plugin Machine CLI
- Run the production build steps for your plugin.
- Create a zip of all of the necessary files for release.
- Upload the zip file to Plugin Machine
- Comment on the pull request with a link to that file
name: Build and ZIP
on:
pull_request:
types: [opened, synchronize]
jobs:
make_zip:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Use Node 16
- uses: actions/setup-node@v3
with:
node-version: 16
# Build, Zip and Upload Plugin
- name: Zip Plugin
id: pluginmachine
uses: imaginary-machines/builder-action@main
with:
PLUGIN_MACHINE_TOKEN: ${{ secrets.PLUGIN_MACHINE_TOKEN }}
PLUGIN_DIR: ${{ github.workspace }}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
COMMENT_PR: true
Without Comment On PR
If you do not want to have Plugin Machine leave a comment on the pull request, set COMMENT_PR to false.
name: Build and ZIP
on:
pull_request:
types: [opened, synchronize]
jobs:
make_zip:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Use Node 16
- uses: actions/setup-node@v3
with:
node-version: 16
# Build, Zip and Upload Plugin
- name: Zip Plugin
id: pluginmachine
uses: imaginary-machines/builder-action@main
with:
PLUGIN_MACHINE_TOKEN: ${{ secrets.PLUGIN_MACHINE_TOKEN }}
PLUGIN_DIR: ${{ github.workspace }}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
COMMENT_PR: false