Add GitHub Actions workflow for linting with Ruff #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Lint with Ruff | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Install uv | |
uses: astral-sh/setup-uv@v4 | |
- name: Set up Python | |
run: uv python install | |
- name: Install the project | |
run: uv sync --all-extras --dev | |
- name: Run Ruff | |
id: run_ruff | |
run: | | |
uv run ruff check . > ruff_output.txt || true | |
- name: Post PR comment | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const { data: comments } = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.pull_request.number, | |
}); | |
const botComment = comments.find(comment => comment.user.login === 'github-actions[bot]'); | |
const body = `## Ruff\n\`\`\`\n${fs.readFileSync('ruff_output.txt', 'utf8')}\n\`\`\``; | |
if (botComment) { | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: botComment.id, | |
body, | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.pull_request.number, | |
body, | |
}); | |
} |