π‘ chore: CI fix env settings #31
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 μμ±νκΈ° |