Skip to content

Commit

Permalink
merge: feat: add .env.*, Makefile and CI (#3)
Browse files Browse the repository at this point in the history
feat: add `.env.*`, `Makefile` and CI
  • Loading branch information
Colk-tech authored Jan 4, 2024
2 parents a10d80e + bc50c70 commit 9248915
Show file tree
Hide file tree
Showing 12 changed files with 814 additions and 2 deletions.
19 changes: 19 additions & 0 deletions .env.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ===== Priority order of environment variables =====
# = 1. Shell environment variables =====
# = 2. Environment variables in .env file =====
# = 1. .env.example =====
# = 2. .env.local =====
# = ! In CI/CD, only .env.ci is used. =====
# = ! In test, only .env.test is used. =====
# ===================================================

# ===== Following environment variables are required in SHELL environment. ======
GENKAIERA_IS_CI=1
GENKAIERA_IS_TEST=1

# ===== Following environment variables are required in .env file. ======
# Database
GENKAIERA_POSTGRES_HOST=postgres
GENKAIERA_POSTGRES_PORT=5432
GENKAIERA_POSTGRES_USER=genkaiera_api
GENKAIERA_POSTGRES_PASSWORD=hM7UCyG61f5aKKy8LOuWlfEhZffuD9gCRia3w+rKrYg0I3sa3PaKP4e7IDrXNfmd
19 changes: 19 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ===== Priority order of environment variables =====
# = 1. Shell environment variables =====
# = 2. Environment variables in .env file =====
# = 1. .env.example =====
# = 2. .env.local =====
# = ! In CI/CD, only .env.ci is used. =====
# = ! In test, only .env.test is used. =====
# ===================================================

# ===== Following environment variables are required in SHELL environment. ======
GENKAIERA_IS_CI=0
GENKAIERA_IS_TEST=0

# ===== Following environment variables are required in .env file. ======
# Database
GENKAIERA_POSTGRES_HOST=postgres
GENKAIERA_POSTGRES_PORT=5432
GENKAIERA_POSTGRES_USER=genkaiera_api
GENKAIERA_POSTGRES_PASSWORD=hM7UCyG61f5aKKy8LOuWlfEhZffuD9gCRia3w+rKrYg0I3sa3PaKP4e7IDrXNfmd
19 changes: 19 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ===== Priority order of environment variables =====
# = 1. Shell environment variables =====
# = 2. Environment variables in .env file =====
# = 1. .env.example =====
# = 2. .env.local =====
# = ! In CI/CD, only .env.ci is used. =====
# = ! In test, only .env.test is used. =====
# ===================================================

# ===== Following environment variables are required in SHELL environment. ======
GENKAIERA_IS_CI=0
GENKAIERA_IS_TEST=0

# ===== Following environment variables are required in .env file. ======
# Database
GENKAIERA_POSTGRES_HOST=postgres
GENKAIERA_POSTGRES_PORT=5432
GENKAIERA_POSTGRES_USER=genkaiera_api
GENKAIERA_POSTGRES_PASSWORD=hM7UCyG61f5aKKy8LOuWlfEhZffuD9gCRia3w+rKrYg0I3sa3PaKP4e7IDrXNfmd
19 changes: 19 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ===== Priority order of environment variables =====
# = 1. Shell environment variables =====
# = 2. Environment variables in .env file =====
# = 1. .env.example =====
# = 2. .env.local =====
# = ! In CI/CD, only .env.ci is used. =====
# = ! In test, only .env.test is used. =====
# ===================================================

# ===== Following environment variables are required in SHELL environment. ======
GENKAIERA_IS_CI=0
GENKAIERA_IS_TEST=1

# ===== Following environment variables are required in .env file. ======
# Database
GENKAIERA_POSTGRES_HOST=postgres
GENKAIERA_POSTGRES_PORT=5432
GENKAIERA_POSTGRES_USER=genkaiera_api
GENKAIERA_POSTGRES_PASSWORD=hM7UCyG61f5aKKy8LOuWlfEhZffuD9gCRia3w+rKrYg0I3sa3PaKP4e7IDrXNfmd
80 changes: 80 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Python CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

permissions: write-all

env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
IMAGE_CACHE_DIR: /tmp/cache/docker-image
IMAGE_CACHE_KEY: cache-image

jobs:
flake8:
name: Run flake8
runs-on: ubuntu-latest

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

- name: Run flake8
env:
GENKAIERA_IS_CI: "1"
run: |
make flake8
mypy:
name: Run mypy
runs-on: ubuntu-latest

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

- name: Run mypy
env:
GENKAIERA_IS_CI: "1"
run: |
make mypy
black:
name: Run black
runs-on: ubuntu-latest

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

- name: Run black
env:
GENKAIERA_IS_CI: "1"
run: |
make black_check
pytest:
name: Run pytest
runs-on: ubuntu-latest

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

- name: Run pytest
env:
GENKAIERA_IS_CI: "1"
run: |
make pytest_ci
- name: Create Coverage Comment
id: coverageComment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: pytest-coverage.txt
junitxml-path: ./pytest.xml

99 changes: 99 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# CI
ifeq ($(GENKAIERA_IS_CI),"1")
ifneq (,$(wildcard ./.env.ci))
include .env.ci
export
else
$(error ".env.ci file is missing")
endif

# TEST
else ifeq ($(GENKAIERA_IS_TEST),"1")
ifneq (,$(wildcard ./.env.test))
include .env.test
export
else
$(error ".env.test file is missing")
endif

# LOCAL
else
ifneq (,$(wildcard ./.env.example))
include .env.example
export
else
$(error ".env.example file is missing")
endif

ifneq (,$(wildcard ./.env.local))
include .env.local
export
else
$(error ".env.local file is missing")
endif
endif

.PHONE: build
build:
docker compose build --build-arg BUILDKIT_INLINE_CACHE=1

.PHONY: up
up:
docker compose up -d --build

.PHONY: down
down:
docker compose down

.PHONY: restart
restart:
docker compose restart

.PHONY: destroy
destroy:
docker compose down --rmi all --volumes --remove-orphans

.PHONY: logs
logs:
docker compose logs -f

.PHONY: shell
shell:
docker compose run --rm app bash

.PHONY: flake8
flake8:
docker compose run --rm app bash -c "python ./script/run_command.py flake8 ./"

.PHONY: mypy
mypy:
docker compose run --rm app bash -c "python ./script/run_command.py mypy ./"

.PHONY: black
black:
docker compose run --rm app bash -c "python ./script/run_command.py black ./"

.PHONY: black_check
black_check:
docker compose run --rm app bash -c "python ./script/run_command.py black ./ --check"

.PHONY: isort
isort:
docker compose run --rm app bash -c "python ./script/run_command.py isort ./"

.PHONY: isort_check
isort_check:
docker compose run --rm app bash -c "python ./script/run_command.py isort ./ --check-only"

.PHONY: pytest_html
pytest_html:
docker compose run --rm app bash -c "python ./script/run_command.py pytest -v ./test/ --cov=./src/ --cov-report=html --html=report.html"

.PHONY: pytest_xml
pytest_xml:
docker compose run --rm app bash -c "python ./script/run_command.py pytest -v ./test/ --cov=./src/ --cov-report=xml"

.PHONY: pytest_ci
pytest_ci:
$(MAKE) up
docker compose run --rm app bash -c "python r./script/un_command.py pytest -v ./test/ --cov=./src/ --junitxml=pytest.xml --cov-report=term-missing:skip-covered | tee pytest-coverage.txt"
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
restart: unless-stopped
tty: true

api:
app:
build:
context: .
dockerfile: ./docker/python/Dockerfile
Expand Down
Loading

0 comments on commit 9248915

Please sign in to comment.