Create Sentry releases after GitHub release

Create Sentry releases after GitHub release

Β·

4 min read

Context

If we are using GitHub releases as part of our release workflow, we can use GitHub Actions to accomplish many tasks, such as notifying services about the new release.

This is very helpful as we can use a single step on our workflow to keep all integrated services in sync.

In this tutorial, we'll notify an error monitoring service called Sentry and create a new release on it with the same version of our app. A real-world scenario for this is an API built with Node.js that uses the Sentry client to report errors.

Services

Sentry

Sentry is a service for error monitoring that helps discover, triage and prioritize errors in real-time.

It's a very helpful and powerful tool as we can receive e-mails on new and reoccurring errors. It's possible to integrate it with many different services and create releases to monitor in which version of our apps an error has happened.

GitHub Actions

GitHub Actions enables automation of our software workflows. It's possible to run workflows with many triggers and perform many tasks from them.

There are thousands of actions available on the marketplace and built by the community that enables us to lint, format, test, build, deploy our projects... The use cases are endless.

Setup

Sentry

In order to communicate with Sentry, we need an auth token. Generate one by going to Settings > Account > API > Auth Tokens > Create New Token. We need a token with org:read and project:releases scopes.

We also need to have the GitHub integration configured and the repository added to our account. Otherwise, the action will fail.

Secrets

We need to setup 3 GitHub secrets on our repo. Go to Settings > Secrets and create the following:

  • SENTRY_AUTH_TOKEN: Sentry auth token created before;
  • SENTRY_ORG: Name found on Settings > Organization Settings;
  • SENTRY_PROJECT: Name of the project created on Sentry.

Workflow

With all the setup finished, create a YAML file under .github/workflows, e.g. create-releases.yml with the following content:

name: Create releases
on:
  release:
    types: [published]
jobs:
  create-sentry-release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@master
      - name: Create a Sentry.io release
        uses: tclindner/sentry-releases-action@v1.2.0
        env:
          SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
          SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
          SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
        with:
          tagName: ${{ github.ref }}
          environment: <env>

And that's it! Now, every time we publish a new release on GitHub, a new release for the same version will be created on Sentry.

Note: environment is a required property that helps filtering issues - see Sentry's documentation. Example values are prod and qa.

Check out an example repo here. Check out the Actions tab to see details of the workflow.

Notes

The example above only creates a Sentry release when our GitHub release is published. However, it's possible to run workflows on other events of a release - see GitHub's documentation.

The tclindner/sentry-releases-action accepts other parameters in the with section. Other examples of parameters are available in the Action's documentation.


I hope you enjoyed this post and follow me on any platform for more.