discord-backup-report #33
This file contains hidden or 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: discord-backup-report | |
| on: | |
| schedule: | |
| - cron: "17 7 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: discord-backup-repo | |
| cancel-in-progress: false | |
| jobs: | |
| report: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 60 | |
| steps: | |
| - name: Checkout discrawl | |
| uses: actions/checkout@v6.0.2 | |
| - name: Setup Go | |
| uses: actions/setup-go@v6.4.0 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Restore Discord DB cache | |
| id: restore-discord-db | |
| uses: actions/cache/restore@v5.0.5 | |
| with: | |
| path: | | |
| .discrawl-ci/discrawl.db | |
| .discrawl-ci/discrawl.db-shm | |
| .discrawl-ci/discrawl.db-wal | |
| key: discrawl-discord-db-${{ runner.os }}-${{ github.ref_name }}-${{ github.run_id }}-${{ github.run_attempt }} | |
| restore-keys: | | |
| discrawl-discord-db-${{ runner.os }}-${{ github.ref_name }}- | |
| discrawl-discord-db-${{ runner.os }}- | |
| - name: Configure Git identity | |
| run: | | |
| git config --global user.name "discrawl reporter" | |
| git config --global user.email "discrawl-reporter@users.noreply.github.com" | |
| - name: Generate daily Discord report | |
| env: | |
| DISCORD_BACKUP_TOKEN: ${{ secrets.DISCORD_BACKUP_TOKEN }} | |
| DISCRAWL_BACKUP_REPOSITORY: ${{ secrets.DISCRAWL_BACKUP_REPOSITORY }} | |
| CONFIG: ${{ runner.temp }}/discrawl/config.toml | |
| DB: ${{ github.workspace }}/.discrawl-ci/discrawl.db | |
| BACKUP_REPO: ${{ runner.temp }}/discord-backup | |
| run: | | |
| if [ -z "${DISCRAWL_BACKUP_REPOSITORY:-}" ]; then | |
| echo "::notice title=Backup report skipped::Configure DISCRAWL_BACKUP_REPOSITORY as owner/repo to enable archive reports." | |
| exit 0 | |
| fi | |
| if [ -z "${DISCORD_BACKUP_TOKEN:-}" ]; then | |
| echo "::error title=Missing secret::Configure DISCORD_BACKUP_TOKEN with write access to the backup repository." | |
| exit 1 | |
| fi | |
| BACKUP_REMOTE="https://x-access-token:${DISCORD_BACKUP_TOKEN}@github.com/${DISCRAWL_BACKUP_REPOSITORY}.git" | |
| mkdir -p "$(dirname "$CONFIG")" | |
| mkdir -p "$(dirname "$DB")" | |
| git clone "$BACKUP_REMOTE" "$BACKUP_REPO" | |
| printf 'db_path = "%s"\n' "$DB" > "$CONFIG" | |
| go run ./cmd/discrawl --config "$CONFIG" subscribe --repo "$BACKUP_REPO" "$BACKUP_REMOTE" | |
| go run ./cmd/discrawl --config "$CONFIG" report --readme "$BACKUP_REPO/README.md" | |
| if git -C "$BACKUP_REPO" diff --quiet README.md; then | |
| echo "README already up to date" | |
| exit 0 | |
| fi | |
| git -C "$BACKUP_REPO" add README.md | |
| git -C "$BACKUP_REPO" commit -m "docs: update discord activity report" | |
| git -C "$BACKUP_REPO" pull --rebase --autostash origin main | |
| git -C "$BACKUP_REPO" push | |
| - name: Save Discord DB cache | |
| uses: actions/cache/save@v5.0.5 | |
| with: | |
| path: | | |
| .discrawl-ci/discrawl.db | |
| .discrawl-ci/discrawl.db-shm | |
| .discrawl-ci/discrawl.db-wal | |
| key: ${{ steps.restore-discord-db.outputs.cache-primary-key }} |