diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 72a206a..182da3e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,44 +2,24 @@ name: Publish to PyPI on: push: - branches: [main] + tags: + - 'v*' jobs: publish: runs-on: ubuntu-latest + permissions: + contents: write + id-token: write steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.11' - - name: Get version from pyproject.toml - id: get_version - run: | - VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') - echo "version=v$VERSION" >> $GITHUB_OUTPUT - - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ steps.get_version.outputs.version }} - release_name: Release ${{ steps.get_version.outputs.version }} - body: | - ## What's Changed - ${{ github.event.head_commit.message }} - - **Full Changelog**: https://github.com/${{ github.repository }}/commits/${{ steps.get_version.outputs.version }} - draft: false - prerelease: false - - name: Install build dependencies run: | python -m pip install --upgrade pip @@ -48,6 +28,21 @@ jobs: - name: Build package run: python -m build + - name: Extract changelog + id: changelog + run: | + VERSION=${GITHUB_REF#refs/tags/v} + CHANGELOG=$(awk '/## \['$VERSION'\]/,/## \[/' CHANGELOG.md | sed '$d' | tail -n +2) + echo "content<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + body: ${{ steps.changelog.outputs.content }} + generate_release_notes: false + - name: Publish to PyPI env: TWINE_USERNAME: __token__