Max Schmitt

August 20 2020

How to deploy Sanity from GitHub Actions

Sanity is an amazing CMS that has found the perfect balance between customizability and development speed.

In this post I will show you how to deploy your Sanity CMS from GitHub Actions.

First, we will need to generate an auth token that allows us to deploy our Sanity project. This way we won't have to run sanity login in CI.


To generate the auth token, head over to, log in and then go to your project's settings. There, go to API > Tokens > Add new token. A modal will show up. Make sure to select "Deploy studio" under "Rights".

A modal showing configuration options for auth tokens on

2. Configure GitHub Secrets

Next, head over to your GitHub repository. Go to Settings > Secrets and click New secret. Add here the auth token that you generated in the first step and call it SANITY_AUTH_TOKEN.

You can also add other environment variables that you might need for your build, just make sure to prefix them with SANITY_STUDIO_.

GitHub secrets configuration screen showing environment variables

3. Add GitHub Actions workflow for deploying Sanity

Now, just copy the following file into your repository. I've highlighted the section that creates the environment variables for your build. Make sure to customize it as you need it.


name: CI
branches: [master]
runs-on: ubuntu-latest
- uses: actions/checkout@v2
- name: Setup Node.js environment
uses: actions/setup-node@v1.4.2
node-version: 12.x
- name: Install dependencies
run: |
- name: Deploy Sanity
run: |
set -e
# Put your environment variables here. Don't forget
# to create secrets for them on GitHub:
cat << EOF > .env.production
# Make sure to add a secret for SANITY_AUTH_TOKEN
SANITY_AUTH_TOKEN="${{ secrets.SANITY_AUTH_TOKEN }}" yarn sanity deploy

And that's all it takes to add Sanity deployment to your CI on GitHub!