- The CI/CD pipeline is run whenever a commit is pushed up to the repo as per
.github/workflows/publish-to-test-pypi.yml
- Provided the project version in
pyproject.tomlis incremented, and the CI/CD testing passes, releases are made to TestPyPI after a commit is pushed.
-
Putting a tag on a commit and pushing it will cause the GitHub CI/CD to run and create a PyPI release.
-
Use the following to tag the lastest commit (i.e.
HEAD) with the version currently configured in./pyproject.toml;
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 --tag- Use the following to tag a prior commit;
version_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 --tagFor new projects, check this out.
Run through uploading to TestPyPI first. If it goes well, then repeat for PyPI
- Upload using TestPyPI global scope API key;
python3 -m pip install --upgrade twine # Maybe I should add twine to requirements_dev.in?
python3 -m build # ? python -m build --sdist --wheel --outdir dist/
python3 -m twine upload --repository TestPyPI dist/*
# user name = __token__
# For p/w, get "API token - Global scope" in 1Password "TestPyPI - grumBit" item -
Create a new token specifically for the project in TestPyPI;
- Head to Test PtPI ->
Managefor fullapp ->Settings->Create a token for fullapp - Set
Token nameto fullapp - Change the
Scopeto "Project: fullapp` - Click
Add Token - Add the generated token in a new password field named '🔑 API Token - "fullapp"' in the 1Password "TestPyPI - grumBit" item
- Head to Test PtPI ->
-
Test the new token by running
python3 -m pip install --upgrade twineagain, but with the new token -
Add the TestPyPI API token to GitHub
- Open the repo on github ->
Settings->Secrets and variables->Actions->New repository secret - Name = "TEST_PYPI_API_TOKEN"
- Secret = The project's API token form the 1Password "TestPyPI - grumBit" item
- Open the repo on github ->
- In a new directory, create a new python venv;
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install wheel pip-tools
python3 -m venv .venv ; source .venv/bin/activate ; pip install --upgrade pip ; pip install wheel pip-tools
- Install the new project;
package_name="fullapp"
python3 -m pip install --index-url https://test.pypi.org/simple/ --pre ${package_name} # Check the package can be installed
python3 -c "from fullapp import myapp" # Check package functions(NB: This mostly repeats the TestPyPI steps above)
- Initial upload to PyPI;
python3 -m build # Only needed if github actions has built a more recent version in TestPyPI than the last manually built one
python3 -m twine upload dist/*
# User name = __token__
# For p/w, get "API token - Global scope" in 1Password "PyPI - grumBit" item -
As per TestPyPI, setup a PyPI API token;
- Create a new PyPI API token for the project in PyPI
- Add the token into the 1Password PyPI item
- Add the token to repo in GitHub
-
Check new API token works by uploading again
python3 -m twine upload dist/* - Try installing and running in a new .venv;
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
python3 -c "from fullapp import myapp; myapp.MyApp().say('hi')"