Skip to content

Attempt 2 to get dynamic versioning working with poetry #5

Attempt 2 to get dynamic versioning working with poetry

Attempt 2 to get dynamic versioning working with poetry #5

Workflow file for this run

name: Release & Publish package
on:
push:
tags:
- 'v*'
workflow_dispatch: # Allow manual triggering
permissions:
contents: read
id-token: write # For trusted publishing to PyPI
jobs:
build:
name: Build distribution packages
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true # Ensure tags are fetched
submodules: recursive
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Verify git state
run: |
git describe --tags --always --dirty
echo "Current tag: $(git describe --tags --exact-match 2>/dev/null || echo 'No exact tag')"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry
poetry self add "poetry-dynamic-versioning[plugin]"
- name: Check version detection
run: |
poetry-dynamic-versioning
poetry version
echo "Expected version from tag: ${GITHUB_REF#refs/tags/v}"
- name: Build package
run: poetry build
- name: Check distribution packages
run: |
python -m pip install twine
python -m twine check dist/*
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist-packages
path: dist/
retention-days: 7
test-install:
name: Test installation
needs: build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.10', '3.11', '3.12']
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist-packages
path: dist/
- name: Test wheel installation
run: |
python -m pip install --upgrade pip
python -m pip install dist/*.whl
python -c "import cvasl_gui; print(f'Successfully imported cvasl_gui')"
publish-to-pypi:
name: Publish to PyPI
needs: [build, test-install]
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/p/cvasl-gui
permissions:
id-token: write # mandatory for trusted publishing
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist-packages
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
create-github-release:
name: Create GitHub Release
needs: [build, test-install]
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist-packages
path: dist/
- name: Extract release notes
id: extract-notes
run: |
# Extract version from tag
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Create release notes
cat > release_notes.md << EOF
## Release $VERSION
### What's Changed
- Package built with Python 3.11
- See [CHANGELOG.md](CHANGELOG.md) for detailed changes
### Installation
\`\`\`bash
pip install cvasl-gui==$VERSION
\`\`\`
### Files
- \`cvasl_gui-$VERSION.tar.gz\` - Source distribution
- \`cvasl_gui-$VERSION-py3-none-any.whl\` - Universal wheel
EOF
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: Release v${{ steps.extract-notes.outputs.version }}
body_path: release_notes.md
files: |
dist/*.tar.gz
dist/*.whl
draft: false
prerelease: ${{ contains(github.ref, 'rc') || contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
# publish-docs:
# name: Publish documentation
# needs: build-and-test
# runs-on: ubuntu-latest
# permissions:
# contents: write
# steps:
# - name: Download the documentation
# uses: actions/download-artifact@v4
# with:
# name: docs-html
# path: docs/
# - name: Deploy
# uses: peaceiris/actions-gh-pages@v3
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: docs/