Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions .github/workflows/unused-imports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: CI / Unused Imports Check

on:
pull_request:
branches: [main]
workflow_dispatch:

jobs:
check-unused-imports:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write

steps:
- name: Checkout PR code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.1

- name: Build zigimports
run: |
git clone --depth 1 https://github.com/tusharsadhwani/zigimports.git /tmp/zigimports
cd /tmp/zigimports
zig build --release=safe
# Binary is named zigimports-<arch>-<os>, find and symlink it
ln -s /tmp/zigimports/zig-out/bin/zigimports-* /tmp/zigimports/zig-out/bin/zigimports

- name: Get changed Zig files
id: changed-files
run: |
FILES=$(git diff --name-only --diff-filter=d ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep '\.zig$' || true)
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Check for unused imports
id: check
run: |
RESULTS=""
echo "${{ steps.changed-files.outputs.files }}" | while read file; do
if [ -n "$file" ] && [ -f "$file" ]; then
/tmp/zigimports/zig-out/bin/zigimports "$file" 2>&1 || true
fi
done | tee unused_imports.txt

# Set output for later steps
if grep -q "is unused" unused_imports.txt 2>/dev/null; then
echo "has_issues=true" >> $GITHUB_OUTPUT
else
echo "has_issues=false" >> $GITHUB_OUTPUT
fi

- name: Post PR comment
if: steps.check.outputs.has_issues == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');

const content = fs.readFileSync('unused_imports.txt', 'utf8').trim();
const lines = content.split('\n').filter(l => l.includes('is unused'));

if (lines.length === 0) return;

// Check for existing comment and update it
const marker = '<!-- unused-imports-check -->';
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
}
);

const existing = comments.find(c =>
c.user.login === 'github-actions[bot]' &&
c.body.includes(marker)
);

let body = '## ⚠️ Unused Imports Found\n\n';
body += '```\n' + lines.join('\n') + '\n```\n\n';
body += 'Run `zigimports --fix <file>` locally to automatically remove unused imports.\n\n';
body += marker;

if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}

- name: Remove comment if no issues
if: steps.check.outputs.has_issues == 'false'
uses: actions/github-script@v7
with:
script: |
const marker = '<!-- unused-imports-check -->';
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
}
);

const existing = comments.find(c =>
c.user.login === 'github-actions[bot]' &&
c.body.includes(marker)
);

if (existing) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id
});
}
1 change: 0 additions & 1 deletion tools/sorcerer/src/RegzWindow.zig
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ const Allocator = std.mem.Allocator;
const regz = @import("regz");
const VirtualFilesystem = regz.VirtualFilesystem;
const RegisterSchemaUsage = @import("RegisterSchemaUsage");
const diffz = @import("diffz");

const dvui = @import("dvui");

Expand Down
2 changes: 0 additions & 2 deletions tools/sorcerer/src/main.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const std = @import("std");
const builtin = @import("builtin");
const dvui = @import("dvui");
const serial = @import("serial");
const regz = @import("regz");
const schemas = @import("schemas");
const RegisterSchemaUsage = @import("RegisterSchemaUsage");
Expand Down
Loading