Backup Firestore #506
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 Firestore | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
# on: [push] | |
jobs: | |
backup: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v3 | |
- name: Backup firestore db in json format | |
run: | | |
echo ${{ secrets.GCP_SA_KEY }} | base64 -d > gcp.json | |
echo ${{ secrets.FB_SA_KEY }} | base64 -d > fb.json | |
npm i | |
GOOGLE_APPLICATION_CREDENTIALS='gcp.json' npx backfire export gs://nostrdb-backups/ndjson/$(date +'%Y-%m-%d').ndjson --gcpProject nostrdirectory --gcpKeyFile gcp.json --paths twitter --project nostrdirectory --keyFile fb.json | |
- name: pretty-stats | |
id: pretty-stats | |
run: | | |
stats=$(curl 'https://firestore.googleapis.com/v1/projects/nostrdirectory/databases/(default)/documents/stats/data') | |
tweetCount=`echo $stats | jq '.fields.tweetCount.integerValue'` | |
verifiedCount=`echo $stats | jq '.fields.verifiedCount.integerValue'` | |
mastodonCount=`echo $stats | jq '.fields.mastodonCount.integerValue'` | |
telegramCount=`echo $stats | jq '.fields.telegramCount.integerValue'` | |
donationBalance=`echo $stats | jq '.fields.donationBalance.integerValue'` | |
donatedCount=`echo $stats | jq '.fields.donatedCount.integerValue'` | |
output=`echo tweetCount $tweetCount, verifiedCount $verifiedCount, telegramCount $telegramCount, mastodonCount $mastodonCount, donatedCount $donatedCount, donationBalance $donationBalance` | |
echo "prettystats=$output" >> $GITHUB_OUTPUT | |
- name: publish stats | |
uses: theborakompanioni/nostr-action@v1 | |
with: | |
key: ${{ secrets.NOSTR_KEY }} | |
relay: wss://nostr-pub.wellorder.net | |
content: 🤖 Latest stats -> ${{ steps.pretty-stats.outputs.prettystats }} |