Skip to content

Commit e5210bb

Browse files
authored
Add CI and Zig security audit workflow (#1)
* Add CI build/test and security audit workflow * Make fmt check non-blocking (continue-on-error) --------- Co-authored-by: midasdf <midasdf@users.noreply.github.com>
1 parent 5e33759 commit e5210bb

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
schedule:
8+
- cron: '0 0 * * 1'
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
check:
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Install Zig
20+
run: |
21+
curl -sL "https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz" | tar -xJ
22+
echo "$PWD/zig-x86_64-linux-0.15.2" >> "$GITHUB_PATH"
23+
24+
- name: Format check
25+
continue-on-error: true
26+
run: zig fmt --check src/
27+
28+
- name: Build
29+
run: zig build
30+
31+
- name: Test
32+
run: zig build test
33+
34+
security-audit:
35+
runs-on: ubuntu-24.04
36+
steps:
37+
- uses: actions/checkout@v4
38+
with:
39+
fetch-depth: 0
40+
41+
- name: Zig Security Audit
42+
env:
43+
GH_EVENT: ${{ github.event_name }}
44+
GH_BASE_REF: ${{ github.event.pull_request.base.ref }}
45+
run: |
46+
echo "## Zig Security Audit" >> "$GITHUB_STEP_SUMMARY"
47+
echo "" >> "$GITHUB_STEP_SUMMARY"
48+
echo "| Pattern | Count | Level |" >> "$GITHUB_STEP_SUMMARY"
49+
echo "|---------|-------|-------|" >> "$GITHUB_STEP_SUMMARY"
50+
51+
total=0
52+
53+
audit() {
54+
local pattern="$1" level="$2" label="$3"
55+
local count
56+
count=$(grep -rn --include='*.zig' -e "$pattern" src/ 2>/dev/null | wc -l)
57+
if [ "$count" -gt 0 ]; then
58+
echo "| \`$label\` | $count | $level |" >> "$GITHUB_STEP_SUMMARY"
59+
total=$((total + count))
60+
fi
61+
if [ "$GH_EVENT" = "pull_request" ] && [ -n "$GH_BASE_REF" ]; then
62+
git diff --name-only "origin/$GH_BASE_REF" -- '*.zig' 2>/dev/null | while read -r file; do
63+
[ -f "$file" ] || continue
64+
grep -n "$pattern" "$file" 2>/dev/null | while IFS=: read -r line content; do
65+
echo "::warning file=$file,line=$line::[$level] $label: $content"
66+
done
67+
done
68+
fi
69+
}
70+
71+
audit '@setRuntimeSafety\(false\)' 'Critical' '@setRuntimeSafety(false)'
72+
audit '@ptrCast' 'Tracked' '@ptrCast'
73+
audit '@ptrFromInt' 'Tracked' '@ptrFromInt'
74+
audit '@intFromPtr' 'Tracked' '@intFromPtr'
75+
audit '@alignCast' 'Tracked' '@alignCast'
76+
audit 'catch unreachable' 'Review' 'catch unreachable'
77+
audit 'orelse unreachable' 'Review' 'orelse unreachable'
78+
audit '@cImport' 'Info' '@cImport'
79+
80+
echo "" >> "$GITHUB_STEP_SUMMARY"
81+
echo "**Total: $total** patterns tracked" >> "$GITHUB_STEP_SUMMARY"
82+
echo "_Not bugs — areas requiring careful review during changes._" >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)