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
CircleCI
.circleci/config.yml
GitHub Actions
GitHub Actions
.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.Branch Protection
All projects should set themain 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.- A Block Theme generator (
yo trewknowledge) - A Hybrid Theme generator (
yo trewknowledge:hybrid) - A Classic Theme generator (
yo trewknowledge:legacy)
How to use the generators
- Make sure your copy of the TK-Quickstart repository is up to date.
- Run
yo trewknowledgein 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.