Skip to content

Commit

Permalink
Merge pull request #3 from Jiooum102/2-setup-cicd
Browse files Browse the repository at this point in the history
Setup CI/CD
  • Loading branch information
Jiooum102 authored Aug 25, 2024
2 parents 1f1ca10 + 6784bc8 commit 9283579
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 0 deletions.
Empty file added .env.dev
Empty file.
32 changes: 32 additions & 0 deletions .github/workflows/linting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Code linting CI
on: push
jobs:
black:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install -r requirements.txt
- run: black --check .

isort:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install -r requirements.txt
- run: isort --check .

flake8:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install -r requirements.txt
- run: flake8
41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
default_language_version:
python: python3.10

customCommands:
- key: "W"
command: git commit --no-verify
context: "global"
subprocess: true

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
language_version: python3.10
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile=black"]
- repo: local
hooks:
- id: pytest-check
name: pytest-check
stages: [push]
types: [python3]
entry: bash -c 'make dev_test'
language: python
pass_filenames: false
always_run: true
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SHELL=/bin/bash

DEV_ENV_FILE=".env.dev"

# Run directly from env
# Recommend to create a specific env and activate it first
dev_install:
./scripts/develop.sh install
dev_setup_env:
export PYTHONPATH=`pwd`
source ${DEV_ENV_FILE}
dev_run_server:
./scripts/develop.sh run
dev_test:
./scripts/develop.sh test
dev_test_lint:
./scripts/develop.sh test_lint
dev_fix_lint:
./scripts/develop.sh fix_lint
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.black]
line-length = 120
skip-string-normalization = 1
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''

[tool.isort]
profile = "black"
lines_after_imports = 2
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
black~=23.11.0
flake8~=6.1.0
isort~=5.12.0
pre-commit~=3.5.0
pytest~=7.4.2
76 changes: 76 additions & 0 deletions scripts/develop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

cmd=$1

ENV_FILE=".env.dev"

# Check if we run from Gitlab runner (use Gitlab variables, not .env file)
if [[ ! -f $ENV_FILE ]]
then
echo ".env file does not exist on your filesystem. Read from environment variables."
else
source $ENV_FILE
fi

# constants
IMAGE_NAME=$PROJECT_NAME
COMMIT_HASH=$(git describe --always)
IMAGE_VERSION="${IMAGE_VERSION//\//-}" # Replace / to - because docker tags not support

usage() {
echo "develop.sh <command> <arguments>"
echo "Available commands:"
echo " install install environment"
echo " test run unit-test"
echo " test_lint run linters"
}

if [[ -z "$cmd" ]]; then
echo "Missing command"
usage
exit 1
fi

install() {
echo "Install requirements ..."
pip install -r requirements.txt

echo "Install pre-commit for auto linting and testing stage ..."
pre-commit install
}

test() {
echo "Unit-test running ..."
/bin/bash ./scripts/run_tests.sh run_test
}

test_lint() {
echo "Run lint test"
black --check . && isort --check . && flake8
}

fix_lint() {
echo "Run fix linters"
black . && isort . && flake8
}


case $cmd in
install)
install "$@"
;;
test)
test "$@"
;;
test_lint)
test_lint "$@"
;;
fix_lint)
fix_lint "$@"
;;
*)
echo -n "Unknown command: $cmd"
usage
exit 1
;;
esac

0 comments on commit 9283579

Please sign in to comment.