Set up continuous integration with a GitHub repository using GitHub Actions

Last updated:

As a part of your development workflow, you might prefer to keep your production codebase source of truth in version control. This would be especially helpful if you work as a part of a development team so that you can track changes and quickly roll them back if needed.

Using GitHub Actions, you can set up a continuous integration with a GitHub repository. This guide walks through the integration process, and assumes that you're familiar with:

Below, learn how to set up the integration using the HubSpot CMS Deploy GitHub Action (recommended) or manually.

Send local files to GitHub

Before you can integrate with GitHub, you'll first need to gather your files locally.

  • If you have an existing CMS asset that lives in HubSpot, such as a theme or set of templates, you can fetch it by running the fetch command as follows: hs fetch <HubSpot_src> <local_dest>. Alternatively, you can download all files in the account's developer file system by running hs fetch /.
  • To create a new local project, it's recommended to start with the CMS theme boilerplate. If you haven't worked with the CMS theme boilerplate before, check out the quickstart guide. If you've already installed the HubSpot CLI and configured your local environment, you can create a new local theme from the boilerplate by running hs create website-theme <new-theme-name>. You'll then need to upload your files to HubSpot with the hs upload command.

With your code available locally, you'll then add it to a GitHub repository. After adding your files to GitHub, proceed to the next step to either install HubSpot's pre-made GitHub Action (recommended) or configure the Action manually.

To streamline the process, HubSpot created a GitHub Action that you can install to your GitHub project to handle automatically deploying changes from a branch to your production HubSpot account.

Install GitHub Action

Create and merge a pull request in main

  • With your secrets, workflows, and scripts in your GitHub repository, create a pull request and merge it into main. 
  • After merging the pull request, navigate to Actions. You should see your deploy Action run, which will then deploy your code to your HubSpot account.

Lock your asset in the design manager

Now that your source of truth lives in GitHub, you should lock your asset in HubSpot to prevent edits from being made there. This ensures that changes only come through the deploy action.

To lock assets in the design manager:

  • In your HubSpot account, navigate to MarketingFiles and TemplatesDesign Tools.
  • Locate your asset's folder in the left sidebar, then right-click and select Lock folder.
design-manager-lock-folder

Was this article helpful?
This form is used for documentation feedback only. Learn how to get help with HubSpot.