Fix CI lint gate #21
This file contains hidden or 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: CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install ruff | |
| run: pip install ruff | |
| - name: Determine lint targets | |
| id: lint_targets | |
| shell: bash | |
| run: | | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| base_sha="${{ github.event.pull_request.base.sha }}" | |
| else | |
| base_sha="${{ github.event.before }}" | |
| fi | |
| if [[ -z "$base_sha" || "$base_sha" =~ ^0+$ ]]; then | |
| git ls-files | grep -E '^(src|tests)/.*\.py$' > lint_targets.txt || true | |
| else | |
| git diff --name-only "$base_sha" "${{ github.sha }}" | grep -E '^(src|tests)/.*\.py$' > lint_targets.txt || true | |
| fi | |
| count=$(wc -l < lint_targets.txt | tr -d ' ') | |
| echo "count=$count" >> "$GITHUB_OUTPUT" | |
| - name: Run ruff | |
| if: steps.lint_targets.outputs.count != '0' | |
| run: xargs -a lint_targets.txt python -m ruff check --select E,F,W --ignore E501,E402 | |
| - name: Skip ruff | |
| if: steps.lint_targets.outputs.count == '0' | |
| run: echo "No changed Python files under src/ or tests/." | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: pip install -r requirements.txt | |
| - name: Run tests | |
| run: python -m pytest tests/ -v --tb=short | |
| safety: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install safety | |
| run: pip install safety | |
| - name: Check dependencies | |
| run: safety check -r requirements.txt || true |