WorkdPress.com now provide the GitHub action support to all the sites which are hosted on WordPress.com with Business or eCommerce plan.
The integration of this automation process is very easy.
Lets see step by step, How I have setup GitHub automation to my site https://maheshwaghmare.com/
Create FTP Details Create FTP Details
If you have a account then you can visit to the URL: https://wordpress.com/hosting-config/<SITENAME>
E.g. I found my hosting details at URL:
https://wordpress.com/hosting-config/maheshwaghmare.com
Below is the screenshot of how it looks like:
Here, You can see the username and if you don’t remember the password then simply reset it by clicking on reset password button.
You can also read more about SFTP on WordPress.com.
Create GitHub Repository Create GitHub Repository
So, I have created a GitHub repository:
https://github.com/maheshwaghmare/git.maheshwaghmare.com/
NOTE: I have set this repository as private. But, This automation will work with both private and public repositories.
After creating a git repository create two branches.
- main – For default usage.
- wordpress.com – For WordPress automation
Now, We are ready to set the GitHub actions.
What are GitHub Actions? What are GitHub Actions?
GitHub actions are basically provide a way to perform some action after doing any git action.
E.g. we can perform GitHub actions as:
- After merge in master do xyz thing.
- After create new tag do abc something
We are creating a Github action which perform as:
After we merge the PR from main to wordpress.com then the content from our Git repository move from GitHub repository to our WordPress hosting.
Read more about GitHub actions.
Create Deploy GitHub Action Create Deploy GitHub Action
We need to set the GitHub action in our main branch. So,
- Create directories .github/workflows/
- Create file wordpress.com.yml
- Copy and paste below code within it:
In our GitHub action we need to set our FTP username and password, BUT, those are with GitHub secretes.
In GitHub we can stare the sensitive data like authentication key, password etc. in GitHub secrets.
Visit to your GitHub repository /settings/secrets/actions/new
E.g. My secrets URL is below:
https://github.com/maheshwaghmare/git.maheshwaghmare.com/settings/secrets/actions/new
Now, We need to set FTP_USER and FTP_PASSWORD something like:
NOTE: The password from above screenshot is wrong. So, Don’t try to hack my site 😛
After adding both keys you can see:
Now, Lets copy the files and folders which we want for our automation.
Copy files to GitHub Repository Copy files to GitHub Repository
Now, Lets clone the repo on local computer
$ git clone <GIT_REPO_URL> $ git fetch --all $ git checkout main && git pull $ git checkout wordpress.com && git merge main $ git push --set-upstream origin wordpress.com
Now, We need a GitHub repository to copy the folders from /wp-content/ which we want for automation.
In My case, I have set below directories:
- /wp-content/mu-plugins/
- /wp-content/plugins/
- /wp-content/themes/
NOTE: Now, We need to copy all the directories with the help of FTP client. I am using the WinSCP to copy all my files and folders but you can use any other FTP client e.g FileZilla.
Then, After copy the files commit the changes and push to the main branch.
Below is the screenshot in which you can see I have just copy above folders.
NOTE: WordPress hosting root directory contain some directories with a (?) mark. So, Avoid them.
Deploy to WordPress.com Deploy to WordPress.com
Now, We are in last step.
- Create a PR from main to wordpress.com
- Merge PR
- Wait for the GitHub action from <GitHub Repo>/actions
e.g. https://github.com/maheshwaghmare/git.maheshwaghmare.com/actions
Here,
You can see my first deploy takes 2 hours 45 minutes and 35 seconds because of there was lot of files and folders in my /wp-content/ directory.
Then, I had did the second change which was:
And, The second deploy takes ONLY 58 seconds.
Pretty awesome.
Try it yourself and let me know you experience.
You can also read the official article at Automatically Deploy to WordPress.com Using GitHub Actions