From da45e9bf3a8f3a05b617d132c2c8694702163485 Mon Sep 17 00:00:00 2001 From: Andrea Duina Date: Fri, 20 Dec 2024 14:29:23 +0100 Subject: [PATCH] improved linting and tests actions --- .github/workflows/main.yml | 98 ++++++++++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 940fbd5..3e6d3ff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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