Add pre-commit configuration file compatible with Trunk.io#13
Add pre-commit configuration file compatible with Trunk.io#13
Conversation
|
Merging to
|
|
Running Code Quality on PRs by uploading data to Trunk will soon be removed. You can still run checks on your PRs using trunk-action - see the migration guide for more information. |
Co-authored-by: brendancsmith <5986636+brendancsmith@users.noreply.github.com>
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: "3.12" | ||
| - uses: pre-commit/action@v3.0.1 |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the problem, you should add a permissions block that restricts the GITHUB_TOKEN permissions to the minimum required. For most pre-commit/CHECK-type jobs that only need to read repository code, setting permissions: contents: read suffices, unless the workflow specifically needs to write to pull requests or issues (which it does not appear to from the provided actions). The recommended approach is to add this permissions block at the workflow level (just after the name: and before on:), so it applies to all jobs unless otherwise specified. You should insert:
permissions:
contents: readat line 3, pushing the on: and subsequent lines down. No import or variable definition is necessary; just a change to the YAML structure.
| @@ -1,5 +1,7 @@ | ||
| # Workflow for running pre-commit checks | ||
| name: Pre-commit | ||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| pull_request: |
Overview
This PR adds a comprehensive
.pre-commit-config.yamlfile that integrates seamlessly with the existing Trunk.io setup in the repository. Pre-commit hooks provide automated code quality checks before commits, helping maintain consistent code standards across contributions.What's Included
1. Pre-commit Configuration (
.pre-commit-config.yaml)A fully configured pre-commit setup with 6 repositories and 16 hooks:
Python Tools:
Code Formatting:
.trunk/configs/.yamllint.yaml.trunk/configs/.markdownlint.yamlStandard Checks (v5.0.0):
2. GitHub Actions Workflow (
.github/workflows/pre-commit.yml)Automated pre-commit checks run on:
This ensures code quality standards are maintained in CI/CD pipelines.
3. Documentation Updates
Added a comprehensive "Development Setup" section to
CONTRIBUTING.mdwith:Trunk.io Compatibility
This configuration is designed to work alongside Trunk.io, not replace it:
✅ Hook versions match those in
.trunk/trunk.yaml✅ Reuses existing Trunk configuration files
✅ Properly excludes test cassettes from linting
✅ TruffleHog and Commitlint commented out (handled by Trunk.io actions)
✅ Compatible with existing Trunk.io pre-commit and pre-push actions
Usage
Contributors can enable pre-commit hooks with:
Hooks will automatically run on every commit. Manual runs are also supported:
Benefits
Closes #[issue_number]
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.