-
Notifications
You must be signed in to change notification settings - Fork 0
45 lines (37 loc) · 1.42 KB
/
reset-dataset.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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