Create Sentry releases after GitHub release
Tags: github, sentry, workflow, tutorial
Published: 2020-07-10 12:21:07

---
title: Create Sentry releases after GitHub release
published: true
description: Using GitHub Actions to automate integration
tags: github, sentry, workflow, tutorial
cover_image: https://res.cloudinary.com/arthurdenner/image/upload/v1594143886/posts/github_actions_sentry.png
---

## Context
 
If we are using [GitHub releases](https://docs.github.com/en/github/administering-a-repository/releasing-projects-on-github) 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](https://sentry.io/welcome/) 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](https://docs.github.com/en/actions/reference/events-that-trigger-workflows) and perform many tasks from them.

There are thousands of actions available on the [marketplace](https://github.com/marketplace?type=actions) 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`](https://sentry.io/settings/account/api/auth-tokens/new-token/). We need a token with `org:read` and `project:releases` scopes.

We also need to have the [GitHub integration](https://sentry.io/integrations/github/) 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:

```yml
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](https://docs.sentry.io/enriching-error-data/environments/). Example values are `prod` and `qa`.

Check out an example repo [here](https://github.com/arthurdenner/releases-sentry-heroku-github-actions). Check out the [Actions tab](https://github.com/arthurdenner/releases-sentry-heroku-github-actions/actions) 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](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release-event-release).

The `tclindner/sentry-releases-action` accepts other parameters in the `with` section. Other examples of parameters are available in the Action's [documentation](https://github.com/tclindner/sentry-releases-action).

---

I hope you enjoyed this post and [follow me](https://linktr.ee/arthurdenner) on any platform for more.