-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (50 loc) · 1.82 KB
/
Copy pathbackup-events.yml
File metadata and controls
59 lines (50 loc) · 1.82 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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