name: Fuzzing

on: [push, pull_request]

permissions:
  contents: read

jobs:
  fuzzing:
    name: Fuzz
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
        with:
          persist-credentials: false

      - name: Setup Node
        uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
        with:
          node-version: lts/*

      - name: Install
        run: |
          npm install

      - name: Run fuzzing
        timeout-minutes: 10
        run: |
          npm run fuzz

      - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
        if: ${{ failure() }}
        with:
          name: undici-fuzz-results-${{ github.sha }}
          path: |
            corpus/
            crash-*
            fuzz-results-*.json
