Self Hoster

GitHub

YouTube Video Placeholder

This tutorial will guide you through the process of creating a new GitHub repository for a WordPress plugin called “Info Block,” which allows you to distribute your custom block across various websites using GitHub and Self-Hoster plugin integration.

Create GitHub Repository

  1. Give it a name
  2. Choose if repository needs to be:
    • Public – Everyone can see it
    • Private – Only you can see it after you logint
1
2

Create Gutenberg block

Open a terminal and prepare your plugin directory:

  • Drag your plugin folder into the terminal to set the working directory.
  • npx @wordpress/create-block@latest hoster-info-block

Exclude Unnecessary Files from GitHub Repo

Configure .gitignore to exclude node modules and other unnecessary files.

  • In your repository, create a .gitignore file and add entries for node_modules/, and other directories/files that should not be tracked by Git.
  • Commit the changes to .gitignore.

Tip

Ignored files will be in your local machine but not in the repository. This will keep repository much lighter in terms of size and tracked changes.

GitHub Actions for Automatic Releases

.gitignore
plugin-root-file.php
├── assets/
│   └── style.css
├── inc/
│   └── updater.php
└── .github/
    └── workflows/
        └── release.yml

Create GitHub workflows for automated releases:

  • In your GitHub repository, navigate to the ‘Actions’ tab and set up a new workflow.
  • Configure the workflow to handle build processes, such as compiling code or packaging the release.
  • Include steps to tag each release, which will trigger the workflow to build and publish your plugin.

Warning

It’s important to create .gitignore file even empty one.

But you should add at least add **/.DS_Store for Mac.

GitHub Secrets for Authentication

Create a GitHub token for automation:

  • Go to your GitHub settings, navigate to ‘Developer settings’, and then to ‘Personal access tokens’.
    https://github.com/settings/tokens
  • Generate a new token with the necessary permissions (e.g., repo, workflow) and name it appropriately.
  • Save this token as a secret in your GitHub repository under ‘Settings’ > ‘Secrets’. This token will authenticate GitHub actions to perform tasks like pushing updates.

Add token to the repository

Under repo > Settings on the left side find Secrets and variables and click on the “Actions”

screenshot 2024 07 02 at 21.00.55
1

Then click on the New repository secret

screenshot 2024 07 02 at 21.03.18

Add a name to the secret and paste password from your “Personal access token”.

I usually call Secret name and Personal token the same to be easier to track.

screenshot 2024 07 02 at 21.10.28

In release.yml replace “GITHUB_TOKEN” to “YOUR_SECRET_NAME”

screenshot 2024 07 02 at 21.11.17
screenshot 2024 07 02 at 21.11.38

Step 6: Deploy and Test Your Plugin

To trigger the release create a new tag same as version number. 0.0.1, 0.0.2 …

Once tag is submitted it will trigger Github action that will create release zip.

Public Repository

Fetch Github releases

Switch from media library to GitHub Repository by toggling on “GitHub Repository

screenshot 2024 06 26 at 18.04.18
1
screenshot 2024 06 26 at 18.04.24
screenshot 2024 06 26 at 18.07.26
1
2
screenshot 2024 06 26 at 18.08.11
1
2

Monitor automatic updates:

  • With each new tag pushed to GitHub, the workflow triggers the build and release processes.
  • Self-Hoster detects the new release and automatically fetches updates, allowing users to update their installed plugin through the WordPress dashboard.

Connect GitHub Account

Info

Connecting GitHub Account gives you two benefits

  • You can host plugins from private repository
  • You will not need to type repository. You will get dropdown list.

Not connected

screenshot 2024 07 02 at 19.00.22

Connected

screenshot 2024 07 02 at 19.00.00

With connected account you can fetch public and private repositories

To connect the account you will need to do 3 steps.

  1. Open GitHub Settings page
  2. Create GutHub App
  3. Grand permissions

Private Repository

Info

Once account is connected and that is a mandatory step you will be able to choose and host plugins updates from Public and Private repositories.