name: Update user agents

on:
  schedule:
    - cron: '0 0 1 * *'
  workflow_dispatch:

jobs:
  update-user-agents:
    if: github.repository == 'streamlink/streamlink'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
      - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
        with:
          python-version: "3.14"
      - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
      - run: uv run --frozen --only-group script ./script/update-user-agents.py
        env:
          WHATISMYBROWSER_API_KEY: ${{ secrets.WHATISMYBROWSER_API_KEY }}
      - uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
        with:
          token: ${{ secrets.STREAMLINKBOT_USERAGENTS_PR }}
          add-paths: |
            src/streamlink/session/http_useragents.py
          commit-message: "session.http_useragents: update useragents"
          committer: "streamlinkbot <streamlinkbot@users.noreply.github.com>"
          author: "streamlinkbot <streamlinkbot@users.noreply.github.com>"
          branch: "automated/session/http_useragents/update"
          branch-suffix: timestamp
          delete-branch: true
          title: "session.http_useragents: update useragents"
          body: "Automated pull request"
