Backup av Sanity #761
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: Backup av Sanity | |
on: | |
schedule: | |
# Runs at 04:00 UTC every day of the month | |
- cron: "0 4 */1 * *" | |
workflow_dispatch: | |
jobs: | |
backup-dataset: | |
runs-on: ubuntu-latest | |
name: Backup dataset for test og produksjon | |
permissions: | |
id-token: "write" # Used to authenticate with Google Cloud | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install dependencies | |
run: npm install @sanity/cli sanity --//npm.pkg.github.com/:_authToken=${{ secrets.READER_TOKEN }} | |
- name: Hent dagens dato | |
id: date | |
run: echo "dagens_dato=$(date +'%Y-%m-%d')" >> $GITHUB_ENV | |
- name: Export dataset | |
env: | |
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_READ_TOKEN_FOR_BACKUP_JOB }} | |
run: cd frontend/mulighetsrommet-cms && npx sanity dataset export production backups/backup-production-${{ env.dagens_dato }}.tar.gz --overwrite && npx sanity dataset export test backups/backup-test-${{ env.dagens_dato }}.tar.gz --overwrite | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
workload_identity_provider: projects/380520190028/locations/global/workloadIdentityPools/github/providers/github-action | |
service_account: team-mulighetsrommet-backup-sa@team-mulighetsrommet-prod-5492.iam.gserviceaccount.com | |
- name: Set up gcloud | |
uses: google-github-actions/setup-gcloud@v2 | |
- name: Upload files to GCS | |
run: gsutil -m rsync -r /home/runner/work/mulighetsrommet/mulighetsrommet/frontend/mulighetsrommet-cms/backups gs://team-mulighetsrommet-sanity-backup | |
- name: "Slett backup-filer fra repo" | |
run: rm -rf /home/runner/work/mulighetsrommet/mulighetsrommet/frontend/mulighetsrommet-cms/backups/* |