Skip to content

Commit

Permalink
improved linting and tests actions
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaDuina committed Dec 20, 2024
1 parent 9d725fd commit da45e9b
Showing 1 changed file with 83 additions and 15 deletions.
98 changes: 83 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,116 @@ name: Check formatting and run tests
on:
pull_request:
branches:
- '*' # Trigger on pull requests for all branches
- '*'
paths:
- '**.py' # Only run on changes to Python files
- '**.py'

push:
branches:
- main

jobs:
check-formatting-and-run-tests:
runs-on: ubuntu-latest # You can choose a different runner if necessary
setup-environment:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2 # Checkout the code to the runner
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10' # Adjust the Python version to match your environment
python-version: '3.12'

- name: Cache Poetry and Virtual Environment
uses: actions/cache@v3
with:
path: |
~/.poetry
.venv
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
poetry-${{ runner.os }}-
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 - # Install Poetry
echo "$HOME/.poetry/bin" >> $GITHUB_PATH # Add Poetry to the PATH
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Install dependencies with Poetry
run: |
poetry install
poetry install --sync --no-interaction
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.poetry
.venv
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
poetry-${{ runner.os }}-
check-formatting:
runs-on: ubuntu-latest
needs: setup-environment # Waits for setup-environment to finish

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.12'

- name: Restore cached Poetry and Virtual Environment
uses: actions/cache@v3
with:
path: |
~/.poetry
.venv
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
poetry-${{ runner.os }}-
- name: Check code formatting with Black
run: |
poetry run black --check . # Check if the code is formatted correctly with Black
continue-on-error: false # Fail the job if Black finds unformatted code
poetry run black --check .
continue-on-error: false

- name: Check imports with isort
run: |
poetry run isort --check-only . # Check if the imports are sorted correctly
continue-on-error: false # Fail the job if isort finds unsorted imports
poetry run isort --check-only .
continue-on-error: false
env:
CI: true # Prevent isort from modifying files during the check
CI: true

run-tests:
runs-on: ubuntu-latest
needs:
- setup-environment # Waits for setup-environment to finish
- check-formatting # Also waits for check-formatting to succeed

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.12'

- name: Restore cached Poetry and Virtual Environment
uses: actions/cache@v3
with:
path: |
~/.poetry
.venv
key: poetry-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
poetry-${{ runner.os }}-
- name: Run tests with pytest
run: |
poetry run pytest --maxfail=1 --disable-warnings -q # Run tests using Poetry's virtualenv
poetry run pytest --maxfail=1 --disable-warnings -q

0 comments on commit da45e9b

Please sign in to comment.