on:
  schedule:
    # runs every Wednesday at 0,6,12,18 UTC in Jan, Feb, Sep-Dec
    - cron: '0 5 * 9-12,1 3'
    # as well as first two weeks of february
    - cron:  '0 5 1-15 2 3'
    # and every day through the last seven days of April (before/during the NFL draft)
    - cron:  '0 5 23-30 4 *'
    # and every day through the first five days of May (after the NFL draft)
    - cron:  '0 5 1-5 5 *'
  workflow_dispatch:

name: update_draft_picks

jobs:
  update_snap_counts:
    runs-on: ${{ matrix.config.os }}

    name: ${{ matrix.config.os }} (${{ matrix.config.r }})

    strategy:
      fail-fast: false
      matrix:
        config:
          - {os: ubuntu-latest,   r: 'release'}

    env:
      GITHUB_PAT: ${{ secrets.NFLVERSE_GH_TOKEN }}
      R_KEEP_PKG_SOURCE: yes

    steps:
      - uses: actions/checkout@v2

      - uses: r-lib/actions/setup-r@v2
        with:
          r-version: ${{ matrix.config.r }}
          http-user-agent: ${{ matrix.config.http-user-agent }}
          use-public-rspm: true

      - uses: r-lib/actions/setup-r-dependencies@v2
        with:
          cache-version: 1
          extra-packages: |
            nflverse/nflverse-data
            ropensci/piggyback

      - name: Update draft pick data
        run: Rscript -e 'source("auto/update_draft_picks.R")'
