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

Validate GitHub release on publish #325

Closed
wants to merge 2 commits into from
Closed
Changes from all 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
12 changes: 11 additions & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@ name: Publish releases to PyPI

on:
release:
types: [published, prereleased]
types: [published]

jobs:
build-and-publish:
name: Builds and publishes releases to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Get tag
id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Set up Python 3.10
uses: actions/[email protected]
with:
python-version: "3.10"
- name: Install build
run: >-
pip install build
- name: Validate tag matches Python project version
shell: python
run: |-
import tomli
with open("pyproject.toml", "rb") as f:
pyproject = tomli.load(f)
assert pyproject["project"]["version"] == "${{ steps.vars.outputs.tag }}"
Comment on lines +23 to +29
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively (and IMHO better solution), is to not set it and update it on release automatically.

Copy link
Collaborator Author

@agners agners Jun 22, 2023

Choose a reason for hiding this comment

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

Hm, so that would involve reading pyproject.toml here, setting the version and writing it back out? Or is there a better way to do this? It seems that Python build doesn't like a pyproject.toml without the version in the project section.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've implemented that in a new PR, see #326.

- name: Build
run: >-
python3 -m build
Expand Down