GitHub Actions

You can add CI/CD workflows to an existing repo using GitHub Actions. Add a GitHub Actions workflow to an existing repository in 5 minutes or less. The Basic Example below should be all you need to trigger Ghost Inspector tests after deploying via a GitHub pull request. Jump to the Advanced Example if you need to run tests against a local build without deploying.

Table of Contents

  • Prerequisites
  • Basic Example
  • Advanced Networking Example

Prerequisites

It is generally recommended to set up your test execution parameters as GitHub secrets, which can then be used environment variables in your actions. The examples below will be using the GitHub secrets syntax (${{ secrets.[SECRET_NAME] }}) for sensitive information like the following:

  • GI_API_KEY - available in your Ghost Inspector account.
  • GI_SUITE or GI_TEST - the ID of the Ghost Inspector suite/test you wish to run against your app.

The examples below start at the jobs portion of a GitHub Action workflow. If this is your first action, be sure to include something like the following at the top of your workflow:

# .github/workflows/main.yml

name: GI
on:
  push:
    branches: [stable]
  pull_request:
    branches: [stable]

Read more about Configuring a workflow in the official GitHub Help.

Basic Example

If your GitHub action deploys to a publicly available URL, the simplest way to integrate Ghost Inspector is with our CLI Docker image.

# .github/workflows/main.yml

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: execute Ghost Inspector test
        uses: docker://ghostinspector/cli
        with:
          args: test execute ${{ secrets.GI_TEST }} \
            --apiKey ${{ secrets.GI_API_KEY }} \
            --startUrl https://your-staging-url \
            --errorOnFail

Here is another example of using a different Action to get the Netlify Deploy Preview URL. However any URL can be used for `startUrl`, or even omitted entirely if your tests already have a fixed URL.

# .github/workflows/main.yml

jobs:
  test:
    runs-on: ubuntu-latest
    container:
      image: node:12-alpine
    steps:
      - name: Wait for the Netlify Preview
        uses: jakepartusch/wait-for-netlify-action@v1
        id: netlify
        with:
          site_name: 'your-netlify-site-name-here'
          max_timeout: 120
      - name: execute Ghost Inspector suite
        uses: docker://ghostinspector/cli
        with:
          args: suite execute ${{ secrets.GI_SUITE }} \
            --apiKey ${{ secrets.GI_API_KEY }} \
            --startUrl ${{ steps.netlify.outputs.url }} \
            --errorOnFail

Advanced Networking Example

The Ghost Inspector CLI image can also be used to test your Docker application without the need to modify your existing container(s). The following example will build and start the application under test in the background, and then utilize our ghostinspector/cli image to create a temporary VPN tunnel (using ngrok) to your Docker app and execute your suite against it:

# .github/workflows/main.yml

jobs:
  test:
    runs-on: ubuntu-latest
    container:
      image: node:12-alpine
      # this will be used by the Ghost Inspector container
      options: --network-alias node-app
    steps:
      - uses: actions/checkout@v2
      - name: install, build, and run app
        run: |
          npm install
          npm run build
          npm start &
      - name: execute Ghost Inspector suite
        uses: docker://ghostinspector/cli
        with:
          args: suite execute ${{ secrets.GI_SUITE }} \
            --apiKey ${{ secrets.GI_API_KEY }} \
            --ngrokTunnel node-app:3000 \
            --ngrokUrlVariable startUrl \
            --ngrokToken ${{ secrets.NGROK_TOKEN }} \
            --errorOnFail