A composite GitHub Action that runs prek (a fast pre-commit hook runner) with optional autofix and PR comments.
action.yml- Composite action with all logicworkflow.yml.tmpl- Workflow template for syncing to repos
To adopt this workflow via template-files, add to your .github/template-files/config.yml:
- source: lint/workflow.yml.tmpl
target: .github/workflows/lint.yml
# Optional: additional branch patterns (main is always included)
# branches:
# - '2[0-9].[0-9]+.x' # CalVer release branches
# Optional: Python version for prek hooks
# python_version: '3.12'- Installs and runs prek with your existing
.pre-commit-config.yaml - Captures command output and git diff for PR comments
- Creates/updates sticky PR comments showing lint issues and suggested fixes
- Updates comment to show success when issues are resolved
- Optionally commits and pushes fixes (autofix mode)
- Reacts to trigger comments with 👀 → 🎉/😕
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: conda/actions/lint@mainThe action automatically fails if lint issues are found (unless autofix: true).
on:
pull_request:
issue_comment:
types: [created]
jobs:
lint:
if: >-
github.event_name == 'pull_request'
|| (
github.event_name == 'issue_comment'
&& github.event.issue.pull_request
&& github.event.comment.body == '@conda-bot prek autofix'
)
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: conda/actions/lint@main
with:
autofix: ${{ github.event_name == 'issue_comment' }}
comment-id: ${{ github.event.comment.id }}
pr-number: ${{ github.event.issue.number }}| Input | Description | Required | Default |
|---|---|---|---|
token |
GitHub token for PR comments and pushing | No | ${{ github.token }} |
autofix |
Whether to commit and push fixes | No | 'false' |
comment-id |
Comment ID to react to (for issue_comment triggers) | No | '' |
pr-number |
PR number (defaults to current PR, override for issue_comment triggers) | No | ${{ github.event.pull_request.number }} |
git-user-name |
Git user name for autofix commits | No | conda-bot |
git-user-email |
Git user email for autofix commits | No | 18747875+conda-bot@users.noreply.github.com |
python-version |
Python version for running prek hooks | No | '3.12' |
checkout |
Whether to checkout the repository (set to false if already checked out) | No | 'true' |
working-directory |
Directory to run prek in (defaults to repo root) | No | '.' |
config |
Path to pre-commit config file (defaults to auto-discovery) | No | '' |
comment-anchor |
Unique anchor for sticky comment (customize to avoid conflicts with parallel workflows) | No | 'lint-comment' |
comment-header |
Optional header text to prepend to comments (e.g., to mark test comments) | No | '' |
comment-on-success |
Create success comment even without prior lint failure (useful for testing) | No | 'false' |
| Output | Description |
|---|---|
outcome |
success if no lint issues, failure if issues found |
output |
The prek command output |
diff |
The git diff of suggested fixes (only if outcome is failure) |
To run lint without creating PR comments, omit the pr-number input:
- uses: conda/actions/lint@main
with:
pr-number: '' # No PR commentsThis is useful for:
- Running lint in contexts without a PR (e.g., scheduled runs)
- CI test scenarios where you don't want test comments cluttering PRs
- Conditional commenting based on file changes (see tests.yml for an example)
The action creates a sticky comment (identified by <!-- lint-comment -->) that:
- Shows prek output and git diff on failure
- Shows a note for fork PRs (autofix cannot push to forks)
- Shows a warning if autofix was attempted but push failed
- Updates to "✅ Lint issues fixed" when resolved
- Includes link to workflow run for details
By default, GITHUB_TOKEN cannot push to fork PRs. The action detects this and shows a helpful message explaining how to fix locally.
To enable autofix for fork PRs, use a GitHub App token instead (untested):
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: conda/actions/lint@main
with:
token: ${{ steps.app-token.outputs.token }}
autofix: true
comment-id: ${{ github.event.comment.id }}
pr-number: ${{ github.event.issue.number }}Requirements:
- GitHub App with
contents: writeandpull-requests: writepermissions - PR author must enable "Allow edits from maintainers"