@@ -89,11 +89,72 @@ 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 : ' ${{ matrix.go }}'
104+ check-latest : true
105+ cache : true
106+ -
107+ name : Locate go fuzz cache
108+ run : |
109+ echo "$(go env GOCACHE)/fuzz" >> "${GITHUB_ENV}"
110+ -
111+ uses : actions/cache@v3
112+ with :
113+ key : ${{ runner.os }}-go-fuzz
114+ path :
115+ ${{ env.CORPUS_DIR }}
116+ -
117+ name : Manage fuzz corpus cache size
118+ run : |
119+ mkdir -p "${{ env.CORPUS_DIR}}"
120+
121+ CURRENT_SIZE=$(du -sm "${CORPUS_DIR}"|cut -f1)
122+ echo "corpus size: ${CURRENT_SIZE}MB"
123+ if [[ "${CURRENT_SIZE}" -gt "${CORPUS_MAX_SIZE}" ]] ; then
124+ # remove the 50 oldest corpus files
125+ echo "::warning:Large fuzz corpus pruned"
126+ find "${CORPUS_DIR}" -type f|ls -t|tail -n +50|xargs rm -f
127+ fi
128+ -
129+ name : Run go fuzz tests
130+ run : >-
131+ go test
132+ -v
133+ -run Fuzz
134+ -fuzz Fuzz
135+ -fuzztime 2m
136+ -fuzzminimizetime 5m
137+ ./...
138+ -
139+ name : Upload failed corpus
140+ if : ${{ failure() }}
141+ uses : actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
142+ with :
143+ path : ${{ env.CORPUS_DIR }}
144+ name : ' ${{ runner.os }}-fuzz-corpus-failure'
145+ retention-days : 60
146+ -
147+ name : Report fuzz corpus cache size
148+ run : |
149+ FINAL_SIZE=$(du -m "${CORPUS_DIR}"|cut -f1)
150+ echo "::notice title=fuzz corpus size:${FINAL_SIZE}MB"
151+
152+
92153 test-complete :
93154 # description: |
94155 # Be explicit about all tests being passed. This allows for setting up only a few status checks on PRs.
95156 name : tests completed
96- needs : [test]
157+ needs : [test,fuzz-test ]
97158 runs-on : ubuntu-latest
98159 steps :
99160 -
0 commit comments