forked from grafana/alloy
-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (86 loc) · 3.05 KB
/
fuzz.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Fuzz test
on:
pull_request:
jobs:
find-tests:
name: Find fuzz tests
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Find fuzz tests
id: set-matrix
run: |
TEST_FILES=$(find . -name '*_test.go' -not -path './vendor/*')
RESULTS=()
for FILE in $TEST_FILES; do
FUZZ_FUNC=$(grep -E 'func Fuzz\w*' $FILE | sed 's/func //' | sed 's/(.*$//')
if [ -z "$FUZZ_FUNC" ]; then
continue
fi
PACKAGE_PATH=$(dirname ${FILE#./})
RESULTS+=("{\"package\":\"$PACKAGE_PATH\",\"function\":\"$FUZZ_FUNC\"}")
echo "Found $PACKAGE_PATH :: $FUZZ_FUNC"
done
NUM_RESULTS=${#RESULTS[@]}
INCLUDE_STRING=""
for (( i=0; i<$NUM_RESULTS; i++ )); do
INCLUDE_STRING+="${RESULTS[$i]}"
if [[ $i -lt $(($NUM_RESULTS-1)) ]]; then
INCLUDE_STRING+=","
fi
done
echo 'matrix={"include": ['$INCLUDE_STRING']}' >> $GITHUB_OUTPUT
fuzz:
name: "${{ matrix.package }} :: ${{ matrix.function }}"
runs-on: ubuntu-latest
if: needs.find-tests.outputs.matrix != ''
needs: [find-tests]
strategy:
fail-fast: false # Allow other jobs in the matrix to run even if a single one fails.
matrix: ${{fromJson(needs.find-tests.outputs.matrix)}}
steps:
- uses: actions/checkout@v4
- name: Set up Go 1.22
uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: false
- name: Find cache location
run:
echo "FUZZ_CACHE=$(go env GOCACHE)/fuzz" >> $GITHUB_ENV
- name: Restore corpus
uses: actions/cache@v4
with:
path: ${{ env.FUZZ_CACHE }}
key: fuzz-${{ matrix.package }}-${{ matrix.function }}-${{ github.sha }}
restore-keys: |
fuzz-${{ matrix.package }}-${{ matrix.function }}-
save-always: true
- name: Fuzz
run: |
cd "${{ matrix.package }}"
go test -fuzz="${{ matrix.function }}\$" -run="${{ matrix.function }}\$" -fuzztime=5s .
# Fuzzing may have failed because of an existing bug, or it may have
# found a new one and written a new corpus entry in testdata/ relative to
# the package.
#
# If that file was written, we should save it as an artifact and then
# create an issue.
- name: Check for new corpus entry
id: new-entry
if: ${{ failure() }}
run: |
UNTRACKED=$(git ls-files . --exclude-standard --others)
if [ -z "$UNTRACKED" ]; then
exit 0
fi
echo "Found new corpus entry: $UNTRACKED"
echo "entry=$UNTRACKED" >> $GITHUB_OUTPUT
- name: Upload corpus entry
if: ${{ failure() && steps.new-entry.outputs.entry != '' }}
uses: actions/upload-artifact@v4
with:
name: failed-test
path: ${{ steps.new-entry.outputs.entry }}