1- name : Code Quality Checks
1+ name : CI
22
33on :
44 push :
5- branches :
6- - develop
7- pull_request :
85
9- jobs :
10- ci :
11- runs-on : ubuntu-latest
126
7+ jobs :
8+ static-analysis : # mypy, black, ruff 등 정적 분석
9+ runs-on : ubuntu-22.04 # 실제 프로덕션에서는 모든 버전을 고정하는 것이 좋다.
10+ # 예기치 못하게 버전이 올라가서 장애나는 것을 막기 위해
1311 steps :
14- - name : Checkout code
15- uses : actions/checkout@v3
12+ - name : Check out the codes
13+ uses : actions/checkout@v2
14+
15+ - name : Setup python environment
16+ id : setup-python
17+ uses : actions/setup-python@v2
18+ with :
19+ python-version : " 3.12"
1620
17- - name : Set up Python
18- uses : actions/setup-python@v4
21+ - name : Cache Poetry
22+ id : cache-poetry
23+ uses : actions/cache@v4
1924 with :
20- python-version : ' 3.12'
25+ key : poetry-1.8.5
26+ path : ~/.local/ # poetry 는 ~/.local 에 설치되므로, 이 디렉터리를 통째로 캐시할 것입니다.
2127
2228 - name : Install Poetry
29+ if : steps.cache-poetry.outputs.cache-hit != 'true'
2330 run : |
24- curl -sSL https://install.python-poetry.org | python3 -
25- echo "${HOME}/.local/bin" >> $GITHUB_PATH
31+ curl -sSL https://install.python-poetry.org | python3 - --version 1.8.5
32+
33+ - name : Register Poetry bin
34+ run : echo "${HOME}/.poetry/bin" >> $GITHUB_PATH
35+
36+ - name : Cache dependencies
37+ id : cache-venv
38+ uses : actions/cache@v4
39+ with :
40+ key : python-${{ steps.setup-python.outputs.python-version }}-poetry-lock-${{ hashFiles('poetry.lock') }}-toml-${{ hashFiles('pyproject.toml') }}-poetry-1.8.5
41+ path : /home/runner/.cache/pypoetry/virtualenvs/
42+
43+ - name : Install dependencies
44+ if : steps.cache-venv.outputs.cache-hit != 'true'
45+ run : poetry install --no-root
46+
47+ - name : Run Black
48+ run : poetry run black . --check
49+
50+ - name : Run Ruff
51+ run : |
52+ poetry run ruff check --select I
53+ poetry run ruff check
54+
55+ - name : Run Mypy
56+ run : poetry run mypy .
57+
58+ test : # 전체 테스트 실행한다.
59+ runs-on : ubuntu-22.04
60+
61+ services :
62+ redis :
63+ image : redis:7.2-alpine
64+ ports :
65+ - 6379:6379
66+ options : >-
67+ --health-cmd "redis-cli ping"
68+ --health-interval 5s
69+ --health-timeout 5s
70+ --health-retries 5
71+ env :
72+ MYSQL_HOST : 127.0.0.1
73+ MYSQL_PORT : 3306
74+ MYSQL_USER : root
75+ MYSQL_PASSWORD : password
76+ MYSQL_DATABASE : tellingme_local
77+ REDIS_HOST : localhost
2678
27- - name : Install Packages & Libraries
79+ steps :
80+ - name : Check out the codes
81+ uses : actions/checkout@v2
82+
83+ - name : Setup python environment
84+ id : setup-python
85+ uses : actions/setup-python@v2
86+ with :
87+ python-version : " 3.12"
88+
89+ - name : Cache Poetry
90+ id : cache-poetry
91+ uses : actions/cache@v4
92+ with :
93+ key : poetry-1.8.5
94+ path : ~/.local/ # poetry 는 ~/.local 에 설치되므로, 이 디렉터리를 통째로 캐시할 것입니다.
95+
96+ - name : Install Poetry
97+ if : steps.cache-poetry.outputs.cache-hit != 'true'
2898 run : |
29- poetry install
99+ curl -sSL https://install.python-poetry.org | python3 - --version 1.8.5
100+
101+ - name : Register Poetry bin
102+ run : echo "${HOME}/.poetry/bin" >> $GITHUB_PATH
30103
31- - name : Run isort (Import sorting)
104+ - name : Cache dependencies
105+ id : cache-venv
106+ uses : actions/cache@v4
107+ with :
108+ key : python-${{ steps.setup-python.outputs.python-version }}-poetry-lock-${{ hashFiles('poetry.lock') }}-toml-${{ hashFiles('pyproject.toml') }}-poetry-1.8.5
109+ path : /home/runner/.cache/pypoetry/virtualenvs/
110+
111+ - name : Install dependencies
112+ if : steps.cache-venv.outputs.cache-hit != 'true'
113+ run : poetry install --no-root
114+
115+ - name : Set timezone to KST
32116 run : |
33- poetry run isort . --check --diff
117+ sudo rm /etc/localtime
118+ sudo ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime
34119
35- - name : Run black (Code formatting)
120+ - name : Start Mysql
36121 run : |
37- poetry run black . --check
122+ sudo systemctl start mysql
123+ mysql -e "use mysql; FLUSH PRIVILEGES; ALTER USER '${{ env.MYSQL_USER }}'@'localhost' IDENTIFIED BY '${{ env.MYSQL_PASSWORD }}';" -uroot -proot
124+ mysql -e 'CREATE DATABASE ${{ env.MYSQL_DATABASE }};' -u${{ env.MYSQL_USER }} -p${{ env.MYSQL_PASSWORD }}
38125
39- - name : Run Mypy
126+ - name : Run tests
40127 run : |
41- poetry run mypy .
128+ poetry run coverage run -m pytest .
129+ poetry run coverage report -m
130+
131+
132+ # deploy:
133+ # runs-on: ubuntu-24.04
134+ # needs: [test, static-analysis]
135+ # if: github.ref == 'refs/heads/main'
136+ # steps:
137+ # - name: Check out the codes
138+ # uses: actions/checkout@v3
139+ #
140+ # - name: deploy staging
141+ # env:
142+ # PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY_STAGING }}
143+ # HOSTNAME: ${{ secrets.SSH_HOST_STAGING }}
144+ # USER_NAME: ${{ secrets.USER_NAME_STAGING }}
145+ #
146+ # # staging 서버의 .bashrc 에 gunicorn_reload 가 정의되어 있습니다. gunicorn master 에게 HUP 를 줘서 worker 를 재시작합니다.
147+ # run: |
148+ # echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
149+ # ssh -o StrictHostKeyChecking=no -t -i private_key ${USER_NAME}@${HOSTNAME} "bash -i -c 'gunicorn_reload'"
150+
151+ # todo : CD 작성하기
0 commit comments