Skip to content

Add CI and Zig security audit workflow#6

Merged
midasdf merged 2 commits intomainfrom
ci/add-security-workflow
Apr 2, 2026
Merged

Add CI and Zig security audit workflow#6
midasdf merged 2 commits intomainfrom
ci/add-security-workflow

Conversation

@midasdf
Copy link
Copy Markdown
Owner

@midasdf midasdf commented Apr 2, 2026

User description

Summary

  • GitHub Actions CI: build, test, format check
  • Zig security audit: tracks unsafe/low-level patterns
  • Runs on push, PR, and weekly schedule (Monday 00:00 UTC)

check job

  • zig fmt --check src/ — format verification
  • zig build — compilation check
  • zig build test — test execution (where available)

security-audit job

  • Scans: @ptrCast, @ptrFromInt, @intFromPtr, @alignCast, catch unreachable, orelse unreachable, @setRuntimeSafety(false), @cImport
  • Reports pattern counts in Actions job summary
  • Adds warning annotations on changed files in PRs
  • Informational only — does not block CI

CodeAnt-AI Description

Add CI checks and a Zig security audit for every change

What Changed

  • Runs format, build, and test checks on pull requests, pushes to main, and a weekly schedule
  • Shows formatting problems without failing the whole CI run, while build and test failures still block changes
  • Adds a security audit that summarizes risky Zig patterns and warns on matching code in pull requests

Impact

✅ Earlier build and test failures on pull requests
✅ Fewer broken changes reaching main
✅ Clearer review of risky Zig code

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • Chores
    • GitHub Actions CI ワークフローを追加しました。毎回のコミットおよびプルリクエスト、週間スケジュールで自動実行される品質チェック(フォーマット検証、ビルド、テスト)とセキュリティ監査が実行されるようになりました。

@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Apr 2, 2026

CodeAnt AI is reviewing your PR.

@gemini-code-assist
Copy link
Copy Markdown

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

@codeant-ai codeant-ai Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Apr 2, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Apr 2, 2026

CodeAnt AI finished reviewing your PR.

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 2, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes. Give us feedback

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

.github/workflows/ci.ymlに新しいGitHub Actionsワークフロー「CI」を追加。mainブランチへのプッシュ、プルリクエスト、および週次スケジュールで実行される。Zigのビルド・テスト実行とセキュリティ監査ジョブを含む。

Changes

Cohort / File(s) Summary
CI/CDワークフロー設定
.github/workflows/ci.yml
新規ワークフローを追加。Ubuntu 24.04上でZig 0.15.2をセットアップし、フォーマットチェック、ビルド、テスト実行、およびセキュリティパターンスキャンを実施。PRの場合は変更ファイルに対して警告を出力。

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding a CI workflow with Zig security audit capabilities. It is concise, specific, and clearly reflects the primary purpose of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/add-security-workflow

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Apr 2, 2026

CodeAnt AI is running Incremental review

@deepsource-io
Copy link
Copy Markdown

deepsource-io Bot commented Apr 2, 2026

DeepSource Code Review

We reviewed changes in 42be1fa...00f162c on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Secrets Apr 2, 2026 8:13p.m. Review ↗

@codeant-ai codeant-ai Bot added size:M This PR changes 30-99 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Apr 2, 2026
@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Apr 2, 2026

CodeAnt AI Incremental review completed.

Copy link
Copy Markdown

@codacy-production codacy-production Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

The pull request successfully implements a Zig CI pipeline and security audit workflow, and Codacy analysis indicates the project remains up to standards. However, two significant issues should be addressed before merging: the security audit script generates excessive noise by flagging existing code not modified in the PR, and the formatting check is configured to 'continue-on-error', which prevents the CI from enforcing style consistency. Additionally, the audit logic contains a scope inconsistency between the summary counts (src/ directory) and file annotations (all .zig files).

About this PR

  • There is a scope inconsistency in the audit logic: the summary count is restricted to the 'src/' directory, while PR annotations scan all '.zig' files in the repository. This may result in discrepancies between the total reported count and the number of visible annotations.

Test suggestions

  • Verify workflow triggers correctly on push, PR, and the specified cron schedule.
  • Verify 'check' job executes format, build, and test steps in sequence.
  • Verify 'security-audit' job correctly identifies and counts the 8 specified Zig patterns in the src/ directory.
  • Verify PR annotations are generated for changed files when running in a pull_request context.
  • Verify the CI pipeline succeeds even if 'zig fmt' finds issues.

🗒️ Improve review quality by adding custom instructions

Comment thread .github/workflows/ci.yml
Comment on lines +67 to +72
git diff --name-only "origin/$GH_BASE_REF" -- '*.zig' 2>/dev/null | while read -r file; do
[ -f "$file" ] || continue
grep -n "$pattern" "$file" 2>/dev/null | while IFS=: read -r line content; do
echo "::warning file=$file,line=$line::[$level] $label: $content"
done
done
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

The security audit logic currently generates warnings for all occurrences of patterns in a modified file, rather than just the new lines introduced in the PR. This creates 'warning noise' for pre-existing code. Update the script to only emit annotations for lines added or modified in the current diff (e.g., using git diff -U0).

Comment thread .github/workflows/ci.yml
Comment on lines +19 to +22
- name: Install Zig
run: |
curl -sL "https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz" | tar -xJ
echo "$PWD/zig-x86_64-linux-0.15.2" >> "$GITHUB_PATH"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

Suggestion: Manual installation of Zig is brittle and lacks version/checksum management. Consider using the community-standard goto-bus-stop/setup-zig action to improve workflow reliability and maintainability.

Comment thread .github/workflows/ci.yml
sudo apt-get install -y libxcb1-dev libxcb-randr0-dev

- name: Format check
continue-on-error: true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

Suggestion: The format check should fail the build if code is not properly formatted. Using continue-on-error: true allows style violations to merge. Consider setting this to false or removing the attribute to enforce project standards.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/ci.yml:
- Around line 21-22: Replace the unsafe curl|tar pipeline with a verified
download-and-verify flow: first download the Zig tar.xz and the corresponding
index.json and/or .minisig for version 0.15.2, then either (preferred) verify
the .minisig using minisign and the Zig public key, or parse index.json to
extract the SHA256 checksum and compare it against sha256sum of the downloaded
archive; only after successful verification, extract the archive and append its
path to GITHUB_PATH. Ensure the new steps occur in the CI script surrounding the
existing curl/tar lines (the lines that download
"zig-x86_64-linux-0.15.2.tar.xz" and echo the path) so the archive is never
extracted unless signature/checksum verification passes.
- Line 70: The GitHub Actions ::warning command must not receive raw grep output
in the content variable because special characters (% , newline, carriage
return) break command parsing; update the echo on the line using the content
variable so that before embedding you escape % -> %25, newline -> %0A and
carriage return -> %0D (e.g., add an escaping step or function that transforms
the content variable), then use that escaped variable in the echo "::warning
file=$file,line=$line::[$level] $label: $escaped_content" to ensure safe,
parseable workflow commands.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1f7ca8e8-cda5-4b76-8f70-ddacb41f6ec3

📥 Commits

Reviewing files that changed from the base of the PR and between 42be1fa and 00f162c.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml

Comment thread .github/workflows/ci.yml
Comment on lines +21 to +22
curl -sL "https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz" | tar -xJ
echo "$PWD/zig-x86_64-linux-0.15.2" >> "$GITHUB_PATH"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Zig programming language download checksum verification sha256

💡 Result:

To download and verify Zig programming language releases using SHA256 checksums: 1. Visit the official download page: https://ziglang.org/download/ 2. Download the appropriate tarball or zip for your platform (e.g., zig-x86_64-linux-0.15.2.tar.xz) and its corresponding .minisig file. 3. SHA256 checksums are provided in the JSON version of the download page at https://ziglang.org/download/index.json. Fetch this JSON to get the 'shasum' field (SHA256 hex digest) for your file, along with expected size. 4. Verify the SHA256 checksum of the downloaded file matches the one from index.json using shasum -a 256 filename. 5. Install minisign and verify the signature: minisign -V -m filename.tar.xz -x filename.tar.xz.minisig -P 'RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U'. The signature includes a trusted comment with the exact filename to prevent downgrade attacks. Primary verification is via minisign signatures using the public key shown on the download page. SHA256 checksums from index.json provide an additional integrity check, especially useful for automation and package managers. For mirrors, perform both SHA256 (from index.json) and minisign verification. Latest stable as of 2026-04-02: 0.15.2 (2025-10-11). Master dev build available as zig-0.16.0-dev-XXXX+commit.tar.xz.

Citations:


🌐 Web query:

Zig 0.15.2 release download files

💡 Result:

The official download page for Zig 0.15.2 is https://ziglang.org/download/#release-0.15.2, which lists the following binary download files (all signed with minisign using public key RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U): Source Code: - zig-0.15.2.tar.xz (20MiB) - zig-bootstrap-0.15.2.tar.xz (50MiB) Windows: - zig-x86_64-windows-0.15.2.zip (88MiB) - zig-aarch64-windows-0.15.2.zip (84MiB) - zig-x86-windows-0.15.2.zip (90MiB) macOS: - zig-x86_64-macos-0.15.2.tar.xz (53MiB) - zig-aarch64-macos-0.15.2.tar.xz (48MiB) Linux and other platform binaries (e.g., x86_64-linux) are also available on the page and mirrors like https://gr.ht/zig/. Direct links follow the pattern https://ziglang.org/download/0.15.2/[filename] (e.g., https://ziglang.org/download/0.15.2/zig-x86_64-windows-0.15.2.zip). Released on 2025-10-11.

Citations:


Zig バイナリ取得時に完全性検証を追加してください

Line 21-22 の curl | tar はチェックサム/署名検証がなく、供給元改ざん時のリスクがあります。CI のツールチェーン導入は完全性検証が必須です。

ただし、提案されている修正案を修正してください。Zig は sha256sum.txt ファイルでなく、index.json から SHA256 チェックサムを提供します。また、minisign 署名 .minisig ファイルによる検証が推奨されています。

以下のいずれかの方法で対応してください:

  1. minisign による署名検証(推奨).minisig ファイルをダウンロードし、公開鍵で署名を検証
  2. index.json から SHA256 チェックサムを取得:JSON パースして得られたハッシュ値と照合
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/ci.yml around lines 21 - 22, Replace the unsafe curl|tar
pipeline with a verified download-and-verify flow: first download the Zig tar.xz
and the corresponding index.json and/or .minisig for version 0.15.2, then either
(preferred) verify the .minisig using minisign and the Zig public key, or parse
index.json to extract the SHA256 checksum and compare it against sha256sum of
the downloaded archive; only after successful verification, extract the archive
and append its path to GITHUB_PATH. Ensure the new steps occur in the CI script
surrounding the existing curl/tar lines (the lines that download
"zig-x86_64-linux-0.15.2.tar.xz" and echo the path) so the archive is never
extracted unless signature/checksum verification passes.

Comment thread .github/workflows/ci.yml
git diff --name-only "origin/$GH_BASE_REF" -- '*.zig' 2>/dev/null | while read -r file; do
[ -f "$file" ] || continue
grep -n "$pattern" "$file" 2>/dev/null | while IFS=: read -r line content; do
echo "::warning file=$file,line=$line::[$level] $label: $content"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's verify the file exists and examine the context
cat -n .github/workflows/ci.yml | sed -n '60,80p'

Repository: midasdf/zephwm

Length of output: 1253


🌐 Web query:

GitHub Actions workflow command escaping special characters %25 %0A %0D

💡 Result:

In GitHub Actions workflow commands, special characters like % (percent), \n (newline), and \r (carriage return) require escaping when using the deprecated ::set-output syntax to handle multiline strings in outputs. To escape: - Replace '%' with '%25' - Replace '\n' with '%0A' - Replace '\r' with '%0D' Example in bash: text="${text//'%'/'%25'}" text="${text//$'\n'/'%0A'}" text="${text//$'\r'/'%0D'}" echo "::set-output name=myoutput::$text" This was a common workaround for the old stdout-based workflow commands like ::set-output and ::set-env, which treated newlines and % as delimiters, truncating multiline content otherwise. Note: ::set-output and ::set-env are deprecated since 2022 due to security issues. Use environment files instead: - For outputs: echo "name=value" >> $GITHUB_OUTPUT (single-line) or use delimiter syntax for multiline: echo "name<<DELIM" >> $GITHUB_OUTPUT; echo "multiline content" >> $GITHUB_OUTPUT; echo "DELIM" >> $GITHUB_OUTPUT - No manual escaping needed with environment files; newlines are preserved naturally with delimiters. Official docs confirm multiline support via delimiters in GITHUB_OUTPUT without % escaping.

Citations:


::warning コマンドに特殊文字のエスケープが必要です

Line 70 の contentgrep の出力から直接取得された生文字列であり、これを GitHub Actions のワークフロー コマンドに埋め込む際は特殊文字をエスケープする必要があります。%、改行 (\n)、キャリッジリターン (\r) は GitHub Actions のワークフロー コマンド解析で特別な意味を持つため、これらが含まれるとコマンド解釈が正しく機能しません。

修正案(GitHub Actions コマンド文字列エスケープ)
-                  echo "::warning file=$file,line=$line::[$level] $label: $content"
+                  esc="${content//'%'/'%25'}"
+                  esc="${esc//$'\n'/'%0A'}"
+                  esc="${esc//$'\r'/'%0D'}"
+                  echo "::warning file=$file,line=$line::[$level] $label: $esc"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/ci.yml at line 70, The GitHub Actions ::warning command
must not receive raw grep output in the content variable because special
characters (% , newline, carriage return) break command parsing; update the echo
on the line using the content variable so that before embedding you escape % ->
%25, newline -> %0A and carriage return -> %0D (e.g., add an escaping step or
function that transforms the content variable), then use that escaped variable
in the echo "::warning file=$file,line=$line::[$level] $label: $escaped_content"
to ensure safe, parseable workflow commands.

@midasdf midasdf merged commit a40dd08 into main Apr 2, 2026
7 checks passed
@midasdf midasdf deleted the ci/add-security-workflow branch April 2, 2026 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant