Skip to content

Commit

Permalink
feat: add linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoub3bidi committed Feb 18, 2024
1 parent 2cb243a commit 818ce3a
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Linter

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Create environment file
run: |
echo "POSTGRES_HOST=${{ secrets.POSTGRES_HOST }}" > .env
echo "POSTGRES_PORT=${{ secrets.POSTGRES_PORT }}" >> .env
echo "POSTGRES_DB=${{ secrets.POSTGRES_DB }}" >> .env
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" >> .env
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> .env
- name: Run linter
run: |
setsid ./ci/lint.sh
14 changes: 13 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
stages:
- test
- lint

unit_test:
stage: test
Expand All @@ -21,4 +22,15 @@ integration_test:
- /^(main|develop.*)$/
- merge_requests
tags:
- imagesbuilder
- imagesbuilder

lint:
stage: lint
script:
- setsid ./ci/lint.sh
only:
refs:
- /^(main|develop.*)$/
- merge_requests
tags:
- imagesbuilder
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ FROM api AS unit_tests

WORKDIR /app/src

CMD ["python", "-m", "unittest", "discover", "-s", "./unit_tests", "-p", "test_*.py", "-v"]
CMD ["python", "-m", "unittest", "discover", "-s", "./unit_tests", "-p", "test_*.py", "-v"]

FROM api AS linter

WORKDIR /app/src

CMD ["ruff", "check", "--fix", "."]
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ Here's how to run the integration test locally:
```shell
docker-compose up --build --abort-on-container-exit mercury_unit_tests
```

## Linter

Having a fast linter can help avoiding coding style problems, and potentially avoid future bugs that takes long hours to fix.
For the linter we're working with [ruff](https://astral.sh/ruff), a very fast linter written in Rust.

Here's how to run the linter test locally:

```shell
docker-compose up --build --abort-on-container-exit mercury_linter
```

-------

## Contributions
Expand Down
3 changes: 3 additions & 0 deletions ci/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

docker-compose up --build --abort-on-container-exit mercury_linter
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ services:
target: unit_tests
env_file:
- .env
mercury_linter:
image: cwcloud-linter:latest
build:
context: .
dockerfile: ./Dockerfile
target: linter
env_file:
- .env

volumes:
mercurydb:
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ bcrypt
python-jose[cryptography]
passlib[bcrypt]
python-multipart
pytest
pytest
ruff

0 comments on commit 818ce3a

Please sign in to comment.