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

Hatchling packaging and UV Release workflow #641

Merged
merged 6 commits into from
Jan 12, 2025
Merged

Conversation

teocns
Copy link
Contributor

@teocns teocns commented Jan 12, 2025

Changes

  • Switch from setuptools/hatch to UV for building and publishing packages
  • Add manual testing capabilities through GitHub Actions UI or CLI
  • Implement safer publishing workflow with environment protections

Important Note About Releases ⚠️

The automatic publishing on GitHub releases remains unchanged:

  1. Create a new release in GitHub UI
  2. Publish it (not draft)
  3. Workflow automatically triggers
  4. Package publishes to PyPI after a 10-second safety delay

Testing Required

Before merging, please:

  1. Set up required secrets:

    • TEST_PYPI_API_TOKEN: Create a token at https://test.pypi.org/
    • Keep existing PYPI_API_TOKEN for production releases
  2. Test the workflow:

    # Test just building (safest)
    gh workflow run "Upload Python Package" --ref <this-branch> --field test_mode=build-only
    
    # Test with dry-run (simulates publish)
    gh workflow run "Upload Python Package" --ref <this-branch> --field test_mode=dry-run
    
    # Optional: Test publish to TestPyPI (requires TEST_PYPI_API_TOKEN)
    gh workflow run "Upload Python Package" --ref <this-branch> --field test_mode=testpypi

What's Changed

  • Build System: Using UV instead of setuptools for more modern and consistent tooling
  • Safety: Added multiple safeguards:
    • Manual runs default to dry-run mode
    • 10-second warning delay before PyPI publish
    • Environment-specific configurations
  • Testing: New options to test the publishing process without affecting PyPI
  • Security: Using OIDC-based trusted publishing
  • Documentation: Added GitHub CLI examples in workflow comments

After Merging

Your existing release process stays exactly the same:

  1. Create and publish a release in GitHub UI
  2. Workflow automatically triggers
  3. Package builds and publishes to PyPI (after 10s delay)
  4. No manual steps needed

The only visible difference will be a 10-second delay with a warning message before publishing, giving you a chance to cancel if needed.

- Replace setuptools/hatch with UV for building and publishing
- Add manual testing options via workflow_dispatch:
  - dry-run: Test without publishing
  - testpypi: Test publish to TestPyPI
  - build-only: Test just the build step
- Add safety measures:
  - Environment-specific configurations
  - Delays before publishing
  - Clear warning messages
- Add GitHub CLI usage examples in comments
- Enable trusted publishing
Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Flag Coverage Δ
unittests 37.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@teocns teocns changed the title Hatchling packaging Hatchling packaging and UV Release workflow Jan 12, 2025
Changed --repository to --publish-url for TestPyPI
Changed --dry-run to --check-url for dry run mode (this will check if
the package exists but won't upload)
Left the build-only mode unchanged as it was working correctly
Left the release mode with just --token as it uses the default PyPI URL

Signed-off-by: Teo <teocns@gmail.com>
Copy link
Contributor

@areibman areibman left a comment

Choose a reason for hiding this comment

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

Great fix Teo!

@teocns teocns merged commit 81c60c6 into main Jan 12, 2025
8 checks passed
@teocns teocns deleted the feat/hatchling-packaging branch January 12, 2025 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants