name: Auto Update

# Controls when the workflow will run
on:
  workflow_dispatch: # Allows workflow to be manually triggered from Actions page
  schedule:
    - cron: "0 0 * * 0" # Runs every Sunday at midnight

jobs:
  npm-upgrade:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - name: Setup node
        uses: actions/setup-node@v3.4.1
        with:
          node-version: 18
      - name: Update dependencies
        run: npm upgrade
      - uses: tibdex/github-app-token@v1
        id: generate-token
        with:
          app_id: ${{ secrets.APP_ID }}
          private_key: ${{ secrets.APP_PRIVATE_KEY }}
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v4
        with:
          title: "Auto NPM Update"
          body: "This PR was created automatically by the Auto Update workflow."
          signoff: true
          commit-message: "Update dependencies via `npm upgrade`."
          branch: "create-pull-request/auto-update/npm"
          branch-suffix: "timestamp"
          labels: "auto-update,dependencies,javascript"
          delete-branch: true
          token: ${{ steps.generate-token.outputs.token }}