Update README.md #33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| jobs: | |
| static-analysis: # mypy, black, ruff 등 정적 분석 | |
| runs-on: ubuntu-22.04 # 실제 프로덕션에서는 모든 버전을 고정하는 것이 좋다. | |
| # 예기치 못하게 버전이 올라가서 장애나는 것을 막기 위해 | |
| steps: | |
| - name: Check out the codes | |
| uses: actions/checkout@v2 | |
| - name: Setup python environment | |
| id: setup-python | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: "3.12" | |
| - name: Cache Poetry | |
| id: cache-poetry | |
| uses: actions/cache@v4 | |
| with: | |
| key: poetry-1.8.5 | |
| path: ~/.local/ # poetry 는 ~/.local 에 설치되므로, 이 디렉터리를 통째로 캐시할 것입니다. | |
| - name: Install Poetry | |
| if: steps.cache-poetry.outputs.cache-hit != 'true' | |
| run: | | |
| curl -sSL https://install.python-poetry.org | python3 - --version 1.8.5 | |
| - name: Register Poetry bin | |
| run: echo "${HOME}/.poetry/bin" >> $GITHUB_PATH | |
| - name: Cache dependencies | |
| id: cache-venv | |
| uses: actions/cache@v4 | |
| with: | |
| key: python-${{ steps.setup-python.outputs.python-version }}-poetry-lock-${{ hashFiles('poetry.lock') }}-toml-${{ hashFiles('pyproject.toml') }}-poetry-1.8.5 | |
| path: /home/runner/.cache/pypoetry/virtualenvs/ | |
| - name: Install dependencies | |
| if: steps.cache-venv.outputs.cache-hit != 'true' | |
| run: poetry install --no-root | |
| - name: Run Black | |
| run: poetry run black . --check | |
| - name: Run Ruff | |
| run: | | |
| poetry run ruff check --select I | |
| poetry run ruff check | |
| - name: Run Mypy | |
| run: poetry run mypy . | |
| test: # 전체 테스트 실행한다. | |
| runs-on: ubuntu-22.04 | |
| services: | |
| redis: | |
| image: redis:7.2-alpine | |
| ports: | |
| - 6379:6379 | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 5s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| env: | |
| MYSQL_HOST: 127.0.0.1 | |
| MYSQL_PORT: 3306 | |
| MYSQL_USER: root | |
| MYSQL_PASSWORD: password | |
| MYSQL_DATABASE: tellingme_local | |
| REDIS_HOST: localhost | |
| steps: | |
| - name: Check out the codes | |
| uses: actions/checkout@v2 | |
| - name: Setup python environment | |
| id: setup-python | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: "3.12" | |
| - name: Cache Poetry | |
| id: cache-poetry | |
| uses: actions/cache@v4 | |
| with: | |
| key: poetry-1.8.5 | |
| path: ~/.local/ # poetry 는 ~/.local 에 설치되므로, 이 디렉터리를 통째로 캐시할 것입니다. | |
| - name: Install Poetry | |
| if: steps.cache-poetry.outputs.cache-hit != 'true' | |
| run: | | |
| curl -sSL https://install.python-poetry.org | python3 - --version 1.8.5 | |
| - name: Register Poetry bin | |
| run: echo "${HOME}/.poetry/bin" >> $GITHUB_PATH | |
| - name: Cache dependencies | |
| id: cache-venv | |
| uses: actions/cache@v4 | |
| with: | |
| key: python-${{ steps.setup-python.outputs.python-version }}-poetry-lock-${{ hashFiles('poetry.lock') }}-toml-${{ hashFiles('pyproject.toml') }}-poetry-1.8.5 | |
| path: /home/runner/.cache/pypoetry/virtualenvs/ | |
| - name: Install dependencies | |
| if: steps.cache-venv.outputs.cache-hit != 'true' | |
| run: poetry install --no-root | |
| - name: Set timezone to KST | |
| run: | | |
| sudo rm /etc/localtime | |
| sudo ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime | |
| - name: Start Mysql | |
| run: | | |
| sudo systemctl start mysql | |
| mysql -e "use mysql; FLUSH PRIVILEGES; ALTER USER '${{ env.MYSQL_USER }}'@'localhost' IDENTIFIED BY '${{ env.MYSQL_PASSWORD }}';" -uroot -proot | |
| mysql -e 'CREATE DATABASE ${{ env.MYSQL_DATABASE }};' -u${{ env.MYSQL_USER }} -p${{ env.MYSQL_PASSWORD }} | |
| - name: Run tests | |
| run: | | |
| poetry run coverage run -m pytest . | |
| poetry run coverage report -m | |
| # deploy: | |
| # runs-on: ubuntu-24.04 | |
| # needs: [test, static-analysis] | |
| # if: github.ref == 'refs/heads/main' | |
| # steps: | |
| # - name: Check out the codes | |
| # uses: actions/checkout@v3 | |
| # | |
| # - name: deploy staging | |
| # env: | |
| # PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY_STAGING }} | |
| # HOSTNAME: ${{ secrets.SSH_HOST_STAGING }} | |
| # USER_NAME: ${{ secrets.USER_NAME_STAGING }} | |
| # | |
| # # staging 서버의 .bashrc 에 gunicorn_reload 가 정의되어 있습니다. gunicorn master 에게 HUP 를 줘서 worker 를 재시작합니다. | |
| # run: | | |
| # echo "$PRIVATE_KEY" > private_key && chmod 600 private_key | |
| # ssh -o StrictHostKeyChecking=no -t -i private_key ${USER_NAME}@${HOSTNAME} "bash -i -c 'gunicorn_reload'" | |
| # todo : CD 작성하기 |