|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + static-analysis: # mypy, black, ruff 등 정적 분석만 실행 |
| 10 | + runs-on: ubuntu-22.04 # 실제 프로덕션 환경에서는 lastest 대신 버젼을 고정하는 것이 좋다. 업데이트 사항에 따라 예상치 못한 에러가 발생할 수 있기 때문. |
| 11 | + steps: |
| 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.13" # 파이썬 버젼 역시 개발환경에 맞는 버젼으로 고정으로 사용한다. |
| 20 | + |
| 21 | + - name: Cache Poetry |
| 22 | + id: cache-poetry |
| 23 | + uses: actions/cache@v3 |
| 24 | + with: |
| 25 | + key: poetry-2.0.1 |
| 26 | + path: ~/.local/ # poetry 의 실제 설치 경로를 통째로 캐시함. |
| 27 | + |
| 28 | + - name: Install Poetry |
| 29 | + if: steps.cache-poetry.outputs.cache-hit != 'true' |
| 30 | + run: | # 개행을 하여 여러줄로 명령어를 사용하고 싶을때 파이프라인 기호 | 를 사용한다. |
| 31 | + curl -sSL https://install.python-poetry.org | python3 - --version 2.0.1 |
| 32 | +
|
| 33 | + - name: Register Poetry bin # 포에트리 환경변수를 깃허브 패스(.zshrc 같은 쉘 설정파일)에 기입하여 포에트리 명령어를 사용할 수 있게 한다. |
| 34 | + run: echo "${HOME}/.poetry/bin" >> $GITHUB_PATH |
| 35 | + |
| 36 | + - name: Cache dependencies |
| 37 | + id: cache-venv |
| 38 | + uses: actions/cache@v3 |
| 39 | + with: |
| 40 | + # hashFiles를 사용하여 파일의 해시값을 비교하여 파이썬 버전이 바뀌었을 때, lock 파일이나 toml 파일이 바뀌었을때 종속성을 재설치합니다. |
| 41 | + # 바뀐 것이 없는 경우에는 캐싱된 종속성을 사용합니다. |
| 42 | + key: python-${{ steps.setup-python.outputs.python-version }}-poetry-lock-${{ hashFiles('poetry.lock') }}-toml-${{ hashFiles('pyproject.toml') }}-poetry-1.8.5 |
| 43 | + path: /home/runner/.cache/pypoetry/virtualenvs/ |
| 44 | + |
| 45 | + - name: Install dependencies # pytest 를 dev 종속성으로 설치하였기 때문에 only-main 옵션은 사용하지 않는다. |
| 46 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 47 | + run: poetry install --no-root |
| 48 | + |
| 49 | + - name: Run Black |
| 50 | + run: poetry run black . --check # check 옵션을 걸게되면 리포매팅을 하지 않는다. |
| 51 | + |
| 52 | + - name: Run Ruff |
| 53 | + run: | # Isort 를 먼저 체크하고 기본 lint 규칙을 지켰는지 검사한다. |
| 54 | + poetry run ruff check --select I |
| 55 | + poetry run ruff check |
| 56 | +
|
| 57 | + - name: Run Mypy # mypy 타입 정적 검사를 실행한다. |
| 58 | + run: poetry run mypy . |
| 59 | + |
| 60 | + test: # mypy와 직렬로 실행하게되면 시간이 너무 오래 걸려서 test와 정적 타입분석은 병렬로 실행 |
| 61 | + runs-on: ubuntu-22.04 |
| 62 | + |
| 63 | + steps: |
| 64 | + - name: Check out the codes |
| 65 | + uses: actions/checkout@v2 |
| 66 | + |
| 67 | + - name: Setup python environment |
| 68 | + id: setup-python |
| 69 | + uses: actions/setup-python@v2 |
| 70 | + with: |
| 71 | + python-version: "3.12" |
| 72 | + |
| 73 | + - name: Cache Poetry |
| 74 | + id: cache-poetry |
| 75 | + uses: actions/cache@v3 |
| 76 | + with: |
| 77 | + key: poetry-2.0.1 |
| 78 | + path: ~/.local/ # poetry 의 실제 설치 경로를 통째로 캐시함. |
| 79 | + |
| 80 | + - name: Install Poetry |
| 81 | + if: steps.cache-poetry.outputs.cache-hit != 'true' |
| 82 | + run: | |
| 83 | + curl -sSL https://install.python-poetry.org | python3 - --version 2.0.1 |
| 84 | +
|
| 85 | + - name: Register Poetry bin |
| 86 | + run: echo "${HOME}/.poetry/bin" >> $GITHUB_PATH |
| 87 | + |
| 88 | + - name: Cache dependencies |
| 89 | + id: cache-venv |
| 90 | + uses: actions/cache@v3 |
| 91 | + with: |
| 92 | + key: python-${{ steps.setup-python.outputs.python-version }}-poetry-lock-${{ hashFiles('poetry.lock') }}-toml-${{ hashFiles('pyproject.toml') }}-poetry-1.8.5 |
| 93 | + path: /home/runner/.cache/pypoetry/virtualenvs/ |
| 94 | + |
| 95 | + - name: Install dependencies |
| 96 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 97 | + run: poetry install --no-root |
| 98 | + |
| 99 | + - name: Run tests # 커버리지로 pytest를 실행하고 결과 report를 출력한다. |
| 100 | + run: | |
| 101 | + poetry run coverage run -m pytest . |
| 102 | + poetry run coverage report -m |
0 commit comments