GitHub Actions can be used to automate almost any type of project, but in this article, I will cover how can we automate deployment (CI/CD) for WordPress. I personally chose WordPress as an example as is the world’s most popular CMS, with over 455 million websites that use WordPress, a number which is increasing day by day. With this in mind, this tutorial will hopefully be useful for many. To know more benefits of using WordPress I would suggest reading this article.
What are GitHub Actions?
GitHub Actions are a convenient service where we can automate our builds, tests, and deployments instead of doing them manually. Every time we complete a task locally and want to deploy it on a server, we want to minimize redundant work especially when we want to deploy only minor fixes. CI/CD (Continuous Integration and Continuous Delivery) helps us automate those processes and GitHub Actions do this for us with a couple of settings. You can also check out the GitHub Actions official documentation for more detailed information.
How do GitHub Actions work
There are many events for GitHub Actions. Some handy and frequent-use events are pull_request, push, schedule, etc. You can find them all on GitHub's official documentation.
Let's see our GitHub branches and how we would like to organize GitHub Actions on them.
GitHub Branches: . More about the cache action here https://github.com/actions/cache -
Node JS:Our theme requires building the JavaScript packages and it has node version dependency v12.x.x so we just take the node version12.xon our virtual server. You can pick your own version from here: https://github.com/actions/setup-node -
PHP:Our theme requires building the PHP packages and it has PHP version dependency v7.4 so we just take the PHP version"7.4"on our virtual server. You can pick your own version from here: https://github.com/shivammathur/setup-php -
Install Node dependency:Here we run an action to install our npm package dependencies. -
Install PHP dependency:Here we run an action to install the PHP package dependencies. -
Build The Theme:Here we run the internal package command to build our WordPress theme. We are using the "Tonic starter" theme for our WordPress Theme. -
Before Deployment:Before deployment, we have to do some tasks if required. In my case, I do not want to mess up the setting that our "infrastructure team" made and I need the right permission to move the files too. so here I do some tasks like removing the old theme and change the folder ownership to mine.
To perform these actions we need to login/SSH to the server. For example, we need a DNS/IP, username, ssh key, port, etc to connect the AWS EC2 instance. I use heressh-actionto make my job easy. https://github.com/appleboy/ssh-action
To add these things just follow below steps:
- Go to the Repository and click on the "Settings" tab 


