GitHub Actions Integration
pycmdcheck integrates seamlessly with GitHub Actions to provide automated package quality checks with inline annotations directly in your pull requests.
Quick Start
Add pycmdcheck to your CI workflow:
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install pycmdcheck
- name: Run pycmdcheck
run: pycmdcheck check --format github --profile ciGitHub Format Output
The --format github flag produces GitHub Actions workflow commands that create inline annotations in your pull requests.
When pycmdcheck finds issues, they appear directly on the affected files:
- Errors appear as red annotations
- Warnings appear as yellow annotations
- Notes appear as blue annotations
This makes it easy to see exactly where issues are located without digging through log output.
Example Output
::error file=src/mypackage/__init__.py,line=1::ST001: Package missing py.typed marker for type checking support
::warning file=pyproject.toml,line=15::MT003: Missing optional metadata field 'keywords'
::notice file=tests/test_main.py,line=42::TS001: Test coverage below recommended threshold
Using Profiles
pycmdcheck includes built-in profiles optimized for different use cases:
| Profile | Description | Use Case |
|---|---|---|
ci |
Skips slow checks (e.g., vulnerability scans), fails on warnings | Continuous integration pipelines |
release |
Focuses on structure, metadata, release, and security checks | Pre-release validation |
strict |
Runs all checks, fails on any issue including notes | Comprehensive quality gate |
relaxed |
Skips informational checks, fails only on errors | Initial adoption / legacy projects |
CI Profile
Best for pull request checks. Optimized for speed by skipping slow vulnerability scans:
- name: Run pycmdcheck
run: pycmdcheck check --format github --profile ciRelease Profile
Use before publishing a new version. Focuses on release-critical checks:
- name: Run pycmdcheck (release)
run: pycmdcheck check --format github --profile release --error-on warningStrict Profile
For projects that want comprehensive quality enforcement:
- name: Run pycmdcheck (strict)
run: pycmdcheck check --format github --profile strictRelaxed Profile
Good for gradually adopting pycmdcheck in existing projects:
- name: Run pycmdcheck (relaxed)
run: pycmdcheck check --format github --profile relaxedControlling Exit Codes
The --error-on flag controls which severity level causes a non-zero exit code:
| Flag | Behavior |
|---|---|
--error-on error |
Exit non-zero only on errors (default) |
--error-on warning |
Exit non-zero on warnings or errors |
--error-on note |
Exit non-zero on any issue |
# Fail the build on warnings
- name: Run pycmdcheck
run: pycmdcheck check --format github --error-on warningMatrix Testing Multiple Python Versions
Test your package across multiple Python versions:
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
check:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install pycmdcheck
- name: Run pycmdcheck
run: pycmdcheck check --format github --profile ciRelease Workflow
Run comprehensive checks before publishing releases:
name: Release Check
on:
push:
tags: ["v*"]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install pycmdcheck
- name: Run pycmdcheck (release profile)
run: pycmdcheck check --format github --profile release --error-on warningUsing a Reusable Workflow
For more convenience, you can create a reusable workflow in your organization:
# .github/workflows/pycmdcheck.yml
name: pycmdcheck
on:
workflow_call:
inputs:
python-version:
type: string
default: "3.12"
error-on:
type: string
default: "warning"
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- run: pip install pycmdcheck
- run: pycmdcheck check --format github --error-on ${{ inputs.error-on }}Then use it in other workflows:
- name: Run pycmdcheck
uses: ./.github/workflows/pycmdcheck.yml
with:
python-version: "3.12"
error-on: warningSee the pycmdcheck repository for more examples.
Skipping Specific Checks
Skip checks that don’t apply to your project:
- name: Run pycmdcheck
run: pycmdcheck check --format github --skip ST001 --skip DC002Or skip entire groups:
- name: Run pycmdcheck
run: pycmdcheck check --format github --skip-group tests --skip-group docsRunning Only Specific Checks
Focus on specific checks or groups:
# Only run metadata and structure checks
- name: Run pycmdcheck
run: pycmdcheck check --format github --only-group metadata --only-group structureCombining with Other Tools
pycmdcheck works well alongside other quality tools:
jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install pycmdcheck ruff mypy pytest
- name: Lint with ruff
run: ruff check .
- name: Type check with mypy
run: mypy src
- name: Test with pytest
run: pytest
- name: Package check with pycmdcheck
run: pycmdcheck check --format github --profile ciCaching Dependencies
Speed up your workflow by caching pip dependencies:
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install dependencies
run: pip install pycmdcheck
- name: Run pycmdcheck
run: pycmdcheck check --format github --profile ciTroubleshooting
Annotations Not Appearing
Make sure you’re using --format github. Without this flag, pycmdcheck outputs human-readable text instead of workflow commands.
Too Many Annotations
GitHub limits the number of annotations per check run. If you have many issues, consider: 1. Using --error-on error to focus on critical issues first 2. Using profiles to limit which checks run 3. Fixing issues incrementally
Slow Checks
Use the ci profile to skip slow checks like vulnerability scanning:
run: pycmdcheck check --format github --profile ci