Improve code quality #1095
This file contains 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
on: | |
pull_request: | |
type: [opened] | |
push: | |
paths: | |
- '.github/workflows/ci.yaml' | |
- '.github/workflows/init_db.sql' | |
- 'insalan/**' | |
- 'requirements.txt' | |
- '*.sh' | |
- 'locale/**' | |
- 'Dockerfile*' | |
jobs: | |
linting: | |
env: | |
PYLINT_MINSCORE: 8.0 | |
runs-on: ubuntu-22.04 | |
steps: | |
- run: echo "### Linting" >> $GITHUB_STEP_SUMMARY | |
- uses: actions/checkout@v3 | |
# Install Python 3.12 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
# Set the environment up | |
- run: python3 -m venv env | |
- run: source env/bin/activate | |
# Install dependencies | |
- name: Install dependencies | |
run: pip3 install -r requirements.txt | |
- name: Install pylint and pylint-django | |
run: pip3 install pylint==3.0.3 pylint-django | |
# Run lints | |
- name: Run linter evaluation | |
shell: bash | |
run: | | |
pylint --fail-under ${{ env.PYLINT_MINSCORE }} --load-plugins pylint_django --django-settings-module insalan.settings ./insalan | tee >(grep "Your code has been" | sed 's/^Your code has been rated at \(.*\)\/10.*/PYLINT_SCORE=\1/' >> "$GITHUB_ENV") | |
# Summary | |
- name: Summary | |
run: echo ::notice title=Pylint Score::Your \`pylint\` score is ${{ env.PYLINT_SCORE }} | |
- run: echo Your \`pylint\` score is ${{ env.PYLINT_SCORE }} >> "$GITHUB_STEP_SUMMARY" | |
unit-tests: | |
if: always() | |
needs: [linting] | |
runs-on: ubuntu-22.04 | |
env: | |
DB_NAME: insalan | |
DB_USER: insalan | |
DB_PASS: insalan | |
DB_HOST: "127.0.0.1" | |
DB_PORT: 5432 | |
services: | |
postgresql: | |
image: postgres | |
env: | |
POSTGRES_PASSWORD: ${{ env.DB_PASS }} | |
POSTGRES_USER: ${{ env.DB_USER }} | |
POSTGRES_DB: ${{ env.DB_NAME }} | |
ports: | |
- "5432:5432" | |
options: --health-cmd pg_isready --health-interval 1s --health-timeout 5s --health-retries 10 | |
steps: | |
- uses: actions/checkout@v3 | |
# Install Python 3.12 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
# Set the environment up | |
- run: python3 -m venv env | |
- run: source env/bin/activate | |
# Install dependencies | |
- run: pip3 install -r requirements.txt | |
# Initialize the database | |
- run: psql postgresql://${{ env.DB_USER }}:${{ env.DB_PASS }}@${{ env.DB_HOST }}:${{ env.DB_PORT }}/${{ env.DB_NAME }} -f .github/workflows/init_db.sql | |
# Prepare database | |
- run: python3 manage.py makemigrations | |
- run: python3 manage.py migrate | |
- run: python3 manage.py test --parallel auto |