Local dev -> review -> production

I’m working on a fairly big Ghost project and have a “client review” Ghost instance that I push to using Github actions, works great. My dev-ops skills are improving :)

What is the best way to set up a workflow where

  • after I push a local update to the preview/approval Ghost instance and client says OK…
  • I can then “sync” directly from preview/approval to production on Ghost Pro.

It would be great if I can just have the approval site one-click deploy to production on ghost pro.

I can change the GitHub Action to push to production instead of preview/review, with smaller ongoing changes this does not feel like a elegant solution, thinking there has to be a better way to do ghost-to-ghost syncing of a theme and all related files. Can I use a separate GitHub action to deploy to production, triggering on… what?

Thank you for any suggestions or ideas,
/magnus

GitHub Actions has the concept of “Environments”, but I’m not sure if there’s a built-in way to deploy to the “staging” environment first, wait for human approval, and then deploy to the “production” environment.

The simplest way I’ve found is to have a manual trigger for your workflow. Here’s a partial example for an Action completely unrelated to Ghost - but in my case I manually deploy to staging:

name: Staging Deployment

on:
  # This allows you to manually trigger a release from the GitHub Actions page of your repository
  workflow_dispatch:

concurrency:
  group: staging-release
  cancel-in-progress: true

jobs:
  quality:
    uses: ./.github/workflows/ci.yml
  build:
    uses: ./.github/workflows/build.yml
  finalize:
    needs:
      - build
      - quality
    runs-on: ubuntu-latest
    environment:
      name: staging
    timeout-minutes: 5
    steps:
      # This is where you can clone the repository, if needed
      - name: Job Setup
        run: echo not implemented
      # The build job creates several artifacts that get uploaded to staging. You can centralize your build logic and
      # create a separate workflow for Staging and Production deploys.
      - name: Restore build
        uses: actions/download-artifact@v3
        with:
          name: build
          path: release/
      # This is where you can run the deploy theme action. The config (URL, API Key, etc.) can be defined for each
      # environment
      - name: Job Execute
        run: echo not implemented

Thank you! I asked Llama AI and it responded with an essay, maybe there’s still hope for mankind, or maybe not. It suggests triggering the Deploy to Production as soon as Deploy-to-review completes. No human necessary. This is what we’re looking at with AI, mark my words, we’re doomed.

needs: deploy-to-review


To set up a GitHub Actions workflow for continuous integration (CI) and deployment (CD), follow these steps:

  1. Create a new repository on GitHub or use an existing one.
  2. Install the necessary dependencies by running npm install or yarn add.
  3. Set up a CI pipeline using GitHub Actions. You can do this by creating a .github/workflows/ directory in your project root and adding a YAML file inside it. For example, create a file called ci.yml:
name: Continuous Integration
on: push
jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Run tests
        run: npm test

This will trigger the CI pipeline every time someone pushes changes to the repository. The pipeline will checkout the code, install dependencies, and then run the tests defined in the package.json file.
4. Add a CD stage to the pipeline by defining another job under the build-and-test job. This job will be responsible for deploying the application to the review environment. Here’s an example:

deploy-to-review:
  needs: build-and-test
  runs-on: ubuntu-latest
  steps:
    - name: Deploy to Review Environment
      env:
        REVIEW_ENVIRONMENT: ${{ secrets.REVIEW_ENVIRONMENT }}
      run: |
        echo "Deploying to review environment..."
        git fetch --prune --progress origin +refs/heads/*:refs/remotes/origin/*
        git reset --hard HEAD~1
        git clean -fdx
        npm ci
        npm run build
        npm run start
        echo "Review environment deployed successfully!"

In this example, we define a new job called deploy-to-review, which has two main tasks:

a. It sets up the environment variables needed for the deployment process, such as the URL of the review environment. These variables are stored in the secrets.REVIEW_ENVIRONMENT variable.

b. It deploys the application to the review environment by checking out the latest version of the code from Git, installing dependencies, building the app, and starting the server.
5. Finally, you need to configure the CD pipeline to automatically deploy the application to the production environment once the review environment has been approved. To do this, you can create a separate job called deploy-to-production that triggers when the deploy-to-review job completes successfully. Here’s an example:

deploy-to-production:
  needs: deploy-to-review
  runs-on: ubuntu-latest
  steps:
    - name: Deploy to Production Environment
      env:
        PRODUCTION_ENVIRONMENT: ${{ secrets.PRODUCTION_ENVIRONMENT }}
      run: |
        echo "Deploying to production environment..."
        git fetch --prune --progress origin +refs/heads/*:refs/remotes/origin/*
        git reset --hard HEAD~1
        git clean -fdx
        npm ci
        npm run build
        npm run start
        echo "Production environment deployed successfully!"

In this example, we define a new job called deploy-to-production, which has similar tasks to the deploy-to-review job but with some key differences:

a. It sets up the environment variables needed for the deployment process, such as the URL of the production environment. These variables are stored in the secrets.PRODUCTION_ENVIRONMENT variable.

b. It deploys the application to the production environment by checking out the latest version of the code from Git, installing dependencies, building the app, and starting the server.
6. Save the changes to your workflow file and commit them to your repository. Once you have pushed the changes to GitHub, the CI/CD pipeline will be triggered automatically whenever someone pushes changes to the repository.