Lets add support to Circle CI to make sure the code is tested regularly. The idea is to have Circle CI to build and run the tests so we can have confidence that the project is in a health state.

The first thing you will need is to create an account on the Circle CI website and add the project so Circle CI can start to monitor your repository and start the building process as soon as new commits arrive.

Having the account created and the project added, we need to create the configuration file - circle.yml - in the project’s root folder. This file will tell Circle CI about the project dependencies and what commands to run.

  # exports environment variables
    PGUSER: postgres
    PGDATABASE: circle_test
    PGPORT: 5432
    PGHOST: localhost

    # Frontend app javascript modules
    - "js/node_modules"
    # Backend app haskell modules
    - "~/.stack"

    # Install stack
    - wget -q -O- https://s3.amazonaws.com/download.fpcomplete.com/ubuntu/fpco.key | sudo apt-key add -
    - echo 'deb http://download.fpcomplete.com/ubuntu/precise stable main' | sudo tee /etc/apt/sources.list.d/fpco.list
    - sudo apt-get update && sudo apt-get install stack -y

    # Build javascript dependencies
    - cd js && npm install --save-dev
    # Build haskell dependencies
    - stack setup && stack build --test --only-dependencies

    # run js tests
    - cd js && npm test
    # run haskell tests
    - stack test

Configuring Yesod

We will need to change the test-settings.yml and the TestImport.hs files so Yesod will handle settings with environment variables when running the tests.

First we tell Yesod that flora_test is the default test database and that it can be overwritten by the PGDATABASE environment variable.

--- a/config/test-settings.yml
+++ b/config/test-settings.yml
@@ -1,2 +1,2 @@
-  database: flora_test
+  database: "_env:PGDATABASE:flora_test"

Secondly, we need to change the TestImport.hs file because it ignores environment variables by default.

diff --git a/test/TestImport.hs b/test/TestImport.hs
index 625acce..ad76ec4 100644
--- a/test/TestImport.hs
+++ b/test/TestImport.hs
@@ -11,7 +11,7 @@ import Foundation            as X
 import Model                 as X
 import Test.Hspec            as X
 import Text.Shakespeare.Text (st)
-import Yesod.Default.Config2 (ignoreEnv, loadAppSettings)
+import Yesod.Default.Config2 (useEnv, loadAppSettings)
 import Yesod.Test            as X

 runDB :: SqlPersistM a -> YesodExample App a
@@ -28,7 +28,7 @@ withApp = before $ do
     settings <- loadAppSettings
         ["config/test-settings.yml", "config/settings.yml"]
-        ignoreEnv
+        useEnv
     foundation <- makeFoundation settings
     wipeDB foundation
     logWare <- liftIO $ makeLogWare foundation

Now, every time you push a commit to github, Circle CI will build the project and run the tests.


You can access the Project settings -> Status badges menu in the Circle CI platform and generate a badge for you to put in your project README file. The badge will change as the last build build successfully or not.

This is how it looks like: