Blinka - Connecting Heroku CI to Github
Tags: github, heroku, testing
Published: 2021-02-10 19:31:27

Heroku CI (continuous integration) runs tests in an environment very similar to an Heroku application, the code is packaged into a slug and runs on a dyno.

With Heroku's Github Integration it can automatically run CI-builds for every commit, then report back to Github with a pass or fail status and a link.
The test results can be parsed if they are reported in the [TAP-format](https://wessman.co/tap-format), but it still stays on Heroku and is not visible on Github.

![Heroku status reported to Github without any test results, just pass or fail.](https://dev-to-uploads.s3.amazonaws.com/i/kyzbye2vlejaobb1p32b.png)

What if we could get the number or failing tests, error messages, backtraces and even screenshots directly to Github?

This is why I built [Blinka🚦](https://www.blinka.app)!

# Setup

1. Configure your application for [Heroku CI](https://devcenter.heroku.com/articles/heroku-ci).
2. Install [`blinka-reporter`](https://github.com/davidwessman/blinka_reporter) by adding it to `Gemfile` using
```bash
bundle add blinka-reporter
```
3. Get `BLINKA_TEAM_ID` and `BLINKA_TEAM_SECRET` from [Blinka🚦](https://www.blinka.app) - the only way to do this today is reaching out to me on Twitter [@davidwessman](https://twitter.com/davidwessman).
4. Add the values from step 3 to Heroku CI environment variables.
5. Add the Github App [blinka-bot](https://github.com/apps/blinka-bot) to the repository.
6. Add Blinka-configuration to the testing part of the Heroku configuration in `app.json`. Mine looks like:
```json
  "environments": {
    "test": {
      "addons": [
        "heroku-postgresql:in-dyno",
        "heroku-redis:in-dyno"
      ],
      "buildpacks": [
        {
          "url": "https://github.com/heroku/heroku-buildpack-google-chrome"
        },
        {
          "url": "https://github.com/heroku/heroku-buildpack-ruby"
        }
      ],
      "env": {
        "BLINKA_REPORT": "true",
        "BLINKA_REPOSITORY": "davidwessman/synka",
        "BLINKA_TAP": "true",
        "WD_CHROME_PATH": "/app/.apt/usr/bin/google-chrome-stable"
      },
      "formation": {
        "test": {
          "quantity": 1,
          "size": "standard-2x"
        }
      },
      "scripts": {
        "test-setup": "bin/yarn && bin/rails webpacker:compile",
        "test": "bin/rails test:system test"
      }
    }
  }
```
7. Before `blinka-reporter` version 0.3.3 you had to do the reporting separately, this is now handled by setting `BLINKA_REPORT=true`.

## Bonus

The gem [`blinka-reporter`](https://github.com/davidwessman/blinka_reporter) also supports outputting test results in TAP-format, without depending on anything but minitest.
Enable by setting the envionment variable `BLINKA_TAP=true`. This allows Heroku to parse the results and report them in their interface.

# Results

## With failing tests

The tests run on Heroku CI and with the TAP-format output we get some feedback in the Heroku interface.

![Test results in Heroku CI interface with one failing test](https://dev-to-uploads.s3.amazonaws.com/i/dhbenuvjuto6zwosmzh1.png)

The test results are reported to [Blinka🚦](https://www.blinka.app) which results in a Github Status:
![Blinka reports number of tests passed, failed or skipped as a Github Status.](https://dev-to-uploads.s3.amazonaws.com/i/w3ivrzxgtf4op15kvwsz.png)

A comment with the results of the CI-run is posted:
![Blinka posts a comment on Github pull request with test results.](https://dev-to-uploads.s3.amazonaws.com/i/qsd41p47jufxwapuv3kb.png)

It can even handle screenshots generated from a failing test, upload them to the service and include them in the comment:
![Blinka includes screenshot from failing test in the Github comment.](https://dev-to-uploads.s3.amazonaws.com/i/yqbexe5bafau2ib64zyu.png)


Please reach out to me on Twitter if you want to learn more!