-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate publishing Python package on PyPI (#1580)
Adds two Tox environments that help with publishing the Python package on PyPI. - `tox -e package` can be used for linting to help detect packaging issues. - `tox -e package -- upload` allows to publish the package on PyPI. - `tox -e ensure_version_matches $GIT_TAG` verifies that the package version matches the semantic Git tag on the current commit. This is used by the GHA configuration to prevent a mismatch of tags and the version of the published package. To make publishing work, you need to add the 2 secrets `PYPI_USERNAME` and `PYPI_PASSWORD` to [Settings ➜ Secrets ➜ Actions](https://github.com/canonical/charmcraft/settings/secrets/actions) with the PyPI access token for the project, as described in the [Python packaging user guide](https://packaging.python.org/en/latest/tutorials/packaging-projects/#uploading-the-distribution-archives). ## Related - #1579 - [Is `setup.py` deprecated?](https://packaging.python.org/en/latest/discussions/setup-py-deprecated/) – _The use as a command line tool is deprecated_ Co-authored-by: Alex Lowe <alex.lowe@canonical.com>
- Loading branch information
Showing
5 changed files
with
67 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Publish | ||
|
||
on: | ||
push: | ||
tags: | ||
- '[1-9]+.[0-9]+.[0-9]+' | ||
|
||
env: | ||
PIP_DISABLE_PIP_VERSION_CHECK: '1' | ||
PY_COLORS: '1' | ||
|
||
jobs: | ||
pypi: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
- name: Install build tools | ||
run: pip install tox | ||
- name: Verify package version is same as Git tag | ||
run: tox run -qe ensure_version_matches -- $GIT_TAG | ||
env: | ||
GIT_TAG: ${{ github.ref_name }} | ||
- name: Build package and upload to PyPI | ||
run: tox run -e package -- upload | ||
env: | ||
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | ||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,7 @@ dmypy.json | |
# backups | ||
*~ | ||
/charmcraft/_version.py | ||
/results/ | ||
|
||
# Spread files | ||
.spread-reuse*.yaml |
This file contains 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
This file contains 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
This file contains 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