|
| 1 | +# QuantEcon Style Guide Checker |
| 2 | + |
| 3 | +An AI-enabled GitHub Action that checks lecture compliance with the QuantEcon Style Guide and provides intelligent suggestions for improvements. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Dual Operation Modes**: PR-triggered checks and scheduled complete reviews |
| 8 | +- **Intelligent Analysis**: Uses rule-based checking with confidence levels |
| 9 | +- **Automated Fixes**: High confidence suggestions can be auto-committed |
| 10 | +- **Comprehensive Reporting**: Detailed tables with suggestions organized by confidence |
| 11 | +- **Flexible Configuration**: Customizable paths, exclusions, and thresholds |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +### PR Mode (Comment Trigger) |
| 16 | + |
| 17 | +Add this to your workflow to trigger style checks when mentioned in PR comments: |
| 18 | + |
| 19 | +```yaml |
| 20 | +name: Style Check on PR Comment |
| 21 | +on: |
| 22 | + issue_comment: |
| 23 | + types: [created] |
| 24 | + |
| 25 | +jobs: |
| 26 | + style-check: |
| 27 | + if: github.event.issue.pull_request && contains(github.event.comment.body, '@qe-style-check') |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + - name: Check style guide compliance |
| 32 | + uses: QuantEcon/meta/.github/actions/qe-style-check@main |
| 33 | + with: |
| 34 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + lectures: 'lectures' |
| 36 | + mode: 'pr' |
| 37 | + confidence-threshold: 'high' |
| 38 | +``` |
| 39 | +
|
| 40 | +### Scheduled Mode |
| 41 | +
|
| 42 | +For comprehensive reviews of all lectures: |
| 43 | +
|
| 44 | +```yaml |
| 45 | +name: Weekly Style Check |
| 46 | +on: |
| 47 | + schedule: |
| 48 | + - cron: '0 9 * * 1' # Every Monday at 9 AM UTC |
| 49 | + workflow_dispatch: |
| 50 | + |
| 51 | +jobs: |
| 52 | + style-check: |
| 53 | + runs-on: ubuntu-latest |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
| 56 | + - name: Complete style guide review |
| 57 | + uses: QuantEcon/meta/.github/actions/qe-style-check@main |
| 58 | + with: |
| 59 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + lectures: 'lectures' |
| 61 | + mode: 'scheduled' |
| 62 | + create-individual-prs: 'true' |
| 63 | +``` |
| 64 | +
|
| 65 | +## Inputs |
| 66 | +
|
| 67 | +| Input | Description | Default | Required | |
| 68 | +|-------|-------------|---------|----------| |
| 69 | +| `style-guide` | Path or URL to the QuantEcon style guide document | `.github/copilot-qe-style-guide.md` | No | |
| 70 | +| `lectures` | Path to directory containing lecture documents (Myst Markdown .md files) | `lectures` | No | |
| 71 | +| `exclude-files` | Comma-separated list of file patterns to exclude (supports regex) | `` | No | |
| 72 | +| `mode` | Operation mode: "pr" for pull request mode, "scheduled" for complete review | `pr` | No | |
| 73 | +| `confidence-threshold` | Minimum confidence level for auto-commit (high, medium, low) | `high` | No | |
| 74 | +| `create-individual-prs` | Create individual PRs per lecture in scheduled mode | `false` | No | |
| 75 | +| `github-token` | GitHub token for API access | | Yes | |
| 76 | + |
| 77 | +## Outputs |
| 78 | + |
| 79 | +| Output | Description | |
| 80 | +|--------|-------------| |
| 81 | +| `suggestions-found` | Whether style suggestions were found (true/false) | |
| 82 | +| `high-confidence-count` | Number of high confidence suggestions | |
| 83 | +| `medium-confidence-count` | Number of medium confidence suggestions | |
| 84 | +| `low-confidence-count` | Number of low confidence suggestions | |
| 85 | +| `files-processed` | Number of files processed | |
| 86 | +| `summary-report` | Summary report of suggestions | |
| 87 | +| `detailed-report` | Detailed report with suggestions table | |
| 88 | + |
| 89 | +## Style Rules Checked |
| 90 | + |
| 91 | +The action checks compliance with the QuantEcon Style Guide including: |
| 92 | + |
| 93 | +### Writing Conventions |
| 94 | +- **R001-R005**: General writing principles, sentence structure, capitalization |
| 95 | +- One sentence paragraphs |
| 96 | +- Proper heading capitalization |
| 97 | +- Clear and concise language |
| 98 | + |
| 99 | +### Code Style |
| 100 | +- **R006-R015**: Python code formatting, variable naming, performance patterns |
| 101 | +- Unicode Greek letters (α, β, γ, etc.) |
| 102 | +- PEP8 compliance |
| 103 | +- Modern timing patterns with `qe.Timer()` |
| 104 | + |
| 105 | +### Mathematical Notation |
| 106 | +- **R016-R021**: LaTeX formatting, equation numbering, symbol usage |
| 107 | +- Proper transpose notation (`\top`) |
| 108 | +- Standard matrix/vector conventions |
| 109 | +- Built-in equation numbering |
| 110 | + |
| 111 | +### Figure Guidelines |
| 112 | +- **R022-R029**: Matplotlib best practices, captions, sizing |
| 113 | +- No embedded titles in plots |
| 114 | +- Proper line width settings |
| 115 | +- Lowercase axis labels |
| 116 | + |
| 117 | +## Confidence Levels |
| 118 | + |
| 119 | +- **High Confidence**: Clear rule violations that can be automatically fixed (e.g., Greek letter usage, transpose notation) |
| 120 | +- **Medium Confidence**: Style improvements that likely need adjustment (e.g., paragraph structure, timing patterns) |
| 121 | +- **Low Confidence**: Suggestions that may need human review (e.g., content organization, complex style choices) |
| 122 | + |
| 123 | +## Examples |
| 124 | + |
| 125 | +### Basic PR Check |
| 126 | +```yaml |
| 127 | +- name: Style Guide Check |
| 128 | + uses: QuantEcon/meta/.github/actions/qe-style-check@main |
| 129 | + with: |
| 130 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 131 | + lectures: 'source/lectures' |
| 132 | + exclude-files: 'intro.md,references.md' |
| 133 | +``` |
| 134 | + |
| 135 | +### Scheduled Review with Individual PRs |
| 136 | +```yaml |
| 137 | +- name: Weekly Style Review |
| 138 | + uses: QuantEcon/meta/.github/actions/qe-style-check@main |
| 139 | + with: |
| 140 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 141 | + mode: 'scheduled' |
| 142 | + create-individual-prs: 'true' |
| 143 | + confidence-threshold: 'medium' |
| 144 | +``` |
| 145 | + |
| 146 | +### Custom Style Guide |
| 147 | +```yaml |
| 148 | +- name: Style Check with Custom Guide |
| 149 | + uses: QuantEcon/meta/.github/actions/qe-style-check@main |
| 150 | + with: |
| 151 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 152 | + style-guide: 'https://raw.githubusercontent.com/MyOrg/style/main/guide.md' |
| 153 | + lectures: 'content' |
| 154 | +``` |
| 155 | + |
| 156 | +## Integration with Existing Workflows |
| 157 | + |
| 158 | +This action integrates well with: |
| 159 | +- **Documentation builds**: Run after successful builds to check style |
| 160 | +- **PR workflows**: Automatic style validation on pull requests |
| 161 | +- **Release workflows**: Ensure style compliance before releases |
| 162 | +- **Content reviews**: Regular maintenance of lecture quality |
| 163 | + |
| 164 | +## Troubleshooting |
| 165 | + |
| 166 | +### No Files Found |
| 167 | +- Verify the `lectures` path exists and contains `.md` files |
| 168 | +- Check `exclude-files` patterns aren't too broad |
| 169 | +- Ensure the repository structure matches the configured paths |
| 170 | + |
| 171 | +### Permission Issues |
| 172 | +- Verify `github-token` has appropriate permissions |
| 173 | +- For PR creation, ensure token has `contents: write` and `pull-requests: write` |
| 174 | +- Check repository settings allow action to create PRs |
| 175 | + |
| 176 | +### Style Guide Loading |
| 177 | +- If using a URL, ensure it's publicly accessible |
| 178 | +- For local files, verify the path is relative to repository root |
| 179 | +- Check that the style guide follows the expected markdown format |
| 180 | + |
| 181 | +## Contributing |
| 182 | + |
| 183 | +To extend or modify the style checking rules: |
| 184 | + |
| 185 | +1. Update the rule definitions in `style_checker.py` |
| 186 | +2. Add corresponding tests in the test suite |
| 187 | +3. Update documentation with new rule descriptions |
| 188 | +4. Ensure confidence levels are appropriately assigned |
| 189 | + |
| 190 | +See the [contribution guidelines](../../../CONTRIBUTING.md) for more details. |
0 commit comments