fix: indent Python heredoc content in YAML #7
Workflow file for this run
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
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write # For PyPI trusted publishing | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch full history for changelog generation | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install PDM | |
| uses: pdm-project/setup-pdm@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: pdm install --dev | |
| - name: Run tests | |
| run: pdm run python -m pytest | |
| - name: Run linting | |
| run: pdm run ruff check . | |
| - name: Run type checking | |
| run: pdm run pyright | |
| - name: Build package | |
| run: pdm build | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| # Extract version from tag | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| # Try to extract changelog from CHANGELOG.md first | |
| if [ -f "CHANGELOG.md" ]; then | |
| # Look for the version section in CHANGELOG.md | |
| VERSION=$VERSION python3 << 'EOF' > release_notes.md | |
| import re | |
| import sys | |
| import os | |
| def extract_version_changelog(version): | |
| try: | |
| with open('CHANGELOG.md', 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| # Look for version section (matches [X.X.X] or [Unreleased]) | |
| version_pattern = rf'\[{re.escape(version)}\].*?(?=\n## |\n\[|$)' | |
| match = re.search(version_pattern, content, re.DOTALL | re.MULTILINE) | |
| if match: | |
| # Extract the content and clean it up | |
| section = match.group(0) | |
| # Remove the version header line | |
| lines = section.split('\n')[1:] | |
| # Remove empty lines at the start | |
| while lines and not lines[0].strip(): | |
| lines.pop(0) | |
| changelog_content = '\n'.join(lines).strip() | |
| if changelog_content: | |
| print(changelog_content) | |
| return True | |
| return False | |
| except Exception as e: | |
| print(f"Error reading CHANGELOG.md: {e}", file=sys.stderr) | |
| return False | |
| # Try to get version-specific changelog | |
| version = os.environ.get('VERSION', '0.0.0') | |
| if not extract_version_changelog(version): | |
| # If no specific version found, check for [Unreleased] | |
| if not extract_version_changelog("Unreleased"): | |
| print("## What's Changed\n\nSee CHANGELOG.md for detailed changes.") | |
| EOF | |
| fi | |
| # If CHANGELOG.md doesn't exist or doesn't have version info, generate from git | |
| if [ ! -s "release_notes.md" ]; then | |
| echo "## What's Changed" > release_notes.md | |
| echo "" >> release_notes.md | |
| # Generate changelog between current tag and previous tag | |
| PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "") | |
| if [ -n "$PREVIOUS_TAG" ]; then | |
| # Get commit messages between tags | |
| git log --pretty=format:"- %s (%h)" ${PREVIOUS_TAG}..HEAD >> release_notes.md | |
| # Get contributors | |
| echo "" >> release_notes.md | |
| echo "## Contributors" >> release_notes.md | |
| git log --pretty=format:"- @%an" ${PREVIOUS_TAG}..HEAD | sort -u >> release_notes.md | |
| else | |
| echo "- Initial release" >> release_notes.md | |
| fi | |
| fi | |
| # Read changelog content and set as output | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| cat release_notes.md >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ steps.changelog.outputs.version }} | |
| body: ${{ steps.changelog.outputs.changelog }} | |
| files: | | |
| dist/* | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://upload.pypi.org/legacy/ | |
| skip-existing: true |