Skip to content

Commit

Permalink
Merge pull request #19 from Xiao75896453/feat/repo/github_action
Browse files Browse the repository at this point in the history
feat (repo/GitHub_Action): Add lint and test
  • Loading branch information
Xiao75896453 authored Aug 5, 2024
2 parents f1b6451 + 0f9d401 commit b245186
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 2 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/pytest_account_password_management.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: pytest_account_password_management

on: push

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11.2"]
redis-version: [6]
env:
STAGE: 'stg'
SERVICE_PORT: 1
DB_HOST: "localhost"
DB_PORT: 5432
DB_USER: "postgres"
DB_PASSWORD: "password"
DB_DATABASE: "db_test"
DB_POOL_SIZE: 10
DB_MAX_OVERFLOW: 5
DB_POOL_RECYCLE: 300
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up PostgreSQL with Postgis 12
# You may pin to the exact commit or the version.
# uses: ireznik/postgis-action@407eaeebecb5f1907ad19d1c63e2f9e1a441ec72
uses: ireznik/postgis-action@v12
with:
# Version of PostgreSQL to use
postgresql version: '15-3.3'
# POSTGRES_DB - name for the default database that is created
postgresql db: $DB_DATABASE
# POSTGRES_USER - create the specified user with superuser power
postgresql user: $DB_USER
# POSTGRES_PASSWORD - superuser password
postgresql password: $DB_PASSWORD
- name: Set PostgreSQL config
run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends postgresql-client
sudo -i -u postgres
sudo PGPASSWORD=$DB_PASSWORD -u $DB_USER psql -h $DB_HOST --no-password -c "ALTER DATABASE $DB_DATABASE SET TIMEZONE TO 'ETC/UTC-8';"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Install dependencies
run: |
poetry install
- name: Set up DB Schema
run: |
source .venv/bin/activate
alembic -c 'projects/account_password_management/alembic.ini' upgrade head
- name: Test with pytest
run: |
source .venv/bin/activate
pytest $PROJECT_PATH
37 changes: 37 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ruff

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11.2"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Install dependencies
run: |
poetry add ruff
- name: Changed Files
id: changed-files
uses: tj-actions/changed-files@v40
with:
files_yaml: |
py:
- '**.py'
- name: Linting the code with ruff
if: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
source .venv/bin/activate
ruff check ${{ steps.changed-files.outputs.all_changed_files }}
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
exclude: migrations/
- repo: local
hooks:
- id: ruff
name: ruff
entry: ruff
args: ['check .']
language: system
types: [python]
- repo: local
hooks:
- id: pytest_account_password_management
name: pytest_account_password_management
entry: pytest
args: ['projects/account_password_management']
language: system
stages: [push]
pass_filenames: false
always_run: true
76 changes: 75 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ ruff = "^0.5.6"
isort = "^5.13.2"
pytest = "^8.3.2"
pre-commit = "^3.8.0"
httpx = "^0.27.0"
pytest-asyncio = "^0.23.8"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"env.py" = ["F401"]
"env.py" = ["F401"]

0 comments on commit b245186

Please sign in to comment.