name: Update and Create PR

on:
  schedule:
    - cron: '0 0 1 * *' # Runs on the first day of each month at midnight
  workflow_dispatch: # Allows the workflow to be triggered manually

permissions:
  contents: write
  pull-requests: write

jobs:
  update-and-pr:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository 🛎️
        uses: actions/checkout@v4

      - name: Set up Node.js 🛠️
        uses: actions/setup-node@v4
        with:
          node-version: 'lts/*' # Use the LTS version of Node.js

      - name: Install dependencies 📦
        run: npm install

      - name: Run update script 🔄
        run: npm run update

      - name: Create Pull Request 🚀 (if there are changes)
        uses: peter-evans/create-pull-request@v6
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          branch: auto-update
          title: "🤖Automated update"
          body: "This PR contains automated updates from running `npm run update`"
          labels: "automated update"

