Fuzzing #2863
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Fuzzing | |
on: | |
pull_request: | |
types: [labeled] | |
schedule: | |
- cron: "14 3 * * *" | |
jobs: | |
fuzz-matrix: | |
if: ${{ github.event_name == 'schedule' || github.event.label.name == 'action/fuzz' }} | |
runs-on: ubuntu-latest | |
outputs: | |
fuzz-names: ${{ steps.list-fuzz.outputs.list }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: '1.19' | |
cache: true | |
- run: go mod download -x | |
- id: list-fuzz | |
run: | | |
list="$(go test -list '^Fuzz' ./... | \ | |
grep '^Fuzz' | \ | |
xargs jq -n '$ARGS.positional' --compact-output --args)" | |
echo "list=${list}" >>$GITHUB_OUTPUT | |
fuzz: | |
needs: fuzz-matrix | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
name: ${{ fromJson(needs.fuzz-matrix.outputs.fuzz-names) }} | |
services: | |
postgres: | |
image: postgres:14-alpine | |
env: | |
POSTGRES_PASSWORD: password123 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: ["127.0.0.1:5432:5432"] | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: '1.19' | |
cache: true | |
- uses: actions/cache@v3 | |
with: | |
key: go-fuzz-corpus-${{ matrix.name }}-${{ github.run_number }} | |
restore-keys: go-fuzz-corpus-${{ matrix.name }}- | |
path: /home/runner/.cache/go-build/fuzz/ | |
- name: Set fuzz time | |
run: echo "fuzz_time=5m" >> $GITHUB_ENV | |
if: "${{ github.event_name == 'pull_request' }}" | |
- name: Run fuzzing | |
run: | | |
name=${{ matrix.name }} | |
# fuzz won't run with ./..., so lookup the package name | |
dir="$(git grep -l "^func ${name}" | xargs dirname)" | |
go test -v -fuzz=${name} -fuzztime "${fuzz_time:-30m}" "./${dir}" | |
env: | |
POSTGRESQL_CONNECTION: "host=localhost port=5432 user=postgres dbname=postgres password=password123" |