A GitHub Action that calculates lines changed in a PR, excluding files that match configurable glob patterns (e.g. test files, migration snapshots). It posts a comment on the PR with the results and automatically updates it when new commits are pushed.
name: Lines Changed
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
lines-changed:
runs-on: ubuntu-latest
steps:
- uses: your-username/lines-changed-check@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
exclude-patterns: |
**/*.test.ts
**/*.test.tsx
**/*.spec.ts
**/*.spec.tsx
**/__tests__/**
**/migrations/**
**/*snapshot*| Input | Description | Required | Default |
|---|---|---|---|
github-token |
GitHub token for API access | Yes | ${{ github.token }} |
exclude-patterns |
Newline-separated glob patterns for files to exclude | No | "" |
post-comment |
Whether to post/update a PR comment | No | "true" |
comment-tag |
HTML tag used to identify the comment for upserts | No | "lines-changed-check" |
| Output | Description |
|---|---|
total-additions |
Lines added (excluding matched files) |
total-deletions |
Lines deleted (excluding matched files) |
total-changes |
Total lines changed (additions + deletions) |
included-file-count |
Number of files counted |
excluded-file-count |
Number of files excluded |
- Fetches all files changed in the PR via the GitHub API
- Matches each file path against the configured exclusion glob patterns using minimatch
- Sums up additions and deletions for non-excluded files
- Posts (or updates) a PR comment with a summary table
- Re-runs automatically on
synchronizeevents (new pushes to the branch)
bun install
bun test
bunx @vercel/ncc build src/index.ts --out dist --minifyThe dist/ directory is committed to the repo since GitHub Actions require the built output.