name: Update test runtime statistics file for test scheduling
on:
  workflow_dispatch:
  schedule:
    - cron: "1 0 * * SAT"
  # push rule below needed for testing only
  push:
    branches:
      - feat/test-run-scheduler

jobs:
  process-statistics:
    name: Download statistics from GitHub and combine them
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout source code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          token: ${{ secrets.PAT }}

      - name: Process statistics
        uses: Kong/gateway-test-scheduler/analyze@7f296716e385b5fce9573ebc5875f13c09504791 # main (node24)
        env:
          GITHUB_TOKEN: ${{ secrets.PAT }}
        with:
          workflow-name: build_and_test.yml
          test-file-runtime-file: .ci/runtimes.json
          artifact-name-regexp: "^test-runtime-statistics-\\d+$"

      - name: Upload new runtimes file
        uses: Kong/gh-storage/upload@29d5de7b2b87c63016daae5680aefab30812a318 # main (node24)
        env:
          GITHUB_TOKEN: ${{ secrets.PAT }}
        with:
          repo-path: Kong/gateway-action-storage/main/.ci/runtimes.json
