Skip to content

Fetch Discord Events (Node.js) #305

Fetch Discord Events (Node.js)

Fetch Discord Events (Node.js) #305

name: Fetch Discord Events (Node.js)
on:
schedule:
# Run once a day at 20:00
- cron: '0 20 * * *'
workflow_dispatch: # Allows for a manual run
jobs:
fetch_and_dump:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Step 1: Check out the repository code
- name: Checkout repository
uses: actions/checkout@v6
# Step 2: Set up a Node.js environment
- uses: pnpm/action-setup@v6
with:
run_install: true
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '24.x' # Or any version you prefer
cache: pnpm
# Step 3: Restore existing events from the event-data branch so past events are preserved
- name: Restore existing events
run: |
git fetch origin event-data || true
git checkout origin/event-data -- scheduled_events.json || true
# Step 4: Install Node.js dependencies
- name: Install dependencies
run: pnpm install
working-directory: 'automation'
# Step 5: Run the Node.js script to fetch events and save to a file
- name: Fetch and save events
run: node get_events.js
working-directory: 'automation'
env:
# Use the GitHub Secret we created to pass the token
DISCORD_BOT_TOKEN: ${{ secrets.DISCORD_BOT_TOKEN }}
# Step 6: Commit the new JSON file back to the repository
- name: Commit and push changes
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add scheduled_events.json
git commit -m "chore(scheduled-events): Update scheduled events from Discord API" || echo "No changes to commit"
git push origin HEAD:event-data --force