# The batch half of ClusterFuzzLite (#1104).
#
# `cfl-pr.yml` fuzzes what a pull request changed and starts from whatever
# corpus it can find. This is what produces that corpus: a longer nightly run
# whose findings are uploaded as `cifuzz-corpus-<target>` artifacts, which the
# PR job then downloads. Without this the PR job logs
# "Could not find artifact: cifuzz-corpus-..." and searches from cold every
# time -- which is exactly what the first run of #1111 did.
#
# So the two files are one feature. A PR-only setup is a fuzzer with amnesia.
name: cfl-batch

on:
  schedule:
    # 03:20 UTC, off the hour to avoid the top-of-hour scheduling queue.
    - cron: "20 3 * * *"
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}
  cancel-in-progress: false

jobs:
  batch:
    name: Build the corpus
    runs-on: ubuntu-latest
    timeout-minutes: 60
    permissions:
      contents: read
      actions: write # writes the corpus artifacts the PR job reads
    steps:
      - name: Build the fuzzers
        uses: google/clusterfuzzlite/actions/build_fuzzers@884713a6c30a92e5e8544c39945cd7cb630abcd1 # v1
        with:
          language: python
          sanitizer: address

      - name: Fuzz
        uses: google/clusterfuzzlite/actions/run_fuzzers@884713a6c30a92e5e8544c39945cd7cb630abcd1 # v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          fuzz-seconds: 1800
          mode: batch
          sanitizer: address
