GitHub to WordPress.com Automation

Advertisement

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:

GitHub to WordPress.com Automation 1
Hosting Configuration

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.

Top ↑

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.

Top ↑

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.

Top ↑

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:
name: Deploy to WordPress.com
on:
push:
branches: [ wordpress.com ]
jobs:
FTP-Deploy-Action:
name: FTP-Deploy-Action
runs-on: ubuntu-latest
steps:
– uses: actions/checkout@master
with:
fetch-depth: 2
– name: FTP-Deploy-Action
uses: Automattic/FTP-Deploy-Action@3.0.1
with:
ftp-server: sftp://sftp.wp.com/htdocs/
ftp-username: ${{ secrets.FTP_USER }}
ftp-password: ${{ secrets.FTP_PASSWORD }}
known-hosts: "\
sftp.wp.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB\
AAABAQDwfT/YEhOKO2Z0+XrjRqUS5Q2Ali6AlhOhZtzlIfMOvm03Sype\
DJH70tlUHasS+nm0SnZ01fOiEeAXa91ZhMihIYUT3nTGuiA2J3uVYsyS\
CJefvhWc0kg1FbEus3V3cVmx4e3XctdkzLbOgPNngypZocbP+8yCpbx6\
Kb9lihmgTjgGn2QzbK1enRSzsN/CbjVhej9jwukbrWqdCrQsKAsoZ2p6\
YCtcKbHS+Yy4RwcO9PxZUBkeMXUrejms027bRcdVfwf55hWSD9xYEHpE\
HupkSL4ofWs3UKeRGz+jCCzl7Nu0S6VSwK4Zzll0auHI0Hwh8WKTJbSn\
1gxCdF93/rmP\
"

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:

GitHub to WordPress.com Automation 2
GitHub to WordPress.com Automation 7

NOTE: The password from above screenshot is wrong. So, Don’t try to hack my site 😛

After adding both keys you can see:

GitHub to WordPress.com Automation 3
GitHub to WordPress.com Automation 8

Now, Lets copy the files and folders which we want for our automation.

Top ↑

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.

GitHub to WordPress.com Automation 4
GitHub to WordPress.com Automation 9

NOTE: WordPress hosting root directory contain some directories with a (?) mark. So, Avoid them.

Top ↑

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
GitHub to WordPress.com Automation 5
GitHub to WordPress.com Automation 10

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:

GitHub to WordPress.com Automation 6
GitHub to WordPress.com Automation 11

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

Leave a Reply