|
| 1 | +--- |
| 2 | +## Lint code with ruff |
| 3 | +name: Code Quality Check |
| 4 | + |
| 5 | +on: |
| 6 | + ## Make this an on-demand Action |
| 7 | + workflow_dispatch: |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + types: |
| 12 | + - opened |
| 13 | + - reopened |
| 14 | + - synchronize |
| 15 | + ## Run only when changes detected in specified paths |
| 16 | + # paths: |
| 17 | + ## Changes in a src/ directory |
| 18 | + # - "src/**" |
| 19 | + ## Changes in a sandbox/ directory |
| 20 | + ## Any Python file in the root directory (non-recursive) |
| 21 | + # - "./*.py" |
| 22 | + ## Ignore changes in specified paths, don't trigger pipeline |
| 23 | + paths-ignore: |
| 24 | + ## Ignore changes in a tests/ directory |
| 25 | + - "tests/*" |
| 26 | + ## Ignore changes to any Jupyter notebooks |
| 27 | + - "*.ipynb" |
| 28 | + ## Ignore changes in a docs/ directory |
| 29 | + - "docs/*" |
| 30 | + |
| 31 | +jobs: |
| 32 | + lint: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + |
| 35 | + steps: |
| 36 | + ## Checkout repository |
| 37 | + - name: Check out code |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + ref: ${{ github.event.pull_request.head.ref }} |
| 41 | + |
| 42 | + ## Install Python in container |
| 43 | + - name: Set up Python |
| 44 | + uses: actions/setup-python@v5 |
| 45 | + with: |
| 46 | + python-version: "3.12" |
| 47 | + |
| 48 | + ## Install uv in container |
| 49 | + - name: Install uv |
| 50 | + uses: astral-sh/setup-uv@v5 |
| 51 | + with: |
| 52 | + version: "latest" |
| 53 | + |
| 54 | + ## Setup venv, install dependencies |
| 55 | + - name: Create virtual environment and install dependencies |
| 56 | + run: | |
| 57 | + uv venv |
| 58 | + uv pip install ruff |
| 59 | +
|
| 60 | + ## Check with ruff |
| 61 | + - name: Run Ruff checks & fix errors |
| 62 | + ## Note: paths must exist or ruff will throw an error. Remove any directories you do not use in your project. |
| 63 | + run: | |
| 64 | + uv run ruff check libs/ sandbox/ scripts/ tests/ ./noxfile.py --fix |
| 65 | +
|
| 66 | + ## Import re-usable workflow from commit-changes.yml |
| 67 | + # Commits changes back to branch for pull request |
| 68 | + # - name: Commit changes back to branch |
| 69 | + # uses: ./.github/workflows/commit-changes.yml |
| 70 | + # with: |
| 71 | + # commit_message: "Apply lint fixes via Ruff" |
| 72 | + |
| 73 | + ## Use the code below if you did not create an on-deman commit-changes.yml workflow |
| 74 | + ## Commit changes back to branch |
| 75 | + - name: Commit and push changes |
| 76 | + env: |
| 77 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + run: | |
| 79 | + git config user.name "github-actions[bot]" |
| 80 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 81 | + if ! git diff --quiet; then |
| 82 | + echo "Changes detected. Committing..." |
| 83 | + git add . |
| 84 | + git commit -m "Apply lint fixes via Ruff" |
| 85 | + git push origin HEAD:${{ github.event.pull_request.head.ref }} |
| 86 | + else |
| 87 | + echo "No changes detected. Skipping commmit." |
| 88 | + fi |
0 commit comments