Introducing GitHub Actions for WordPress (Plugins)
Do you develop your WordPress plugins on GitHub? Then here’s a treat for you! We’re excited to release a GitHub Action that deploys to the WordPress.org Plugin Repository whenever you tag a new version on GitHub. You’ll be able to manage your entire development lifecycle in GitHub—no more futzing with local Bash scripts or controlling commit/push access in multiple places.
Keep reading for more details about GitHub Actions and how to get set up, but the gist is this: you reference our action in your plugin repo’s workflow file, filtered to only run when a tag is pushed, and set your username/password secrets. After that, each time you tag a new version on GitHub, whether by pushing a Git tag from the command line or making one using the GitHub releases interface, your plugin will be deployed to WordPress.org.
What’s a GitHub Action?
GitHub Actions, announced at GitHub Universe 2018, is a way to automate development workflows using container-based actions. And since they’re on GitHub, they’re shareable and customizable across the open source ecosystem. Workflows can be triggered by GitHub platform events (e.g. push, issue opened, release published), can run a sequence of actions in response, can be written in any language, and can interact with the full GitHub API and any other public API.
If you’re interested in learning more and building your own GitHub Actions, then check out GitHub’s documentation, their pre-built actions, and sign up for the limited public beta of GitHub Actions. For an even more in-depth walkthrough of creating your own GitHub Action, there’s an excellent writeup on CSS-Tricks and an insider’s perspective from Jessie Frazelle.
Let’s do this!
To get started, head to the Actions tab in your Actions-enabled GitHub repo and create a new workflow. You can use the visual editor, or copy and paste the example from our Action’s readme. You will then want to set the
SVN_USERNAME secrets, either in the Action visual editor or in the repository settings. Don’t worry though, these secrets cannot be viewed as plaintext again once you’ve saved them, so you can use your WordPress.org SVN credentials without exposing them to other contributors.
Once that’s all set, every time you push a new tag to GitHub or create one using GitHub’s releases feature, a new version will be deployed to your WordPress.org repository. By default, it will attempt to deploy to a repository with the same slug as your GitHub repo, but this can be customized using the
SLUG environment variable. The deployment does the following:
- Copies WordPress.org-specific assets to the top-level
assetsdirectory in SVN (by default it looks for a
.wordpress-orgsubfolder but this can be customized using the
- Commits all other new, modified, and deleted files to
- Copies the contents of
VERSIONis the name of your tag in Git
This Action is ready to use today for those already in the GitHub Actions beta. Note that public repositories are currently only able to trigger Actions on push. Instructions and examples including information about customizations can be found in the readme file. We are also working on more Actions to release soon. Happy plugin deploying!
Want to build amazing websites and tools like this that help web engineers? Do you love being a part of the open-source community? Join our team and help us make the web a better place.
Hendrik Luehrsen on
Really great! Good starting point to figure out how actions work. How do you handle keeping the svn pass secret? That seems a bit of a leap of faith to me.
Jeff Paul on
Hendrik – your SVN username, SVN password, and GitHub token are all set when editing your workflow or in the repository settings and otherwise cannot be viewed once stored. For more information, check out the GitHub secrets documentation at https://developer.github.com/actions/creating-workflows/storing-secrets/.
Allyson Alves de Souza on
I’m glad that you shared this, it’s amazing, I will love to not deal with TortoiseSVN anymore :P
Just one question, how can we tell the action to ignore some file or folders? (Like package.json, for example)
I would suggest using a gitattributes file. Take a look at one in my projects: https://github.com/thefrosty/wp-utilities/blob/master/.gitattributes
You can set what you want to ignore on release/tag creation.
Allyson Alves de Souza on
Thanks TheFrosty! I used .gitattributes one time, but never understood completely your usage and application, now it make’s more sense to me!
Wow! No more scripts to publish to WP plugin repo then.
Abdullah Ramzan on
Much appreciated :) We are planning to push our plugins on GitHub now.
Its very time saving & escape us from managing the plugins manually.
Thank you 10up team :)
Does this need to be a private repo on Git? If not, can someone view the keys inside of the .sh file?
Or do you run the .sh file locally?
Jeff Paul on
Steve – the secrets are stored as part of your repository settings, see more here: https://github.com/10up/action-wordpress-plugin-deploy#required-secrets.
Fantastic tool you have created, just tested it for the first time today. How can I exclude my github README.md from the wordpress repo?
I added the file to .distignore but it still gets added to the WordPress repo. Not a big issue but I would like to exclude it if possible.
Jeff Paul on
Assuming you have a line for “README.md” in your .distignore file, the WordPress.org Plugin Deploy action should skip distributing that file to WordPress.org. Details on a sample .distignore file are here: https://github.com/10up/action-wordpress-plugin-deploy#distignore. If you’re still unable to get things to work, please open an issue in our GitHub repository and we’ll gladly help triage there (as it’ll better expose the solution to others searching there for help): https://github.com/10up/action-wordpress-plugin-deploy/issues.
Thanks and happy holidays!