Repository navigation
135 lines (119 loc) · 4.61 KB
/
Copy pathfuzz-testing.yml
File metadata and controls
135 lines (119 loc) · 4.61 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Fuzz Testing
on:
# schedule:
# - cron: '0 2 * * *' # Daily at 2 AM
workflow_dispatch:
inputs:
duration:
description: 'Fuzz duration in seconds'
required: false
default: '300'
target:
description: 'Specific fuzz target to run'
required: false
default: ''
permissions:
contents: read
issues: write
jobs:
fuzz:
name: Fuzz Testing with cargo-fuzz
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Rust nightly
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 # master
with:
toolchain: nightly
- name: Install cargo-fuzz
uses: taiki-e/install-action@41049aa56687c35e0afa74eed4f09cec4f9afabf # v2.85.2
with:
tool: cargo-fuzz@0.12.0
- name: Cache fuzz corpus
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: fuzz/corpus
key: ${{ runner.os }}-fuzz-corpus-${{ github.sha }}
restore-keys: |
${{ runner.os }}-fuzz-corpus-
- name: Initialize fuzz directory if needed
run: |
if [ ! -d "fuzz" ]; then
cargo fuzz init
echo "Fuzz directory initialized. Add fuzz targets to fuzz/fuzz_targets/"
fi
- name: List fuzz targets
id: targets
run: |
if [ -d "fuzz/fuzz_targets" ]; then
TARGETS=$(ls fuzz/fuzz_targets/*.rs 2>/dev/null | xargs -n1 basename | sed 's/\.rs$//' || echo "")
echo "targets=$TARGETS" >> $GITHUB_OUTPUT
echo "Found targets: $TARGETS"
else
echo "targets=" >> $GITHUB_OUTPUT
echo "No fuzz targets found"
fi
- name: Run fuzz tests
if: steps.targets.outputs.targets != ''
run: |
DURATION="${{ github.event.inputs.duration || '300' }}"
TARGET="${{ github.event.inputs.target }}"
mkdir -p fuzz-results
if [ -n "$TARGET" ]; then
echo "Running fuzz target: $TARGET for ${DURATION}s"
timeout ${DURATION}s cargo fuzz run $TARGET -- -max_total_time=${DURATION} || true
else
for target in ${{ steps.targets.outputs.targets }}; do
echo "Running fuzz target: $target for ${DURATION}s"
timeout ${DURATION}s cargo fuzz run $target -- -max_total_time=${DURATION} || true
done
fi
- name: Check for crashes
if: steps.targets.outputs.targets != ''
id: crashes
run: |
if [ -d "fuzz/artifacts" ] && [ "$(ls -A fuzz/artifacts 2>/dev/null)" ]; then
echo "crashes=true" >> $GITHUB_OUTPUT
echo "# Fuzz Testing Crashes Detected" > fuzz-report.md
echo "" >> fuzz-report.md
for artifact in fuzz/artifacts/*/*; do
if [ -f "$artifact" ]; then
echo "## Crash: $(basename $(dirname $artifact))" >> fuzz-report.md
echo "File: $artifact" >> fuzz-report.md
echo "\`\`\`" >> fuzz-report.md
xxd -l 256 "$artifact" >> fuzz-report.md || cat "$artifact" >> fuzz-report.md
echo "\`\`\`" >> fuzz-report.md
echo "" >> fuzz-report.md
fi
done
else
echo "crashes=false" >> $GITHUB_OUTPUT
echo "# Fuzz Testing - No Crashes" > fuzz-report.md
echo "All fuzz targets completed successfully." >> fuzz-report.md
fi
- name: Upload fuzz artifacts
if: always() && steps.targets.outputs.targets != ''
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: fuzz-results
path: |
fuzz-report.md
fuzz/artifacts/
fuzz/corpus/
retention-days: 90
- name: Create issue on crash
if: steps.crashes.outputs.crashes == 'true'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const fs = require('fs');
const report = fs.readFileSync('fuzz-report.md', 'utf8');
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Fuzz Testing: Crashes detected on ${new Date().toISOString().split('T')[0]}`,
body: report,
labels: ['bug', 'fuzz-testing', 'security']
});