---
name: autocheck
on:
  schedule:
    - cron: '0 0 * * *'
  workflow_dispatch:
env:
  GH_TOKEN: ${{ secrets.CREW_PR_TOKEN }}
permissions:
  actions: write
  contents: write
  packages: write
  pull-requests: write
  repository-projects: read
jobs:
  autocheck:
    if: ${{ github.repository_owner == 'chromebrew' }}
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: true
      - name: Run required checks if necessary
        run: |
            for pr in $(gh pr list -s open --author app/github-actions --json number | jq '.[].number')
            do
              # Run check workflow if it didn't already run.
              gh pr checks --required $pr || (echo "Running check workflow on PR ${pr}." ; gh workflow run Unit-Test.yml $pr)
              # Add reviewers to autogenerated PRs.
              gh pr edit $pr --add-reviewer chromebrew/active
            done
