Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: publish release to testpypi from github actions #109

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches: [ master ]

jobs:
build:
tests:

runs-on: ubuntu-latest
strategy:
Expand All @@ -23,14 +23,17 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install build dependencies for requests in python 3.9
# it's not clear why this is needed only for this version of python
run: sudo apt-get install libxml2-dev libxslt-dev

- name: Install Poetry
uses: snok/install-poetry@v1
with:
# Version of Poetry to use
version: 1.2.2
version: 1.4.1

- name: Install dependencies
run: |
poetry install
Expand All @@ -50,3 +53,38 @@ jobs:
- name: Generate coverage report
run: |
poetry run coverage report

build-and-publish:
runs-on: ubuntu-latest
needs: tests

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install Poetry
uses: snok/install-poetry@v1
with:
# Version of Poetry to use
version: 1.4.1

- name: Build distribution tarball and wheel
# TODO: restrict this to master branch only
run: |
poetry build

- name: Publish distribution 📦 to Test PyPI
# publish to testpypi on all commit just for testing this PR
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/

- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
Comment on lines +73 to +89
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poetry can also do the publish for you. I haven't tested publishing to test pypi before, but according to the configs I found I think I have it correct.

Suggested change
- name: Build distribution tarball and wheel
# TODO: restrict this to master branch only
run: |
poetry build
- name: Publish distribution 📦 to Test PyPI
# publish to testpypi on all commit just for testing this PR
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Install Dependencies
run: |
poetry install
- name: Publish distribution 📦 to Test PyPI
# publish to testpypi on all commit just for testing this PR
run |
# I believe publishing with password is depreciated and you you need a token instead?
poetry config pypi-token.test-pypi ${{ secrets.TEST_PYPI_API_TOKEN }}
poetry config repositories.test-pypi https://test.pypi.org/legacy/
poetry publish -r test-pypi --build
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
run |
poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}
poetry publish --build

12 changes: 6 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ $ pytest

`slowapi` tries to follow [semantic versioning](https://semver.org/).

To release a new version:

- Update CHANGELOG.md
- Bump the version number in `pyproject.toml`
- `poetry build`
- `poetry publish`
Releases are published directly from CI (github actions). To create a new release:
- Update `CHANGELOG.md` and the version in `pyproject.toml`,
- Commit those changes to a new PR,
- Get the PR reviewed and merged,
- Tag the merge commit with the same version number prefixed with `v`, eg. `v0.1.6`,
- Push the tag to trigger the release.

# Credits

Expand Down