์ฐธ๊ณ ํญ๋ชฉ
GitHub ํธ์คํธ ์คํ๊ธฐ๋ ํ์ฌ GitHub Enterprise Server์์ ์ง์๋์ง ์์ต๋๋ค.
์๊ฐ
์ด ๊ฐ์ด๋์์๋ Python ํจํค์ง๋ฅผ ๋น๋ํ๊ณ ํ ์คํธํ๊ณ ๊ฒ์ํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค.
GitHub ํธ์คํธ ์คํ๊ธฐ์๋ Python ๋ฐ PyPy๋ฅผ ํฌํจํ๋ ์ํํธ์จ์ด๊ฐ ์ฌ์ ์ค์น๋ ๋๊ตฌ ์บ์๊ฐ ์์ต๋๋ค. ์ฌ์ฉ์๋ ์๋ฌด๊ฒ๋ ์ค์นํ ํ์๊ฐ ์์ต๋๋ค. ์ต์ ์ํํธ์จ์ด ๋ฐ ์ฌ์ ์ค์น๋ Python ๋ฐ PyPy ๋ฒ์ ์ ์ ์ฒด ๋ชฉ๋ก์ GitHub ํธ์คํ ์คํ๊ธฐ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
ํ์ ์กฐ๊ฑด
YAML ๋ฐ GitHub Actions์ ๊ตฌ๋ฌธ์ ๋ํด ์ ์๊ณ ์์ด์ผ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ์ํฌํ๋ก ์์ฑ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
Python๊ณผ pip์ ๋ํ ๊ธฐ๋ณธ ํ์ต์ ์ ํํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ๋ค์์ ์ฐธ์กฐํ์ธ์.
GitHub Enterprise Server์์ ์์ฒด ํธ์คํ ์คํ๊ธฐ ์ฌ์ฉ
์คํ๊ธฐ๋ฅผ ์์ฒด ํธ์คํ
ํ๋ GitHub Enterprise Server์์ actions/setup-LANGUAGE
๊ฐ์ ์ค์ ์์
์ ์ฌ์ฉํ ๊ฒฝ์ฐ ์ธํฐ๋ท์ ์ก์ธ์คํ ์ ์๋ ์คํ๊ธฐ์์ ๋๊ตฌ ์บ์๋ฅผ ์ค์ ํด์ผ ํ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ์ธํฐ๋ท์ ์ก์ธ์คํ ์ ์๋ ์์ฒด ํธ์คํ
์คํ๊ธฐ์์ ๋๊ตฌ ์บ์ ์ค์ ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
Python ์ํฌํ๋ก ํ ํ๋ฆฟ ์ฌ์ฉ
๋น ๋ฅด๊ฒ ์์ํ๋ ค๋ฉด ์ํฌํ๋ก ํ
ํ๋ฆฟ์ ๋ฆฌํฌ์งํ ๋ฆฌ์ .github/workflows
๋๋ ํฐ๋ฆฌ์ ์ถ๊ฐํฉ๋๋ค.
GitHub์(๋) ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ด๋ฏธ ํ๋ ์ด์์ .py
ํ์ผ์ด ์๋ ๊ฒฝ์ฐ์ ์๋ํด์ผ ํ๋ Python์ฉ ์ํฌํ๋ก ํ
ํ๋ฆฟ์ ์ ๊ณตํฉ๋๋ค. ์ด ๊ฐ์ด๋์ ํ์ ์น์
์์๋ ์ด ์ํฌํ๋ก ํ
ํ๋ฆฟ์ ์ฌ์ฉ์ ์ง์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์์๋ฅผ ์ ๊ณตํฉ๋๋ค.
-
GitHub์์ ๋ฆฌํฌ์งํ ๋ฆฌ์ ๊ธฐ๋ณธ ํ์ด์ง๋ก ์ด๋ํฉ๋๋ค.
-
๋ฆฌํฌ์งํ ๋ฆฌ ์ด๋ฆ ์๋์์ ์์ ์ ํด๋ฆญํฉ๋๋ค.
-
๋ฆฌํฌ์งํ ๋ฆฌ์ ์ํฌํ๋ก๊ฐ ์ด๋ฏธ ์๋ ๊ฒฝ์ฐ ์ ์ํฌํ๋ก๋ฅผ ํด๋ฆญํฉ๋๋ค.
-
"์ํฌํ๋ก ์ ํ" ํ์ด์ง์๋ ๊ถ์ฅ๋๋ ์ํฌํ๋ก ํ ํ๋ฆฟ์ ์ ํ ํญ๋ชฉ์ด ํ์๋ฉ๋๋ค. "Python ์ ํ๋ฆฌ์ผ์ด์ "์ ๊ฒ์ํฉ๋๋ค.
-
"Python ์ ํ๋ฆฌ์ผ์ด์ " ์ํฌํ๋ก์์ ๊ตฌ์ฑ์ ํด๋ฆญํฉ๋๋ค.
"Python ์ ํ๋ฆฌ์ผ์ด์ " ์ํฌํ๋ก ํ ํ๋ฆฟ์ ์ฐพ์ ์ ์๋ ๊ฒฝ์ฐ, ๋ค์ ์ํฌํ๋ก ์ฝ๋๋ฅผ ๋ฆฌํฌ์งํ ๋ฆฌ์
.github/workflows
๋๋ ํฐ๋ฆฌ์ ์๋python-app.yml
(์ด)๋ผ๋ ์ ํ์ผ์ ๋ณต์ฌํฉ๋๋ค.YAML name: Python application on: push: branches: [ "main" ] pull_request: branches: [ "main" ] permissions: contents: read jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Python 3.13 uses: actions/setup-python@v5 with: python-version: "3.13" - name: Install dependencies run: | python -m pip install --upgrade pip pip install ruff pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint and format Python code with ruff run: | # Lint with the default set of ruff rules with GitHub Annotations ruff check --format=github --target-version=py39 # Verify the code is properly formatted ruff format --diff --target-version=py39 - name: Test with pytest run: | pytest
name: Python application on: push: branches: [ "main" ] pull_request: branches: [ "main" ] permissions: contents: read jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Python 3.13 uses: actions/setup-python@v5 with: python-version: "3.13" - name: Install dependencies run: | python -m pip install --upgrade pip pip install ruff pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint and format Python code with ruff run: | # Lint with the default set of ruff rules with GitHub Annotations ruff check --format=github --target-version=py39 # Verify the code is properly formatted ruff format --diff --target-version=py39 - name: Test with pytest run: | pytest
-
ํ์์ ๋ฐ๋ผ ์ํฌํ๋ก๋ฅผ ํธ์งํฉ๋๋ค. ์๋ฅผ ๋ค์ด Python ๋ฒ์ ์ ๋ณ๊ฒฝํฉ๋๋ค.
-
๋ณ๊ฒฝ ๋ด์ฉ ์ปค๋ฐ์ ํด๋ฆญํฉ๋๋ค.
Python ๋ฒ์ ์ง์
GitHub ํธ์คํธ ์คํ๊ธฐ์์ ์ฌ์ ์ค์น๋ ๋ฒ์ ์ Python ๋๋ PyPy๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด setup-python
์์
์ ์ฌ์ฉํ์ธ์. ์ด ์์
์ ๊ฐ ์คํ๊ธฐ์ ๋๊ตฌ ์บ์์์ Node.js์ ํน์ ๋ฒ์ ์ ์ฐพ์ ํ์ ์ด์ง ํ์ผ์ PATH
์ ์ถ๊ฐํฉ๋๋ค. ์ด๋ ๋๋จธ์ง ์์
๋์ ์ ์ง๋ฉ๋๋ค. ํน์ ๋ฒ์ ์ Python์ด ๋๊ตฌ ์บ์์ ์ฌ์ ์ค์น๋์ด ์์ง ์์ผ๋ฉด setup-python
์์
์ด python-versions
๋ฆฌํฌ์งํ ๋ฆฌ์์ ์ ์ ํ ๋ฒ์ ์ ๋ค์ด๋ก๋ํ๊ณ ์ค์ ํฉ๋๋ค.
setup-python
์์
์ ์ฌ์ฉํ๋ ๊ฒ์ ๋ค์ํ ์คํ๊ธฐ ๋ฐ Python ๋ฒ์ ๊ฐ์ ์ผ๊ด๋ ๋์์ ๋ณด์ฅํ๋ฏ๋ก GitHub Actions๋ก Python์ ์ฌ์ฉํ๋ ๋ฐ ๊ถ์ฅ๋๋ ๋ฐฉ๋ฒ์
๋๋ค. ์์ฒด ํธ์คํธ ์คํ๊ธฐ๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ Python์ ์ค์นํ๊ณ ์ด๋ฅผ PATH
์ ์ถ๊ฐํด์ผ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ setup-python
์์
์ ์ฐธ์กฐํ์ธ์.
์๋ ํ ์ด๋ธ์์๋ ๊ฐ GitHubํธ์คํธ ์คํ๊ธฐ์์ ๋๊ตฌ ์บ์์ ์์น๋ฅผ ์ค๋ช ํฉ๋๋ค.
Ubuntu | Mac | Windows | |
---|---|---|---|
๋๊ตฌ ์บ์ ๋๋ ํฐ๋ฆฌ | /opt/hostedtoolcache/* | /Users/runner/hostedtoolcache/* | C:\hostedtoolcache\windows\* |
Python ๋๊ตฌ ์บ์ | /opt/hostedtoolcache/Python/* | /Users/runner/hostedtoolcache/Python/* | C:\hostedtoolcache\windows\Python\* |
PyPy ๋๊ตฌ ์บ์ | /opt/hostedtoolcache/PyPy/* | /Users/runner/hostedtoolcache/PyPy/* | C:\hostedtoolcache\windows\PyPy\* |
์์ฒด ํธ์คํ
์คํ๊ธฐ๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ setup-python
์์
์ ์ฌ์ฉํ์ฌ ์ข
์์ฑ์ ๊ด๋ฆฌํ๋๋ก ์คํ๊ธฐ๋ฅผ ๊ตฌ์ฑํ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ setup-python
์ถ๊ฐ ์ ๋ณด์์ ์์ฒด ํธ์คํธ ์คํ๊ธฐ๋ก setup-python ์ฌ์ฉ์ ์ฐธ์กฐํ์ธ์.
GitHub๋ ์๋ฏธ ์ฒด๊ณ ๋ฒ์ ๊ด๋ฆฌ ๊ตฌ๋ฌธ์ ์ง์ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ์๋ฏธ ์ฒด๊ณ ๋ฒ์ ๊ด๋ฆฌ ์ฌ์ฉ ๋ฐ ์๋ฏธ ์ฒด๊ณ ๋ฒ์ ๊ด๋ฆฌ ์ฌ์์ ์ฐธ์กฐํ์ธ์.
์ฌ๋ฌ Python ๋ฒ์ ์ฌ์ฉ
๋ค์ ์์์์๋ ์์ ์ ๋ํ ํ๋ ฌ์ ์ฌ์ฉํ์ฌ ์ฌ๋ฌ Python ๋ฒ์ ์ ์ค์ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ์ํฌํ๋ก์์ ์์ ๋ณํ ์คํ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
name: Python package on: [push] jobs: build: runs-on: ubuntu-latest strategy: matrix: python-version: ["pypy3.10", "3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} # You can test your matrix by printing the current Python version - name: Display Python version run: python -c "import sys; print(sys.version)"
name: Python package
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["pypy3.10", "3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# You can test your matrix by printing the current Python version
- name: Display Python version
run: python -c "import sys; print(sys.version)"
ํน์ Python ๋ฒ์ ์ฌ์ฉ
ํน์ ํ Python ๋ฒ์ ์ ๊ตฌ์ฑํ ์ ์์ต๋๋ค. ์: 3.12. ๋๋ ์๋ฏธ ์ฒด๊ณ ๋ฒ์ ๊ตฌ๋ฌธ์ ์ฌ์ฉํ์ฌ ์ต์ ๋ถ ๋ฆด๋ฆฌ์ค๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค. ์ด ์์์์๋ Python 3์ ์ต์ ๋ถ ๋ฆด๋ฆฌ์ค๋ฅผ ์ฌ์ฉํฉ๋๋ค.
name: Python package on: [push] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Python # This is the version of the action for setting up Python, not the Python version. uses: actions/setup-python@v5 with: # Semantic version range syntax or exact version of a Python version python-version: '3.x' # Optional - x64 or x86 architecture, defaults to x64 architecture: 'x64' # You can test your matrix by printing the current Python version - name: Display Python version run: python -c "import sys; print(sys.version)"
name: Python package
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
# This is the version of the action for setting up Python, not the Python version.
uses: actions/setup-python@v5
with:
# Semantic version range syntax or exact version of a Python version
python-version: '3.x'
# Optional - x64 or x86 architecture, defaults to x64
architecture: 'x64'
# You can test your matrix by printing the current Python version
- name: Display Python version
run: python -c "import sys; print(sys.version)"
๋ฒ์ ์ ์ธ
์ฌ์ฉํ ์ ์๋ Python ๋ฒ์ ์ ์ง์ ํ๋ฉด setup-python
์ด ##[error]Version 3.7 with arch x64 not found
์ค๋ฅ์ ํจ๊ป ์คํจํฉ๋๋ค. ์ค๋ฅ ๋ฉ์์ง์๋ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ฒ์ ์ด ํฌํจ๋ฉ๋๋ค.
์คํํ์ง ์์ผ๋ ค๋ Python ๊ตฌ์ฑ์ด ์๋ ๊ฒฝ์ฐ ์ํฌํ๋ก์์ exclude
ํค์๋๋ฅผ ์ฌ์ฉํ ์๋ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ GitHub Actions์ ๋ํ ์ํฌํ๋ก ๊ตฌ๋ฌธ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
name: Python package on: [push] jobs: build: runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: ["3.9", "3.11", "3.13", "pypy3.10"] exclude: - os: macos-latest python-version: "3.11" - os: windows-latest python-version: "3.11"
name: Python package
on: [push]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.11", "3.13", "pypy3.10"]
exclude:
- os: macos-latest
python-version: "3.11"
- os: windows-latest
python-version: "3.11"
๊ธฐ๋ณธ Python ๋ฒ์ ์ฌ์ฉ
์ข
์์ฑ์ ๋ช
์์ ์ผ๋ก ์ค์ ํ๋ ๋ฐ ๋์์ด ๋๋ฏ๋ก setup-python
์ ์ฌ์ฉํ์ฌ ์ํฌํ๋ก์์ ์ฌ์ฉ๋๋ Python ๋ฒ์ ์ ๊ตฌ์ฑํ๋ ๊ฒ์ด ์ข์ต๋๋ค. setup-python
์ ์ฌ์ฉํ์ง ์์ผ๋ฉด python
์ ํธ์ถํ ๋ PATH
์์ ์ค์ ๋ Python์ ๊ธฐ๋ณธ ๋ฒ์ ์ด ๋ชจ๋ ์
ธ์์ ์ฌ์ฉ๋ฉ๋๋ค. Python์ ๊ธฐ๋ณธ ๋ฒ์ ์ GitHub ํธ์คํธ ์คํ๊ธฐ๋ง๋ค ๋ค๋ฅด๋ฉฐ ์ด๋ก ์ธํด ์๊ธฐ์น ์์ ๋ณ๊ฒฝ์ด ๋ฐ์ํ๊ฑฐ๋ ์์๋ณด๋ค ์ด์ ๋ฒ์ ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
GitHub ํธ์คํธ ์คํ๊ธฐ | ์ค๋ช |
---|---|
Ubuntu | Ubuntu ์คํ๊ธฐ์๋ /usr/bin/python ๋ฐ /usr/bin/python3 ์ ์ค์น๋ ์ฌ๋ฌ ๋ฒ์ ์ ์์คํ
Python์ด ์์ต๋๋ค. Ubuntu์ ํจ๊ป ํจํค์ง๋ Python ๋ฒ์ ์ GitHub๊ฐ ๋๊ตฌ ์บ์์ ์ค์นํ๋ ๋ฒ์ ์ ์ถ๊ฐ๋ฉ๋๋ค. |
Windows | ๋๊ตฌ ์บ์์ ์๋ Python ๋ฒ์ ์ ์ ์ธํ๊ณ Windows์๋ ๋์ผํ ๋ฒ์ ์ ์์คํ
Python์ด ์ ๊ณต๋์ง ์์ต๋๋ค. ๋ค๋ฅธ ์คํ๊ธฐ์ ์ผ๊ด๋ ๋์์ ์ ์งํ๊ณ setup-python ์์
์์ด ์ฆ์ ์ฌ์ฉ ๊ฐ๋ฅํ Python์ ํ์ฉํ๊ธฐ ์ํด GitHub๋ ๋๊ตฌ ์บ์์ ๋ช ๊ฐ์ง ๋ฒ์ ์ PATH ์ ์ถ๊ฐํฉ๋๋ค. |
macOS | macOS ์คํ๊ธฐ์๋ ๋๊ตฌ ์บ์์ ์ผ๋ถ์ธ ๋ฒ์ ์ธ์ ๋ ์ด์์ ์์คํ
Python ๋ฒ์ ์ด ์ค์น๋์ด ์์ต๋๋ค. ์์คํ
Python ๋ฒ์ ์ /usr/local/Cellar/python/* ๋๋ ํฐ๋ฆฌ์ ์์ต๋๋ค. |
์ข ์์ฑ ์ค์น
GitHub ํธ์คํธ ์คํ๊ธฐ์๋ pip ํจํค์ง ๊ด๋ฆฌ์๊ฐ ์ค์น๋์ด ์์ต๋๋ค. ์ฝ๋๋ฅผ ๋น๋ํ๊ณ ํ
์คํธํ๊ธฐ ์ ์ pip์ ์ฌ์ฉํ์ฌ PyPI ํจํค์ง ๋ ์ง์คํธ๋ฆฌ์์ ์ข
์์ฑ์ ์ค์นํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ์๋ YAML์ pip
ํจํค์ง ์ค์น ํ๋ก๊ทธ๋จ๊ณผ setuptools
๋ฐ wheel
ํจํค์ง๋ฅผ ์ค์นํ๊ฑฐ๋ ์
๊ทธ๋ ์ด๋ํฉ๋๋ค.
์ข ์์ฑ์ ์บ์ํ์ฌ ์ํฌํ๋ก ์๋๋ฅผ ๋์ผ ์๋ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ์ข ์์ฑ ์บ์ฑ ์ฐธ์กฐ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.x' - name: Install dependencies run: python -m pip install --upgrade pip setuptools wheel
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: python -m pip install --upgrade pip setuptools wheel
์๊ตฌ ์ฌํญ ํ์ผ
pip
์ ์
๋ฐ์ดํธํ ํ ์ผ๋ฐ์ ์ธ ๋ค์ ๋จ๊ณ๋ requirements.txt
์์ ์ข
์์ฑ์ ์ค์นํ๋ ๊ฒ์
๋๋ค. ์์ธํ ๋ด์ฉ์ pip๋ฅผ ์ฐธ์กฐํ์ธ์.
steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.x' - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
์ข ์์ฑ ์บ์ฑ
setup-python
์์
์ ์ฌ์ฉํ์ฌ ์ข
์์ฑ์ ์บ์ํ๊ณ ๋ณต์ํ ์ ์์ต๋๋ค.
๋ค์ ์์์์๋ pip์ ๋ํ ์ข ์์ฑ์ ์บ์ํฉ๋๋ค.
steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: '3.12' cache: 'pip' - run: pip install -r requirements.txt - run: pip test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- run: pip install -r requirements.txt
- run: pip test
๊ธฐ๋ณธ์ ์ผ๋ก setup-python
์์
์ ์ ์ฒด ๋ฆฌํฌ์งํ ๋ฆฌ์์ ์ข
์์ฑ ํ์ผ(pip์ ๊ฒฝ์ฐ requirements.txt
, pipenv์ ๊ฒฝ์ฐ Pipfile.lock
๋๋ poetry์ ๊ฒฝ์ฐ poetry.lock
)์ ๊ฒ์ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ setup-python
์ถ๊ฐ ์ ๋ณด์์ ํจํค์ง ์ข
์์ฑ ์บ์ฑ์ ์ฐธ์กฐํ์ธ์.
์ฌ์ฉ์ ์ง์ ์๊ตฌ์ฌํญ์ด ์๊ฑฐ๋ ์บ์ฑ์ ๋ํ ์ธ๋ถ์ ์ธ ์ ์ด๊ฐ ํ์ํ ๊ฒฝ์ฐ cache
์์
์ ์ฌ์ฉํ ์ ์์ต๋๋ค. pip๋ ์คํ๊ธฐ์ ์ด์ ์ฒด์ ์ ๋ฐ๋ผ ๋ค๋ฅธ ์์น์ ์ข
์์ฑ์ ์บ์ํฉ๋๋ค. ์บ์ํด์ผ ํ๋ ๊ฒฝ๋ก๋ ์ฌ์ฉํ๋ ์ด์ ์ฒด์ ์ ๋ฐ๋ผ ์์ Ubuntu ์์์ ๋ค๋ฅผ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ cache
์์
๋ฆฌํฌ์งํ ๋ฆฌ์์ Python ์บ์ฑ ์์๋ฅผ ์ฐธ์กฐํ์ธ์.
์ฝ๋ ํ ์คํธ
์ฝ๋๋ฅผ ๋น๋ํ๊ณ ํ ์คํธํ๊ธฐ ์ํด ๋ก์ปฌ์์ ์ฌ์ฉํ๋ ๊ฒ๊ณผ ๋์ผํ ๋ช ๋ น์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
pytest ๋ฐ pytest-cov๋ฅผ ์ฌ์ฉํ์ฌ ํ ์คํธ
์ ์์pytest``pytest-cov
๊ทธ๋ฐ ๋ค์ ํ
์คํธ๊ฐ ์คํ๋์ด JUnit ํ์์ผ๋ก ์ถ๋ ฅ๋๊ณ ์ฝ๋ ๊ฒ์ฌ ๊ฒฐ๊ณผ๋ Cobertura๋ก ์ถ๋ ฅ๋ฉ๋๋ค. ์์ธํ ๋ด์ฉ์ JUnit ๋ฐ Cobertura๋ฅผ ์ฐธ์กฐํ์ธ์.
steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.x' - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt - name: Test with pytest run: | pip install pytest pytest-cov pytest tests.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest tests.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
Ruff๋ฅผ ์ฌ์ฉํ์ฌ ์ฝ๋ ๋ฆฐํ ๋ฐ/๋๋ ์์ ์ง์
๋ค์ ์์์์๋ ruff
์(๋ฅผ) ์ค์นํ๊ฑฐ๋ ์
๊ทธ๋ ์ด๋ํ๊ณ ์ด๋ฅผ ์ฌ์ฉํ์ฌ ๋ชจ๋ ํ์ผ์ ๋ฆฐํธํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ Ruff๋ฅผ ์ฐธ์กฐํ์ธ์.
steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.x' - name: Install the code linting and formatting tool Ruff run: pipx install ruff - name: Lint code with Ruff run: ruff check --output-format=github --target-version=py39 - name: Check code formatting with Ruff run: ruff format --diff --target-version=py39 continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install the code linting and formatting tool Ruff
run: pipx install ruff
- name: Lint code with Ruff
run: ruff check --output-format=github --target-version=py39
- name: Check code formatting with Ruff
run: ruff format --diff --target-version=py39
continue-on-error: true
์์ ์ง์ ๋จ๊ณ๊ฐ continue-on-error: true
์ค์ ๋์์ต๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ์์ ์ง์ ๋จ๊ณ๊ฐ ์ฑ๊ณตํ์ง ๋ชปํ ๊ฒฝ์ฐ ์ํฌํ๋ก๊ฐ ์คํจํ์ง ์์ต๋๋ค. ๋ชจ๋ ์์ ์ง์ ์ค๋ฅ๋ฅผ ํด๊ฒฐํ์ผ๋ฉด ์ํฌํ๋ก๊ฐ ์ ๋ฌธ์ ๋ฅผ catchํ ์ ์๋๋ก ํด๋น ์ต์
์ ์ ๊ฑฐํ ์ ์์ต๋๋ค.
tox๋ฅผ ์ฌ์ฉํ์ฌ ํ ์คํธ ์คํ
GitHub Actions๋ฅผ ์ฌ์ฉํ๋ฉด tox๋ก ํ
์คํธ๋ฅผ ์คํํ๊ณ ์ฌ๋ฌ ์์
์ ์์
์ ๋ถ์ฐํ ์ ์์ต๋๋ค. ํน์ ๋ฒ์ ์ ์ง์ ํ๋ ๋์ PATH
์์ Python ๋ฒ์ ์ ์ ํํ๋ ค๋ฉด -e py
์ต์
์ ์ฌ์ฉํ์ฌ tox๋ฅผ ํธ์ถํด์ผ ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ tox๋ฅผ ์ฐธ์กฐํ์ธ์.
name: Python package on: [push] jobs: build: runs-on: ubuntu-latest strategy: matrix: python: ["3.9", "3.11", "3.13"] steps: - uses: actions/checkout@v4 - name: Setup Python uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} - name: Install tox and any other packages run: pip install tox - name: Run tox # Run tox using the version of Python in `PATH` run: tox -e py
name: Python package
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.9", "3.11", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install tox and any other packages
run: pip install tox
- name: Run tox
# Run tox using the version of Python in `PATH`
run: tox -e py
์ํฌํ๋ก ๋ฐ์ดํฐ๋ฅผ ์ํฐํฉํธ๋ก ํจํค์ง
์ํฌํ๋ก๊ฐ ์๋ฃ๋ ํ ๋ณผ ์ํฐํฉํธ๋ฅผ ์ ๋ก๋ํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด ๋ก๊ทธ ํ์ผ, ์ฝ์ด ๋คํ, ํ ์คํธ ๊ฒฐ๊ณผ ๋๋ ์คํฌ๋ฆฐ์ท์ ์ ์ฅํด์ผ ํ ์ ์์ต๋๋ค. ์์ธํ ๋ด์ฉ์ ์ํฌํ๋ก ์ํฐํฉํธ์ ๋ฐ์ดํฐ ์ ์ฅ ๋ฐ ๊ณต์ ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
๋ค์ ์์๋ upload-artifact
์์
์ ์ฌ์ฉํ์ฌ pytest
์คํ์ ํ
์คํธ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๊ดํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค. ์์ธํ ๋ด์ฉ์ upload-artifact
์์
์ ์ฐธ์กฐํ์ธ์.
name: Python package on: [push] jobs: build: runs-on: ubuntu-latest strategy: matrix: python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 - name: Setup Python # Set Python version uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} # Install pip and pytest - name: Install dependencies run: | python -m pip install --upgrade pip pip install pytest - name: Test with pytest run: pytest tests.py --doctest-modules --junitxml=junit/test-results-${{ matrix.python-version }}.xml - name: Upload pytest test results uses: actions/upload-artifact@v3 with: name: pytest-results-${{ matrix.python-version }} path: junit/test-results-${{ matrix.python-version }}.xml # Use always() to always run this step to publish test results when there are test failures if: ${{ always() }}
name: Python package
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Setup Python # Set Python version
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Install pip and pytest
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
- name: Test with pytest
run: pytest tests.py --doctest-modules --junitxml=junit/test-results-${{ matrix.python-version }}.xml
- name: Upload pytest test results
uses: actions/upload-artifact@v3
with:
name: pytest-results-${{ matrix.python-version }}
path: junit/test-results-${{ matrix.python-version }}.xml
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
PyPI์ ๊ฒ์
CI ํ ์คํธ๋ฅผ ํต๊ณผํ๋ฉด Python ํจํค์ง๋ฅผ PyPI์ ๊ฒ์ํ๋๋ก ์ํฌํ๋ก๋ฅผ ๊ตฌ์ฑํ ์ ์์ต๋๋ค. ์ด ์น์ ์์๋ ๋ฆด๋ฆฌ์ค๋ฅผ ๊ฒ์ํ ๋๋ง๋ค GitHub Actions๋ฅผ ์ฌ์ฉํ์ฌ PyPI์ ํจํค์ง๋ฅผ ์ ๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค. ์์ธํ ๋ด์ฉ์ ๋ฆฌํฌ์งํ ๋ฆฌ์์ ๋ฆด๋ฆฌ์ค ๊ด๋ฆฌ์(๋ฅผ) ์ฐธ์กฐํ์ธ์.
์๋ ์์ ์ํฌํ๋ก์์๋ ์ ๋ขฐํ ์ ์๋ ๊ฒ์๋ฅผ ์ฌ์ฉํ์ฌ PyPI๋ฅผ ์ธ์ฆํ๋ฏ๋ก ์๋์ผ๋ก ๊ตฌ์ฑ๋ API ํ ํฐ์ด ํ์ํ์ง ์์ต๋๋ค.
# ์ด ์ํฌํ๋ก๋ GitHub์์ ์ธ์ฆ๋์ง ์์ ์์ ์ ์ฌ์ฉํฉ๋๋ค. # ์์ ์ ํ์ฌ์์ ์ ๊ณตํ๋ฉฐ # ๋ณ๋์ ์๋น์ค ์ฝ๊ด, ๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ, ์ง์ ์ค๋ช ์์์ ๊ท์ ๋ฉ๋๋ค. # ์ฐธ์กฐํ์ธ์. # ์ปค๋ฐ SHA์ ์์ ์ ๊ณ ์ ํ๋ ๊ฒ์ด ์ข์ต๋๋ค. # ์ต์ ๋ฒ์ ์ ์ป์ผ๋ ค๋ฉด SHA๋ฅผ ์ ๋ฐ์ดํธํด์ผ ํฉ๋๋ค. # ํ๊ทธ ๋๋ ๋ถ๊ธฐ๋ฅผ ์ฐธ์กฐํ ์๋ ์์ง๋ง ๊ฒฝ๊ณ ์์ด ์์ ์ด ๋ณ๊ฒฝ๋ ์ ์์ต๋๋ค. name: Upload Python Package on: release: types: [published] permissions: contents: read jobs: release-build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: "3.x" - name: Build release distributions run: | # NOTE: put your own distribution build steps here. python -m pip install build python -m build - name: Upload distributions uses: actions/upload-artifact@v3 with: name: release-dists path: dist/ pypi-publish: runs-on: ubuntu-latest needs: - release-build permissions: # IMPORTANT: this permission is mandatory for trusted publishing id-token: write # Dedicated environments with protections for publishing are strongly recommended. environment: name: pypi # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status: # url: https://pypi.org/p/YOURPROJECT steps: - name: Retrieve release distributions uses: actions/download-artifact@v3 with: name: release-dists path: dist/ - name: Publish release distributions to PyPI uses: pypa/gh-action-pypi-publish@6f7e8d9c0b1a2c3d4e5f6a7b8c9d0e1f2a3b4c5d
# ์ด ์ํฌํ๋ก๋ GitHub์์ ์ธ์ฆ๋์ง ์์ ์์
์ ์ฌ์ฉํฉ๋๋ค.
# ์์
์ ํ์ฌ์์ ์ ๊ณตํ๋ฉฐ
# ๋ณ๋์ ์๋น์ค ์ฝ๊ด, ๊ฐ์ธ์ ๋ณด์ฒ๋ฆฌ๋ฐฉ์นจ, ์ง์ ์ค๋ช
์์์ ๊ท์ ๋ฉ๋๋ค.
# ์ฐธ์กฐํ์ธ์.
# ์ปค๋ฐ SHA์ ์์
์ ๊ณ ์ ํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
# ์ต์ ๋ฒ์ ์ ์ป์ผ๋ ค๋ฉด SHA๋ฅผ ์
๋ฐ์ดํธํด์ผ ํฉ๋๋ค.
# ํ๊ทธ ๋๋ ๋ถ๊ธฐ๋ฅผ ์ฐธ์กฐํ ์๋ ์์ง๋ง ๊ฒฝ๊ณ ์์ด ์์
์ด ๋ณ๊ฒฝ๋ ์ ์์ต๋๋ค.
name: Upload Python Package
on:
release:
types: [published]
permissions:
contents: read
jobs:
release-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Build release distributions
run: |
# NOTE: put your own distribution build steps here.
python -m pip install build
python -m build
- name: Upload distributions
uses: actions/upload-artifact@v3
with:
name: release-dists
path: dist/
pypi-publish:
runs-on: ubuntu-latest
needs:
- release-build
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
# Dedicated environments with protections for publishing are strongly recommended.
environment:
name: pypi
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
# url: https://pypi.org/p/YOURPROJECT
steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v3
with:
name: release-dists
path: dist/
- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@6f7e8d9c0b1a2c3d4e5f6a7b8c9d0e1f2a3b4c5d