Using GitHub Actions to deploy custom plugin

Becoming one of the core maintainers for our inhouse framework plugin means that I need to create the fastest process to release a new version of the plugin. It’s a new challenge for me to research this week ๐Ÿ’ช

The current status of our framework plugin:

  • Plugin code are zipped on our custom server (I don’t use wordpress.org because I want to build it for internal use at first) with SFTP access.
  • A private repository on GitHub to maintain the code.

I want to proceed the plugin release from GitHub like how I setup to release a plugin on wordpress.org using GitHub Action. By that way, I can manage the code only with GitHub. Let’s find how I do the release process!

To prevent affecting on the repository log of my custom plugin, I’ve created a private repository just for testing GitHub Action. I want to make sure that it works before applying this solution.

Zip source code

At first, I’m thinking to add a custom GitHub action to upload release file directly to the remote server, but after research, I found that GitHub Action can’t access the release path with the workflow after it released. Beside that, I will need the file with the correct file name something like “my_plugin.zip” to upload on remote server, so the uploading GitHub release source code won’t work in this case.

๐Ÿค” I’m thinking about make a zip file after release a version and then upload this file to my remote server, so I’m testing with the zip file first. I’ve tried with a GitHub Actions called Zip Release, below is my example workflow file:

Bug from GitHub Action Zip Release which prevent putting array in include / exclude

It run smoothly but at the final stage when I want to use the exclude or include parameters, it always returns a bug “A sequence was not expected” which prevent me to using these parameters. I think it’s a bug from the developer ๐Ÿ˜ญ.

After reading the code from Zip Release action, I found that by using GitHub action and define the environment is ubuntu-latest, I can run ubuntu command with this setting. Great! I decided to try a quick test:

Zip and upload source code to remote host

It works ๐Ÿ›ฐ๏ธ.

Folder structure

The other problem is the folder structure in zip file is not correct at this time. When releasing a WordPress plugin, I will need a parent directory named with “my-plugin” inside a zip file. Something like this:

The current directory in zip file

FooScripts
barconfig
Baz
โ”œโ”€โ”€โ”€BadBaz
โ””โ”€โ”€โ”€Drop
What I need to release a WordPress plugin
my-plugin
โ”œโ”€โ”€โ”€FooScripts
โ”œโ”€โ”€โ”€barconfig
โ”œโ”€โ”€โ”€Baz
โ”‚   โ”œโ”€โ”€โ”€BadBaz
โ”‚   โ””โ”€โ”€โ”€Drop

I came with an idea to create a folder for “my-plugin” and copy all the things I need to this folder, then zip and release this folder.

Researching about GitHub virtual environment for GitHub Actions, I found that it some cool command called rsync which I can use to copy all the files to my created “my-plugin” folder. Here is the code which works in my case:

Finish the code

All the thing I need is updating the correct setting for my custom plugin (like the remote folder path, the zip file name…), cleanup the code.

The most important thing is the trigger action I need to update, because all the code above is just a test workflow, so I made it trigger on a push Git. When releasing a plugin, I don’t want it to release each time my team push a new code, so I update the trigger action into Git release instead.

That’s it ๐Ÿ›Ž๏ธ