name: OpenOSRS - Scraper

on:
  schedule:
    - cron: 0 0 * * *

jobs:
  scrape-npcs:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2.3.4
        with:
          repository: open-osrs/cache-client
          ref: master
          path: cache-client

      - uses: actions/cache@v2.1.3
        with:
          path: ~/.gradle/caches
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}
          restore-keys: |
            ${{ runner.os }}-gradle-

      - name: Set up JDK 11
        uses: actions/setup-java@v1.4.3
        with:
          java-version: 11

      - name: Make gradlew executable
        run: chmod +x ./gradlew
        working-directory: cache-client

      - name: Assembling cache client
        run: ./gradlew assemble --console=plain
        working-directory: cache-client

      - name: Downloading jagex cache
        run: ./gradlew download --console=plain
        working-directory: cache-client

      - uses: actions/checkout@v2.3.4
        with:
          repository: open-osrs/runelite
          ref: master
          path: OpenOSRS

      - name: Make gradlew executable
        run: chmod +x ./gradlew
        working-directory: OpenOSRS

      - name: Assembling scraper
        run: ./gradlew :wiki-scraper:assemble --console=plain
        working-directory: OpenOSRS

      - name: Building cache client
        run: ./gradlew build --console=plain
        working-directory: cache-client

      - name: Building scraper
        run: ./gradlew :wiki-scraper:build --console=plain
        working-directory: OpenOSRS

      - name: Scraping NPC stats
        run: ./gradlew :wiki-scraper:npcStatsScrape --console=plain
        working-directory: OpenOSRS

      - name: Create NPC stats Pull Request
        uses: peter-evans/create-pull-request@v3.4.1
        with:
          token: ${{ secrets.OpenOSRS }}
          path: /home/runner/work/runelite/runelite/OpenOSRS
          author: OpenOSRS <openosrs.github@gmail.com>
          committer: OpenOSRS <openosrs.github@gmail.com>
          branch: NPC-UPDATE
          commit-message: 'client: Update NPC stats'
          title: 'client: Update NPC stats'
          body: This is an auto-generated PR with changes from the OSRS wiki
          labels: automated-pull-request, NPC stats
          signoff: false
