Skip to main content
Most of our code is available on GitHub. You can find our repositories at the Trew Knowledge GitHub Org or at the WP VIP GitHub Org. In some rare occasions, we might have repositories in other places like GitLab or Bitbucket. When starting a new project there are some things we need to do before we begin working on the code. This includes creating a new repository, adjusting settings and setting up CI/CD.

Initial Commit

For WP VIP projects it is all done for us using the VIP Go Skeleton repository as a template. For non-WP VIP projects, we need to it ourselves. Visit TK’s fork of WP VIP Skeleton, click on the “Use this template” button and follow the instructions.

Build, test & deploy

We need to set up the build, test and deploy process. This is usually done using GitHub Actions, but it can also be done using other CI/CD tools like CircleCI. This process differs between WPVIP and non-WPVIP projects.

WordPress VIP Projects

For WPVIP projects we use their CircleCI account. We need to request VIP to add the project to CircleCI. The way it works is that CircleCI will do everything we want it to do and in the end it will deploy the final code to another branch suffixed by -built (i.e. main-built). We then need to update the deployment branch through the WordPress VIP dasboard for that specific environment. See more details here. You can control what goes into the -built branch by adding and modifying a .deployignore file. This file should be added to the root of the project and should contain a list of files and folders that should not be included in the final build. It works the same way as a .gitignore file. Example Scenario: You want your source code to be in the main branch and the build folder to be ignored. However, you want the build folder to be included in the -built branch and the source folder to be ignored.

Non-WP VIP Projects

For Non-WPVIP projects we use GitHub Actions. This gives us much more flexibility. We need to create at least one new workflow file in the .github/workflows/ folder. Preferrably we should have at least 2. One workflow tracks changes to plugins and deploys only those. The other tracks changes to the theme and only builds and deploys the files it needs to. If you have multiple themes you should consider one workflow for each theme. Deployment is usually done via SSH. We need to add the SSH key and some other secrets to the repository and then use it in the workflow file.

Sample Configuration Files

.circleci/config.yml
.github/workflows/main.yml

Sample repository secrets

In order for GitHub Actions to work, you may need to add some secrets to the repository. These secrets are used to authenticate with the server and to deploy the code.
The following are only examples. Make sure you adjust to your situation.

Branch Protection

All projects should set the main branch as a protected branch. This means that no one can push directly to the main branch and all changes must be made through a pull request. This is to ensure that all changes are reviewed and tested before they are merged into the main branch. Here are the common rules we follow:
  • Require a pull request before merging
  • Require approvals (at least 1).
  • Dismiss stale pull request approvals when new commits are pushed.
  • Require status checks to pass before merging.
  • Require branches to be up to date before merging.

Pull Request templates

All projects should have a pull request template. This is a file that is automatically added to the pull request when it is created. It should contain a checklist of things that need to be done before the pull request can be merged.
.github/pull_request_template.md

Generate a new Theme

At Trew Knowledge we have some scaffolding tools to help us get started. We have 3 theme generators.
  1. A Block Theme generator ( yo trewknowledge )
  2. A Hybrid Theme generator ( yo trewknowledge:hybrid )
  3. A Classic Theme generator ( yo trewknowledge:legacy )
For the most part, we don’t use the Classic Theme generator anymore. If you are not interested in working on a Full Site Editing theme, use the hybrid option. The classic generator will be deprecated soon.

How to use the generators

  1. Make sure your copy of the TK-Quickstart repository is up to date.
  2. Run yo trewknowledge in the terminal. It will then prompt you to answer a couple of questions about the theme. After that, it will generate a block theme for you.