name: Update .mergify.yml
on:
  schedule:
    # Runs once an hour
    - cron: "0 * * * *"

jobs:
  update-mergify:
    name: Update .mergify.yml
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: master
      - name: Checkout Chisel Repo Tools
        uses: actions/checkout@v2
        with:
          repository:  ucb-bar/chisel-repo-tools
          path: tools
      - name: Setup Scala
        uses: olafurpg/setup-scala@v10
      - name: Install Ammonite
        run: sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/com-lihaoyi/Ammonite/releases/download/2.3.8/2.13-2.3.8) > /usr/local/bin/amm && chmod +x /usr/local/bin/amm'
      - name: Cache Scala
        uses: coursier/cache-action@v6
      - name: Generate .mergify.yml
        run: |
          ./tools/scripts/mergify.sc .github/configs/mergify_config.yml > .mergify.yml
          # Delete tools so they don't get included in commit
          rm -rf tools/
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v3.8.2
        with:
          # TODO Default GITHUB_TOKEN cannot trigger PR CI
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Update .mergify.yml
          branch: actions/workflows/update-mergify
          delete-branch: true
          title: Update .mergify.yml
          body: |
            This is an automated pull request by "Update .mergify.yml" workflow created with [create-pull-request][1].

            [1]: https://github.com/peter-evans/create-pull-request

