TestPyPi 에 업로드PyPi 에 업로드이것은 GitHub Actions CI/CD 워크 플로를 사용하여 Python 패키지를 TestPyPI 및 PYPI에 테스트, 빌드 및 업로드하는 작업 예제입니다.
이 가이드를 통해 작업 하여이 예제 패키지를 만들었습니다.
README의 나머지 부분은 같은 방식으로 새로운 프로젝트를 설정하도록 설명합니다.
설정할 때;
pip install example-package-grumbit 사용하여 설치할 수 있습니다 높은 수준에서 Pytesting을 포함한 Github CI/CD 프로젝트 포장을 설정하는 프로세스는 다음과 같습니다.
./.github/workflows/publish-to-test-pypi.yml 제외하십시오../.github/workflows/publish-to-test-pypi.yml 을 추가하고 github ci/cd 작업을 받으십시오 cd < pacakges directory >
python3 -m venv .venv # Create the venv if it doesn't exist yet
source .venv/bin/activate
python3 -m pip install --upgrade pip setuptools wheel pip-tools pytest # Install the tools needed for the build tool
python3 -m pip install --upgrade build # Install the build tool itself
python3 -m build # build the packagepython3 -m pip install --upgrade twine # Install the twine upload tool
python3 -m twine upload --repository testpypi dist/ * # Upload to TestPyPi
# When prompted, the username is __token__ and the password is the TestPyPi global scope API token패키지를 업로드 한 후 패키지 특정 API 토큰을 TestPypi에 설정하고 저장해야합니다.
패키지를 새로운 venv 에서 다운로드하여 사용할 수 있습니다.
cd < some new tmp directory >
python3 -m venv .venv
source .venv/bin/activate
package_name= " example-package-grumBit "
python3 -m pip install --index-url https://test.pypi.org/simple/ --pre ${package_name} # Check the package can be installed
python3 -c " from example_package_grumbit import example; print(example.add_one(1)) " # Check package functionspython3 -m twine upload dist/ * # Upload to PyPi
# When prompted, the username is __token__ and the password is the PyPi global scope API token[project] 섹션에서 버전을 업데이트해야하며, 다시 제작하고 업로드해야합니다. vs ./pyproject.toml
python3 -m build # build the package
python3 -m twine check dist/ * # check the package can be uploaded
python3 -m twine upload --repository testpypi dist/ * # test uploading using TestPyPi
python3 -m twine upload dist/ * # Upload to PyPi
cd " <the project's directory> "
repo_name= " <the new repo's name> "
gh repo create " ${repo_name} " --private
git init
git add --all
git commit -m " init "
git branch -M master
git remote add origin [email protected]:grumBit/ ${repo_name} .git
git push -u origin master 기본 분기가 master 아닌 경우 github에서 변경하거나 .github/workflows/publish-to-test-pypi.yml 변경하십시오.
REPO에 TestPypi 및 PYPI API 토큰을 추가하십시오.
gh browse 사용하여 GitHub에서 레포를 엽니 다. 브라우저에서 Settings -> Secrets -> Actions 클릭하십시오. 그런 다음 위의 패키지를 업로드 한 후 생성 된 API 토큰으로 PYPI_API_TOKEN 및 TEST_PYPI_API_TOKEN 이라는 두 가지 새로운 비밀을 추가하십시오.
.github/Workflows/Publish-to-test-pypi.yml 워크 플로 정의를 작성하고 구성합니다
publish-to-test-pypi.yml 이미 자동 테스트에 필요한 부품이 포함되어 있습니다 (아래 참조).TestPyPi 에 업로드master 브랜치에 커밋 될 때마다 Github CI/CD가 실행됩니다.TestPyPi 에 업로드됩니다PyPi 에 업로드커밋에 태그를 넣고 밀면 Github CI/CD가 실행되고 PYPI 릴리스가 생성됩니다.
다음을 사용하여 ./pyproject.toml 에 현재 구성된 버전으로 마지막 커밋 (예 : HEAD )을 태그하십시오.
version_tag=v $( cat ./pyproject.toml | egrep " ^version " | cut -d ' " ' -f2 )
version_tag_info= " Some release info "
git tag -a " ${version_tag} " -m " ${version_tag_info} "
git push --tagversion_tag= " vX.X.X "
version_tag_info= " Some release info "
commit_sha= " 16fb0fd "
git tag -a " ${version_tag} " " ${commit_sha} " -m " ${version_tag_info} "
git push --tag - name : Install requirements
run : >-
python -m
pip install
--requirement requirements.txt
- name : Run tests
run : >-
python -m
pytest__init__.py 가 src/ 에 추가되어야한다는 것을 의미했으며 다음과 같은 tests/ 디렉토리;src/ 트리 내에 test/ 폴더를 포함시키는 것보다 덜 편리하다고 생각합니다. ./pyproject.toml 구성하여 임베디드 test/ 폴더가 제외되도록 구성 할 수 있지만 현재 "표준"과 함께 갔다. packaging_tutorial/
├── src/
│ ├── __init__.py
│ └── example_package_grumbit/
│ ├── __init__.py
│ └── example.py
└── tests/
├── __init__.py
└── example_package_grumbit/
├── __init__.py
└── test_example.py