-
Notifications
You must be signed in to change notification settings - Fork 83
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
base: master
Are you sure you want to change the base?
Conversation
Proposed way forward from a chat with @twcurrie: Action plan for this PR:
|
https://intuit.github.io/auto/ might be a useful tool for this task (although python support does not seem like a priority after a quick look) |
@twcurrie @thentgesMindee if you have a moment to take a look at this PR, it'd be great. I've tried to put together something simple to reduce friction when publishing releases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the release notes I use release drafter, but this puts the changes in the release tag and not a CHANGELOG.md
file so not exactly what you are looking for. Towncrier is one I have heard of, but have never used myself that can put the changes in a CHANGELOG.md
.
- 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 }} |
There was a problem hiding this comment.
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.
- 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 |
https://github.com/marketplace/actions/pypi-publish#trusted-publishing would recommend setting this up. The way i like to do things in terms of publishing is have it so it pushes to pypi whenever a new version in the pyproject.toml is committed to main. Could be a good first step and then use something like https://github.com/mikepenz/release-changelog-builder-action to generate change logs and releases later? name: Tag and publish client library versions
on:
push:
branches:
- main
jobs:
autotag:
permissions:
contents: 'write'
id-token: 'write'
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/slowapi
outputs:
tag-exists: ${{ steps.check-tag-exists.outcome }}
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Setup poetry
run: |
curl -sSL https://install.python-poetry.org | python3 - --version 1.5.0
export PATH=$PATH:$HOME/.local/bin
- name: Get version
run: echo "VERSION=$(poetry version | cut -d ' ' -f2)" >> $GITHUB_ENV
- name: Check tag exists for client library version
id: check-tag-exists
continue-on-error: true
run: >
git tag -l | grep v${{ env.VERSION }} || exit 1
- name: Push tag if none exists
if: ${{ steps.check-tag-exists.outcome == 'failure' }}
uses: actions/github-script@v4
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs')
github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/v${{ env.VERSION }}`,
sha: context.sha
})
- name: Build artefact
run: >
poetry build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1 |
This is a draft of what an automatic package publishing workflow could look like.
TODO:
master
branch