@@ -89,11 +89,71 @@ jobs:
8989 name : ' unit.report.${{ matrix.os }}-${{ matrix.go }}'
9090 retention-days : 1
9191
92+ fuzz-test :
93+ name : fuzz test
94+ runs-on : ubuntu-latest
95+ env :
96+ CORPUS_MAX_SIZE_MB : 100
97+ steps :
98+ -
99+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
100+ -
101+ uses : actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
102+ with :
103+ go-version : stable
104+ check-latest : true
105+ cache : true
106+ -
107+ name : Locate go fuzz cache
108+ run : |
109+ GOCACHE=$(go env GOCACHE)
110+ echo "GOCACHE=${GOCACHE}/fuzz" >> "${GITHUB_ENV}"
111+ -
112+ uses : actions/cache@v3
113+ with :
114+ key : ${{ runner.os }}-go-fuzz
115+ path :
116+ ${{ env.CORPUS_DIR }}
117+ -
118+ name : Manage fuzz corpus cache size
119+ run : |
120+ CURRENT_SIZE=$(du -sm "${CORPUS_DIR}"|cut -f1)
121+ echo "corpus size: ${CURRENT_SIZE}MB"
122+ if [[ "${CURRENT_SIZE}" -gt "${CORPUS_MAX_SIZE}" ]] ; then
123+ # remove the 50 oldest corpus files
124+ echo "::warning:Large fuzz corpus pruned"
125+ find "${CORPUS_DIR}" -type f|ls -t|tail -n +50|xargs rm -f
126+ fi
127+ -
128+ name : Run go fuzz tests
129+ run : >-
130+ go test
131+ -v
132+ -run Fuzz
133+ -fuzz Fuzz
134+ -fuzztime 2m
135+ -fuzzminimizetime 5m
136+ ./...
137+ -
138+ name : Upload failed corpus
139+ if : ${{ failure() }}
140+ uses : actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
141+ with :
142+ path : ${{ env.CORPUS_DIR }}
143+ name : ' ${{ runner.os }}-fuzz-corpus-failure'
144+ retention-days : 60
145+ -
146+ name : Report fuzz corpus cache size
147+ run : |
148+ FINAL_SIZE=$(du -m "${CORPUS_DIR}"|cut -f1)
149+ echo "::notice title=fuzz corpus size:${FINAL_SIZE}MB"
150+
151+
92152 test-complete :
93153 # description: |
94154 # Be explicit about all tests being passed. This allows for setting up only a few status checks on PRs.
95155 name : tests completed
96- needs : [test]
156+ needs : [test,fuzz-test ]
97157 runs-on : ubuntu-latest
98158 steps :
99159 -
0 commit comments