-
Notifications
You must be signed in to change notification settings - Fork 0
Add GitHub Actions workflow to publish to PyPI #52
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,53 @@ | ||
| name: Publish to PyPI | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ">=3.11" | ||
|
|
||
| - name: Install build dependencies | ||
| run: pip install build twine | ||
|
|
||
| - name: Validate version matches tag | ||
| run: | | ||
| TAG_VERSION="${GITHUB_REF_NAME#v}" | ||
| PKG_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])") | ||
| if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then | ||
| echo "::error::Tag version ($TAG_VERSION) does not match package version ($PKG_VERSION)" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Build sdist and wheel | ||
| run: python -m build | ||
|
|
||
| - name: Verify distributions | ||
| run: twine check dist/* | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: dist | ||
| path: dist/ | ||
|
|
||
| publish: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| environment: pypi | ||
| permissions: | ||
| id-token: write | ||
| actions: read | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: dist | ||
| path: dist/ | ||
toddysm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - uses: pypa/gh-action-pypi-publish@release/v1 | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,7 +1,59 @@ | ||
| # Setting Up Your Environment | ||
| # Contributing to RegShape | ||
|
|
||
| ## Setting Up Visual Studio Code | ||
| ## Setting Up Your Environment | ||
|
|
||
| ### Setting Up Visual Studio Code | ||
| Create an `.env` file in the root directory of the project and add the following: | ||
| ``` | ||
| PYTHONPATH=<your_workspace_folder_path>/src | ||
| ``` | ||
| ``` | ||
|
|
||
| ## Releasing | ||
|
|
||
| ### Version Tagging Convention | ||
|
|
||
| Release tags follow the format `vX.Y.Z` (e.g., `v0.1.0`, `v1.0.0`). The version | ||
| in the tag **must** match the `version` field in `pyproject.toml`. | ||
|
|
||
| ### How to Create a Release | ||
|
|
||
| 1. Update the `version` field in `pyproject.toml` to the new version. | ||
| 2. Commit the version bump: `git commit -am "Bump version to X.Y.Z"`. | ||
| 3. Push the commit to `main`. | ||
| 4. Create a GitHub Release: | ||
| - Go to **Releases** → **Draft a new release**. | ||
| - Create a new tag `vX.Y.Z` targeting `main`. | ||
| - Add release notes describing the changes. | ||
| - Click **Publish release**. | ||
| 5. The `publish.yml` workflow runs automatically, building and publishing the | ||
| package to PyPI. | ||
|
|
||
| ### What the Workflow Does | ||
|
|
||
| The `publish.yml` GitHub Actions workflow: | ||
|
|
||
| 1. **Build** — Checks out the code, validates the tag version matches | ||
| `pyproject.toml`, builds sdist and wheel distributions, and verifies them | ||
| with `twine check`. | ||
| 2. **Publish** — Downloads the build artifacts and publishes to PyPI using | ||
| trusted publishing (OIDC). | ||
|
|
||
| ### Verifying the Published Package | ||
|
|
||
| After the workflow completes, verify the package at | ||
| https://pypi.org/project/regshape/. You can also install it with: | ||
|
|
||
| ``` | ||
| pip install regshape==X.Y.Z | ||
| ``` | ||
|
|
||
| ### Trusted Publishing Setup (One-Time) | ||
|
|
||
| PyPI trusted publishing must be configured once by the repository owner: | ||
|
|
||
| 1. On [PyPI](https://pypi.org/), go to **Account** → **Publishing** → **Add a | ||
| new pending publisher**. | ||
| 2. Fill in: Owner = `toddysm`, Repository = `regshape`, Workflow = `publish.yml`, | ||
| Environment = `pypi`. | ||
| 3. On GitHub, create an environment named `pypi` under **Settings** → | ||
| **Environments**. Optionally add required reviewers for an approval gate. |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.