Reset Production #59
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Reset Production | |
on: | |
# Run at 2AM every night | |
schedule: | |
- cron: '0 10 * * *' | |
# Also support manual | |
workflow_dispatch: | |
jobs: | |
reset: | |
name: Reset dataset | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install repo | |
uses: bkwld/cloak-actions/install@v1 | |
- name: Install Sanity CLI tools | |
run: yarn global add @sanity/cli groq-cli | |
# Deleting of the whole dataset was not allowed, so deleting all the | |
# user created documents before re-importing them | |
# https://github.com/sanity-io/sanity/issues/2935#issuecomment-1161251898 | |
# https://www.sanity.io/guides/bulk-deletion-using-sanity-cli | |
- name: Delete current documents | |
env: | |
SANITY_AUTH_TOKEN: ${{ secrets.RESET_DATASET_SANITY_API_TOKEN }} | |
NEXT_PUBLIC_SANITY_PROJECT_ID: ${{ vars.SANITY_PROJECT_ID }} | |
run: > | |
sanity documents query "*[ | |
!(_type match 'sanity.*') && | |
!(_type match 'system.*') && | |
!(_type match 'preview.*') | |
]._id" --dataset production --apiVersion 2023-05-01 | |
| groq "*" -o ndjson | |
| xargs sanity documents delete --dataset production | |
- name: Import backup | |
env: | |
SANITY_AUTH_TOKEN: ${{ secrets.RESET_DATASET_SANITY_API_TOKEN }} | |
NEXT_PUBLIC_SANITY_PROJECT_ID: ${{ vars.SANITY_PROJECT_ID }} | |
run: sanity dataset import backups/production.gz production --replace |