Skip to content

Backup events from Netlify Blobs #3

Backup events from Netlify Blobs

Backup events from Netlify Blobs #3

Workflow file for this run

name: Backup events from Netlify Blobs
on:
schedule:
- cron: "0 3 1 * *" # 3 AM UTC on the 1st of each month
workflow_dispatch: # allow manual trigger
jobs:
backup:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- name: Fetch events from Netlify Blobs
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
run: |
node -e "
const { getStore } = require('@netlify/blobs');
const fs = require('fs');
async function main() {
const store = getStore({
name: 'events',
siteID: process.env.NETLIFY_SITE_ID,
token: process.env.NETLIFY_AUTH_TOKEN,
});
const events = await store.get('all', { type: 'json' });
fs.writeFileSync('data/events.json', JSON.stringify(events, null, 2));
console.log('Fetched ' + events.length + ' events');
}
main().catch(e => { console.error(e); process.exit(1); });
"
- name: Check for changes
id: diff
run: |
git diff --quiet data/events.json && echo "changed=false" >> "$GITHUB_OUTPUT" || echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Commit and push
if: steps.diff.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add data/events.json
git commit -m "Sync events from Netlify Blobs
Automated monthly backup of live event data."
git push