Effortless Way to Sync Your Project with GitHub Templates

I recently purchased Makerkit, a SaaS boilerplate built with Next.js, Remix, Firebase and Supabase to build SaaS products in record time. The issue with this template when I use in a project is the author was extremely active updating the template's code base, which is good for us as their customer. In the another hand, we will need to catch-up with the latest changes, if needed.

In this article, I want to address how to update my project when there is a new commit in the template, so my project will receive the updates right away. Note that you can use this method with any GitHub templates.

One possible way is to use GitHub Actions to sync the template with our repo. I found a useful library for this purpose: https://github.com/AndreasAugustin/actions-template-sync.

This library supports both private and public templates and repositories. It also has a detailed README to follow.

GitHub Personal Access Token

The first thing we need is a GitHub personal access token, which can be created here: https://github.com/settings/personal-access-tokens/new. Make sure to create one with the specific scopes needed to read the template repository and update our project repository.

Then, in the project settings, add the newly created access token to the GitHub Actions secrets. Let's name it GH_PERSONAL_ACCESS_TOKEN, for example.

GitHub Actions

Navigate to the project Actions and create a new workflow. Copy, paste, and update the necessary variables in the action script below, and we're done!

As a note, we can schedule this script to run based on the Cron configuration. Double-check your schedule at https://crontab.guru/ before applying it to the script.

name: template-sync

on:
  # cronjob trigger
  schedule:
    - cron:  "0 0 1 * *"
  # manual trigger
  workflow_dispatch:

env:
  SOURCE_BRANCH: main
  SOURCE_REPOSITORY: makerkit/next-supabase-saas-kit-turbo

jobs:
  repo-sync:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout ${{ github.repository }}
        uses: actions/checkout@v4
        if: github.repository != env.SOURCE_REPOSITORY
        with:
          token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

      - name: actions-template-sync
        uses: AndreasAugustin/actions-template-sync@v1.1.8
        if: github.repository != env.SOURCE_REPOSITORY
        with:
          github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
          source_repo_path: ${{ env.SOURCE_REPOSITORY }}
          upstream_branch: ${{ env.SOURCE_BRANCH }}
          pr_title: "[actions-template-sync] Upstream template update"
          pr_commit_msg: "chore(template): upstream template update"

Run the Script

Let's try running it manually to see if a PR is created to sync our project with the template.