Automatic Sanity Studio Deploy
#Sanity
#GitHub Actions
The Setup
To make this work, you'll need to create a new API token in Sanity to put in the Github Repository as a Secret:
1.) Go to https://www.sanity.io/manage and find the desired Sanity project.
2.) Select API in the Project Settings.
3.) Under Tokens, create a new token called SANITY_AUTH_TOKEN as a deploy token:

4.) Create the token, copy it. and add it to your GitHub repo in Settings then add the Secret.
5.) Boom! You're all set to add the code to your .github/workflows folder to enable GH Actions.
The Code
.github/workflows/build-studio.yamlname: Build && Deploy Sanity Studio
on:
push:
branches: [main]
paths-ignore:
- "./web/**"
jobs:
sanity-deploy:
name: Build & Deploy Sanity Studio
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 12.x
- name: Install dependencies
run: |
cd studio
npm install
npm install @sanity/cli
- name: Deploy Sanity Studio
run: |
set -e
cd studio
SANITY_AUTH_TOKEN="${{ secrets.SANITY_AUTH_TOKEN }}" npx sanity deploy