A GitHub Action that runs code quality checks on both Pull Requests and Push events:
- Line width check: Ensures files adhere to maximum line width rules
- Rust import multi-line: Prevents multi-line use statements in Rust code
Add this action to your GitHub workflow:
name: Code Quality
on:
pull_request:
branches: [ main, master ]
push:
branches: [ main, master ]
jobs:
quality-checks:
runs-on: ubuntu-latest
name: Run code quality checks
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Code Quality Checks
uses: your-username/pr-code-quality-checks@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Optional: Override default line width rules
# line_width_rules: 'CHANGELOG.md:80;*.md:110;*.rs:110;*.toml:110;DEFAULT=110'| Input | Description | Required | Default |
|---|---|---|---|
github_token |
GitHub token for creating check runs | Yes | ${{ github.token }} |
line_width_rules |
Rules for max line width in format: file_pattern:width;file_pattern:width |
No | CHANGELOG.md:80;*.md:110;*.rs:110;*.toml:110;DEFAULT=110 |
check_diff |
If true, only checks files and lines changed in the current event (PR or push) | No | true |
rust_import_ignore |
Semicolon-separated glob patterns for Rust files to skip the multi-line import check | No | '' |
| Output | Description |
|---|---|
line_width_result |
Result of line width check (success or failure) |
rust_import_result |
Result of Rust import style check (success or failure) |
The line_width_rules input accepts a semicolon-separated list of rules in the format:
file_pattern:max_width;file_pattern:max_width;DEFAULT=default_width
For example:
CHANGELOG.md:80- CHANGELOG.md files have a max width of 80 characters*.md:110- All markdown files have a max width of 110 charactersDEFAULT=110- All other files have a max width of 110 characters
This check enforces the following style for Rust imports:
use crate::rtp_::{
Bitrate, Descriptions,
Extension
};use crate::rtp_::Bitrate, Descriptions;
use crate::rtp_::Extension;To skip checking generated or third-party modules, configure the rust_import_ignore input with semicolon-separated patterns (supports * and **) that match repository-relative paths, for example: rust_import_ignore: 'src/generated/**/*.rs;vendor.rs'.
To run the tests locally:
npm install
npm testFor continuous test running during development:
npm run test:watchMIT