chore: Consolidate CI style checks (#1936)

This commit is contained in:
Matthew Zhou
2024-10-24 15:24:26 -07:00
committed by GitHub
parent d94d02666a
commit f93dc8250b
7 changed files with 58 additions and 176 deletions

View File

@@ -1,34 +0,0 @@
name: Code Formatter (autoflake)
on:
pull_request:
paths:
- '**.py'
workflow_dispatch:
jobs:
autoflake-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: "3.12"
poetry-version: "1.8.2"
install-args: "-E dev" # TODO: change this to --group dev when PR #842 lands
- name: Run Autoflake
id: autoflake
run: poetry run autoflake --remove-all-unused-imports --remove-unused-variables --in-place --recursive --ignore-init-module-imports .
continue-on-error: true
- name: Check Autoflake Output
if: steps.autoflake.outcome == 'failure'
run: |
poetry run autoflake --version
poetry run python --version
echo "Autoflake check failed. To fix, please run 'poetry run autoflake .'"
exit 1

View File

@@ -1,36 +0,0 @@
name: Code Formatter (Black)
on:
pull_request:
paths:
- '**.py'
workflow_dispatch:
jobs:
black-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # Checkout the PR branch
fetch-depth: 0 # Fetch all history for all branches and tags
- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: "3.12"
poetry-version: "1.8.2"
install-args: "-E dev" # TODO: change this to --group dev when PR #842 lands
- name: Run Black
id: black
run: poetry run black --check .
continue-on-error: true
- name: Auto-fix with Black and commit
if: steps.black.outcome == 'failure' && !contains(github.event.pull_request.labels.*.name, 'check-only')
run: |
poetry run black .
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git diff --quiet && git diff --staged --quiet || (git add -A && git commit -m "Apply Black formatting")
git push
- name: Error if 'check-only' label is present
if: steps.black.outcome == 'failure' && contains(github.event.pull_request.labels.*.name, 'check-only')
run: echo "Black formatting check failed. Please run 'black .' locally to fix formatting issues." && exit 1

57
.github/workflows/code_style_checks.yml vendored Normal file
View File

@@ -0,0 +1,57 @@
name: Code Style Checks
on:
pull_request:
paths:
- '**.py'
pull_request_target:
types:
- opened
- edited
- synchronize
workflow_dispatch:
permissions:
pull-requests: read
jobs:
validation-checks:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"] # Adjust Python version matrix if needed
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # Checkout the PR branch
fetch-depth: 0 # Fetch all history for all branches and tags
- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: ${{ matrix.python-version }}
poetry-version: "1.8.2"
install-args: "-E dev -E postgres -E milvus -E external-tools -E tests" # Adjust as necessary
- name: Validate PR Title
uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run Pyright
uses: jakebailey/pyright-action@v2
with:
python-version: ${{ matrix.python-version }}
level: "error"
continue-on-error: true
- name: Run isort
run: poetry run isort --profile black --check-only --diff .
- name: Run Black
run: poetry run black --check .
- name: Run Autoflake
run: poetry run autoflake --remove-all-unused-imports --remove-unused-variables --in-place --recursive --ignore-init-module-imports .

View File

@@ -1,48 +0,0 @@
name: Code Formatter (isort)
on:
pull_request:
paths:
- '**.py'
workflow_dispatch:
jobs:
isort-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # Checkout the PR branch
fetch-depth: 0 # Fetch all history for all branches and tags
- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: "3.12"
poetry-version: "1.8.2"
install-args: "-E dev" # TODO: change this to --group dev when PR #842 lands
- name: Run isort
id: isort
run: |
output=$(poetry run isort --profile black --check-only --diff . | grep -v "Skipped" || true)
echo "$output"
if [ -n "$output" ]; then
echo "isort_changed=true" >> $GITHUB_OUTPUT
else
echo "isort_changed=false" >> $GITHUB_OUTPUT
fi
continue-on-error: true
- name: Auto-fix with isort and commit
if: steps.isort.outputs.isort_changed == 'true' && !contains(github.event.pull_request.labels.*.name, 'check-only')
run: |
poetry run isort --profile black .
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if [[ -n $(git status -s) ]]; then
git add -A
git commit -m "Apply isort import ordering"
git push
else
echo "No changes to commit"
fi
- name: Error if 'check-only' label is present and changes are needed
if: steps.isort.outputs.isort_changed == 'true' && contains(github.event.pull_request.labels.*.name, 'check-only')
run: echo "Isort check failed. Please run 'isort .' locally to fix import orders." && exit 1

View File

@@ -1,37 +0,0 @@
name: Code Formatter (Pyright type checking)"
on:
pull_request:
paths:
- '**.py'
permissions:
contents: read
pull-requests: read
jobs:
pyright:
name: "Pyright types check"
strategy:
matrix:
python-version: ["3.11"]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: ${{matrix.python-version}}
poetry-version: "1.7.1"
install-args: "-E dev" # TODO: change this to --group dev when PR #842 lands
- name: "Add Poetry venv to PATH"
run: 'echo "$(poetry env info --path)/bin" >> $GITHUB_PATH'
- name: "Run Pyright"
uses: jakebailey/pyright-action@v2
with:
python-version: ${{matrix.python-version}}
level: "error"
continue-on-error: true # TODO: remove once the repo has been corrected for pyright

View File

@@ -1,20 +0,0 @@
name: Validate Pull Request Format
on:
pull_request_target:
types:
- opened
- edited
- synchronize
permissions:
pull-requests: read
jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}