---
title: "Using GitHub Actions to Create Sentry Releases"
description: "At Sentry, we're big fans of continuous integration and deployment, and of course, GitHub. In this blog post, we'll walk through how to use GitHub Actions to automatically create Sentry releases."
url: "https://blog.sentry.io/using-github-actions-to-create-sentry-releases/"
canonical_url: "https://blog.sentry.io/using-github-actions-to-create-sentry-releases/"
authors: ["Liz Krane"]
published: "2019-12-17"
category: "Product Updates"
---

# Using GitHub Actions to Create Sentry Releases

\*UPDATE: We have an official Sentry GitHub Action. Learn more [here](https://blog.sentry.io/minimize-risk-continuous-shipping-integration-deployment/). \*

At Sentry, we’re big fans of [continuous integration and deployment](https://blog.sentry.io/minimize-risk-continuous-shipping-integration-deployment/). We’re also big fans of GitHub — and not just because we employ a number of notable GitHub alumni. We use our own [GitHub integration](https://docs.sentry.io/integrations/source-code-mgmt/github/) to link issues, identify suspect commits that likely introduced new errors, and suggest assignees who can best resolve each issue.

Last month, GitHub [released GitHub Actions for general availability](https://github.blog/2019-11-14-powering-community-led-innovation-with-github-actions/). Much like Sentry’s own [Integration Platform](https://docs.sentry.io/integrations/integration-platform/), GitHub Actions lets developers create their own customized, automated workflows and combine their favorite third party tools — in this case, directly from within a GitHub repo!

In this blog post, we’ll walk through how to use GitHub Actions to automatically create Sentry releases.

![action](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-0.D0DV_I27.jpg&w=1200&q=100)

## Writing a GitHub Actions workflow file

GitHub Actions are defined in a `.yml` or `.yaml` “workflow” file stored in your repository’s `.github/workflows` directory.

These workflow files allow you to define commands to run on a GitHub-hosted [virtual machine](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners), triggered by various workflow events within GitHub. For example, in [our example GitHub Action](https://github.com/getsentry/sentry-round-robin/blob/master/.github/workflows/sentry-and-heroku-deploy.yml) workflow file, we run our commands whenever a commit is pushed to the master branch:

```plaintext
name: New Sentry Release and Deploy to Heroku
on:
  push:
    branches:
      - master
```

_See GitHub’s documentation on _[_workflow event triggers_](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows)_ to explore the other events you can work with._

The main body of our workflow file defines which environment to run in, a list of environment variables, and the sequence of steps to run. These steps can be pre-defined GitHub Actions, like the [checkout action](https://github.com/actions/checkout) that checks out a copy of the current repo, enabling you to run commands like `git push` within the workflow.

```plaintext
jobs:
  release:
    runs-on: ubuntu-18.04
    env:
      SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
    steps:
      - uses: actions/checkout@v1.0.0
      - name: Create new Sentry release and deploy
    run: |
      # Run some commands here
```

To store any authentication tokens (for example, your `SENTRY_AUTH_TOKEN`) or other sensitive information, go to your GitHub repo and navigate to Settings > Secrets. There you can save any required information and pull them into your GitHub Actions virtual machine as environment variables.

![secrets](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-1.BQZ_I2JE.jpg&w=1200&q=100)

In [our example workflow](https://github.com/getsentry/sentry-round-robin/blob/master/.github/workflows/sentry-and-heroku-deploy.yml), we use the following environment variables for the Sentry CLI:

-   `SENTRY_AUTH_TOKEN` - Your [Internal Integration token](https://docs.sentry.io/integrations/integration-platform/#auth-tokens-1).
-   `SENTRY_ORG` - Your Sentry organization slug.
-   `SENTRY_PROJECT` - Your Sentry project slug.
-   `SENTRY_DEPLOY_ENVIRONMENT` - Optionally, you can set the name of the environment (for example, “production”) that will show up in your Sentry deploys.

## Creating a Sentry Internal Integration

Our [Integration Platform](https://blog.sentry.io/introducing-sentry-integration-platform/) allows developers to connect Sentry with third-party tools — either as Public Integrations that anyone can use, or as [Internal Integrations](https://blog.sentry.io/sentrys-internal-integrations-build-internal-tools-that-fit-your-workflow/) built only for one organization to combine Sentry with their internal tools and custom workflows.

To create a new Internal Integration, navigate to _Settings > Developer Settings > New Internal Integration_ within Sentry. There, you’ll give your new integration a title (for example, “Create Sentry Releases with GitHub Actions”), choose which permissions to use, and get your token for authenticating with Sentry’s API.

### Setting permissions

You can apply [different sets of permissions](https://docs.sentry.io/api/permissions/) for each integration. For this one, we’ll need `Admin` access for “Release” and `Read` access for “Organization”:

![permissions](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-0.B0cBznBQ.png&w=1200&q=100)

_See our _[_docs page on permissions_](https://docs.sentry.io/api/permissions/)_ to learn more about scopes for Sentry’s API endpoints._

Next, click “Save” at the bottom of the page and then grab your token:

![credentials](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-1.B-kYRS3X.png&w=1200&q=100)

In the next section, we’ll use this Internal Integration token to enable our GitHub Actions workflow to authenticate with Sentry’s API when creating a new Release.

## Creating a new release within a GitHub Actions workflow

First things first: if you’re going to use GitHub Actions, it’ll work best if you’re also using [our GitHub integration](https://docs.sentry.io/integrations/#github) so that new releases can automatically be associated with your project’s latest commits. Be sure to add the GitHub integration to Sentry ([see instructions in our docs here](https://docs.sentry.io/integrations/#github)) and then configure the GitHub integration to use your repository.

![repos](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-4.DWLWeYeH.png&w=1200&q=100)

Our [example workflow](https://github.com/getsentry/sentry-round-robin/blob/master/.github/workflows/sentry-and-heroku-deploy.yml) installs [Sentry’s command line interface](https://docs.sentry.io/cli/) on GitHub’s virtual machine, creates a new Sentry release, and then creates a new Sentry deploy linked to that release:

```plaintext
run: |
  # Install Sentry CLI
  curl -sL https://sentry.io/get-cli/ | bash

  # Create new Sentry release
  export SENTRY_RELEASE=$(sentry-cli releases propose-version)
  sentry-cli releases new -p $SENTRY_PROJECT $SENTRY_RELEASE
  sentry-cli releases set-commits --auto $SENTRY_RELEASE
  sentry-cli releases finalize $SENTRY_RELEASE

  # Create new deploy for this Sentry release
  sentry-cli releases deploys $SENTRY_RELEASE new -e $SENTRY_DEPLOY_ENVIRONMENT
```

_See our documentation for more details about _[_Sentry release management_](https://docs.sentry.io/cli/releases/)_._

If we also wanted to deploy our app to (for example) Heroku, we can take advantage of the fact that Github’s virtual environment includes the Heroku CLI by default. Just a couple more commands will update Heroku’s environment variable for the `SENTRY_RELEASE` and then deploy the app to Heroku:

```plaintext
run: |
  # ... previous Sentry commands

  # Update Heroku env var for SENTRY_RELEASE so future events are linked to the latest releast
  heroku config:set SENTRY_RELEASE=$SENTRY_RELEASE -a ${{ secrets.HEROKU_APP_NAME }}

  # Deploy to Heroku
  git push https://heroku:$HEROKU_API_KEY@git.heroku.com/${{ secrets.HEROKU_APP_NAME }}.git HEAD:master
```

**Checking that the GitHub Action worked:**

To run your GitHub Action, you’ll need to invoke the triggering event — for example, pushing a new commit to the master branch. Navigate to the “Actions” tab via your GitHub repository page to see the status of your workflow.

Once the workflow completes, navigate to your Sentry project and click “Releases” on the left-side menu. You’ll see a brand new release listed for your project, which will also show the environment to which you most recently deployed the project. (In our example workflow, this is whatever value is entered for the `SENTRY_DEPLOY_ENVIRONMENT` value in GitHub Secrets.)

![release](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-5.BtaBaFTQ.jpg&w=1200&q=100)

To check that new events from your project are associated with the latest release, you’ll need to trigger an error in your project.

For example, if you’re using an Express app, you can add the following Express route:

```plaintext
app.get('/debug-sentry', function mainHandler(req, res) {
  throw new Error('Sentry error!');
});
```

_See our docs for the complete _[_Nodejs/Express example code_](https://docs.sentry.io/platforms/javascript/guides/express/)_._

After triggering a new error, check your project’s “Releases” page again in Sentry. On the page for your latest release, you’ll see a new unresolved issue associated with the release:

![release-2](https://blog.sentry.io/_vercel/image?url=_astro%2Finline-6.Dn69uwT-.jpg&w=1200&q=100)

## Using pre-defined GitHub Actions

In addition to creating your own workflow files as part of your codebase, you can also use pre-defined GitHub Actions created by others. The [GitHub Marketplace](https://github.com/marketplace?type=actions) features many public Actions that do run common tasks like running tests, deploying code, sending notifications, and publishing npm modules. A community member even created [an Action to create Sentry releases](https://github.com/marketplace/actions/create-a-sentry-io-release).

Many popular cloud computing platforms already have GitHub Actions available to help you automate deploying your code:

-   [Actions for Google Cloud Platform](https://github.com/GoogleCloudPlatform/github-actions)
-   [AWS Actions](https://github.com/aws-actions)
-   [Actions for Microsoft Azure](https://github.com/Azure/actions)

Pre-defined Actions that exist in dedicated repositories can be referenced by `{owner}/{repo}@{ref}`. For example, [in our workflow](https://github.com/getsentry/sentry-round-robin/blob/master/.github/workflows/sentry-and-heroku-deploy.yml) we referenced the [checkout action](https://github.com/actions/checkout):

```plaintext
steps:
  - uses: actions/checkout@v1.0.0
```

To learn more about creating and using GitHub Actions, check out [GitHub’s documentation](https://help.github.com/en/actions/automating-your-workflow-with-github-actions) which features several step-by-step tutorials.

## The future is **Action-packed**

By combining [Sentry’s Github integration](https://docs.sentry.io/integrations/source-code-mgmt/github/) with Github Actions, [Sentry’s command line interface](https://docs.sentry.io/cli/) (or [REST API](https://docs.sentry.io/api/)), and your other third-party tools of choice, there’s no limit to the vast array of customizations you can create for your own development pipeline! Is your team using Github Actions and Sentry in other ways? Let us know; we’d love to hear from you!

And if workflow customization is your jam, be sure to check out our [Integration Platform](https://docs.sentry.io/integrations/integration-platform/) for more ways to combine other tools with Sentry.
