Deploying Your Ghost Theme Using GitHub Actions: A Step-by-Step Guide

As a Ghost theme developer, deploying your theme efficiently and effectively ensures a seamless experience for your users. GitHub Actions, a powerful automation tool, can simplify the deployment process by automating tasks such as building, testing, and deploying your theme. This guide will walk you through the steps to deploy your Ghost theme using GitHub Actions.

Prerequisites

Before we begin, make sure you have the following in place:

  • A Ghost theme repository hosted on GitHub.
  • A basic understanding of Git and GitHub.
  • A Ghost CMS instance where you can deploy your theme.

Set Up GitHub Actions

  • Navigate to your theme repository on GitHub and click on the “Actions” tab.
  • Click the “Set up a workflow yourself” button.
  • This will open the workflow file main.yml in the GitHub Actions editor. You can rename the file to deploy-theme.yml.

Configure the Workflow

Add the following code in the deploy-theme.yml file:

# Learn more → https://github.com/TryGhost/action-deploy-theme#getting-started
name: Deploy Theme
on:
  push:
    branches:
      - master
      - main
jobs:
  deploy:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v3
      - name: Deploy Ghost Theme
        uses: TryGhost/action-deploy-theme@v1
        with:
          api-url: ${{ secrets.GHOST_ADMIN_API_URL }}
          api-key: ${{ secrets.GHOST_ADMIN_API_KEY }}

To Customize the workflow, you can replace the main with the branch name you want to trigger the deployment from (e.g., master).

Set Up Ghost API Credentials

  • In your Ghost CMS instance, navigate to the “Integrations” section in the admin panel.
  • Create a new custom integration and generate an API key with the necessary permissions for theme deployment.
  • Copy the generated API URL and key.

Add Secrets to Your Repository

  • Go to your GitHub repository and click on the “Settings” tab.
  • In the left sidebar, click on “Secrets”.
  • Click on “New repository secret” and add the following secrets:
GHOST_ADMIN_API_URL: Paste the copied API URL.
GHOST_ADMIN_API_KEY: Paste the generated API key.

Deployment

Once the changes are pushed, GitHub Actions will automatically trigger the deployment workflow. You can monitor the deployment process by navigating to the “Actions” tab in your repository. Once the workflow completes successfully, your Ghost theme will be deployed to your Ghost CMS instance.

By leveraging the power of GitHub Actions, you can streamline the deployment process for your Ghost theme. Automating the build and deployment tasks saves time and ensures consistency and reliability.