Integration: Codeship

Integrate Ghost Inspector with Codeship

Search our documentation:

Toggle Documentation Menu

Integration: Codeship

Ghost Inspector tests can be run inside your Codeship builds. Codeship offers two products: one called "Codeship Basic" (pre-configured, works out of the box, little customization) and one called "Codeship Pro" (Docker-based, fully customizable CI environment, dedicated single-tenant environment). Codeship offers their own version of Ghost Inspector documentation.

We cover both Codeship products below and provide two examples. The first is a simple setup that triggers a suite of tests on their default URLs during the testing stage. The second is a more advanced setup that will launch your application, create a private tunnel to it's interface, then trigger a suite of Ghost Inspector tests using that tunnel URL.

Codeship Pro

For both our simple and advanced examples, we'll setup encrypted environmental variables for our API key ($GHOST_API_KEY) and suite ID ($GHOST_SUITE_ID). These are encrypted and included in the codeship-services.yml file.

Next, we'll need to add the following commands to a script, placed in the repository, that will be called from the codeship-steps.yml file:

- name: Ghost Inspector
  service: app
  command: ghost-inspector.sh

Example #1 (Simple)

For our simple Codeship configuration example, we'll be triggering a Ghost Inspector test suite (with default settings). We'll add these commands inside the ghost-inspector.sh script:

# Execute Ghost Inspector suite via API and store results in JSON file
curl "https://api.ghostinspector.com/v1/suites/$GHOST_SUITE_ID/execute/?apiKey=$GHOST_API_KEY" > ghostinspector.json

# Check JSON results for failing tests
if [ $(grep -c '"passing":false' ghostinspector.json) -ne 0 ]; then exit 1; else echo "Tests Passed"; fi

Example #2 (Advanced)

For our more advanced Codeship configuration example, we'll be starting our application, creating an ngrok tunnel, then triggering a Ghost Inspector test suite (using that tunnel) in the "Test" section of our build pipeline. This example follows a similar route to our CircleCI blog post which walks through this process in slightly more detail.

In addition to the variables for our API key and suite ID, we'll also need to setup an ngrok.io account and add a $NGROK_TOKEN variable with our ngrok.io token.

We'll add these commands inside the ghost-inspector.sh script to start the application, create the ngrok tunnel, and trigger the Ghost Inspector suite:

# Start our application (Command needs to be customized)
node server.js &

# Download ngrok and unzip
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
chmod +x ngrok

# Download JSON parser for determining ngrok tunnel
wget https://stedolan.github.io/jq/download/linux64/jq
chmod +x jq

# Intialize ngrok and open tunnel to our application (Port 3000 needs to be customized)
./ngrok authtoken $NGROK_TOKEN
./ngrok http 3000 > /dev/null &

# Execute Ghost Inspector suite via API using the ngrok tunnel and store results in JSON file
curl "https://api.ghostinspector.com/v1/suites/$GHOST_SUITE_ID/execute/?apiKey=$GHOST_API_KEY&startUrl=$(curl 'http://localhost:4040/api/tunnels' | ./jq -r '.tunnels[1].public_url')" > ghostinspector.json

# Check JSON results for failing tests
if [ $(grep -c '"passing":false' ghostinspector.json) -ne 0 ]; then exit 1; else echo "Tests Passed"; fi

 

Codeship Basic

For both our simple and advanced examples, we'll setup environmental variables for our API key ($GHOST_API_KEY) and suite ID ($GHOST_SUITE_ID):

Codeship Environmental Variables

Now that our variables are setup, we need to add a code snippet to trigger the Ghost Inspector suite in our pipeline:

Example #1 (Simple)

For our simple Codeship configuration example, we'll be triggering a Ghost Inspector test suite (with default settings) in the "Test" section of our build pipeline:

# Execute Ghost Inspector suite via API and store results in JSON file
curl "https://api.ghostinspector.com/v1/suites/$GHOST_SUITE_ID/execute/?apiKey=$GHOST_API_KEY" > ghostinspector.json

# Check JSON results for failing tests
if [ $(grep -c '"passing":false' ghostinspector.json) -ne 0 ]; then exit 1; else echo "Tests Passed"; fi

Example #2 (Advanced)

For our more advanced Codeship configuration example, we'll be starting our application, creating an ngrok tunnel, then triggering a Ghost Inspector test suite (using that tunnel) in the "Test" section of our build pipeline. This example follows a similar route to our CircleCI blog post which walks through this process in slightly more detail.

In addition to the variables for our API key and suite ID, we'll also need to setup an ngrok.io account and add a $NGROK_TOKEN variable with our ngrok.io token.

Now we'll add a code snippet to start the application, create the ngrok tunnel, and trigger the Ghost Inspector suite:

# Start our application (Command needs to be customized)
node server.js &

# Download ngrok and unzip
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
chmod +x ngrok

# Download JSON parser for determining ngrok tunnel
wget https://stedolan.github.io/jq/download/linux64/jq
chmod +x jq

# Intialize ngrok and open tunnel to our application (Port 3000 needs to be customized)
./ngrok authtoken $NGROK_TOKEN
./ngrok http 3000 > /dev/null &

# Execute Ghost Inspector suite via API using the ngrok tunnel and store results in JSON file
curl "https://api.ghostinspector.com/v1/suites/$GHOST_SUITE_ID/execute/?apiKey=$GHOST_API_KEY&startUrl=$(curl 'http://localhost:4040/api/tunnels' | ./jq -r '.tunnels[1].public_url')" > ghostinspector.json

# Check JSON results for failing tests
if [ $(grep -c '"passing":false' ghostinspector.json) -ne 0 ]; then exit 1; else echo "Tests Passed"; fi

 

Note: These examples assume that you want to execute a suite after your project has been built. For other options, please see our API.