Publish #2
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: Publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_type: | |
| description: "Version increment type" | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| default: "patch" | |
| jobs: | |
| publish: | |
| 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 # Full history for proper tagging | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| version: "latest" | |
| - name: Set up Python | |
| run: uv python install 3.11 | |
| - name: Install dependencies | |
| run: uv sync --dev | |
| - name: Configure Git | |
| run: | | |
| git config --local user.email "[email protected]" | |
| git config --local user.name "GitHub Action" | |
| - name: Get current version | |
| id: current_version | |
| run: | | |
| CURRENT_VERSION=$(grep '^version = ' pyproject.toml | cut -d'"' -f2) | |
| echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo "Current version: $CURRENT_VERSION" | |
| - name: Calculate new version | |
| id: new_version | |
| run: | | |
| CURRENT_VERSION="${{ steps.current_version.outputs.version }}" | |
| VERSION_TYPE="${{ github.event.inputs.version_type }}" | |
| # Split version into parts | |
| IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION" | |
| MAJOR=${VERSION_PARTS[0]} | |
| MINOR=${VERSION_PARTS[1]} | |
| PATCH=${VERSION_PARTS[2]} | |
| # Increment based on type | |
| if [ "$VERSION_TYPE" = "major" ]; then | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| elif [ "$VERSION_TYPE" = "minor" ]; then | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| else | |
| PATCH=$((PATCH + 1)) | |
| fi | |
| NEW_VERSION="$MAJOR.$MINOR.$PATCH" | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "New version: $NEW_VERSION" | |
| - name: Update version in pyproject.toml | |
| run: | | |
| NEW_VERSION="${{ steps.new_version.outputs.version }}" | |
| sed -i "s/^version = .*/version = \"$NEW_VERSION\"/" pyproject.toml | |
| # Also update version in main.py if it exists | |
| if grep -q "version=" ahn_cli/main.py; then | |
| sed -i "s/@click.version_option(version=\".*\"/@click.version_option(version=\"$NEW_VERSION\"/" ahn_cli/main.py | |
| fi | |
| - name: Commit version bump | |
| run: | | |
| git add pyproject.toml ahn_cli/main.py | |
| git commit -m "chore: bump version to ${{ steps.new_version.outputs.version }}" | |
| - name: Create and push tag | |
| run: | | |
| git tag "v${{ steps.new_version.outputs.version }}" | |
| git push origin main --tags | |
| - name: Build package | |
| run: uv build | |
| - name: Publish to PyPI | |
| env: | |
| UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
| run: | | |
| uv publish | |
| - name: Generate release notes | |
| id: release_notes | |
| run: | | |
| # Get commits since last tag | |
| LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
| if [ -z "$LAST_TAG" ]; then | |
| COMMITS=$(git log --pretty=format:"- %s" HEAD) | |
| else | |
| COMMITS=$(git log --pretty=format:"- %s" "$LAST_TAG"..HEAD) | |
| fi | |
| # Create release notes | |
| cat > release_notes.md << EOF | |
| ## What's Changed | |
| ### Version bump: ${{ steps.current_version.outputs.version }} → ${{ steps.new_version.outputs.version }} | |
| ### Commits | |
| $COMMITS | |
| ### Installation | |
| \`\`\`bash | |
| pip install ahn_cli==${{ steps.new_version.outputs.version }} | |
| \`\`\` | |
| Or with uv: | |
| \`\`\`bash | |
| uv tool install ahn_cli==${{ steps.new_version.outputs.version }} | |
| \`\`\` | |
| EOF | |
| # Set output | |
| echo "notes<<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: v${{ steps.new_version.outputs.version }} | |
| name: v${{ steps.new_version.outputs.version }} | |
| body: ${{ steps.release_notes.outputs.notes }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| dist/* |