publish to gh

This commit is contained in:
Adil Hafeez 2025-12-23 19:00:41 -08:00
parent e7ce00b5a7
commit 4173feaf22
No known key found for this signature in database
GPG key ID: 9B18EF7691369645
2 changed files with 200 additions and 0 deletions

102
.github/workflows/publish-plano-cli.yml vendored Normal file
View file

@ -0,0 +1,102 @@
name: Publish Plano CLI
on:
workflow_dispatch:
inputs:
registry:
description: 'Target registry'
required: true
type: choice
options:
- pypi
- github
- both
default: 'pypi'
version:
description: 'Version to publish (leave empty to use version from pyproject.toml)'
required: false
type: string
release:
types: [published]
push:
permissions:
contents: read
packages: write
jobs:
publish:
runs-on: ubuntu-latest
defaults:
run:
working-directory: arch/tools
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Configure Poetry
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Install dependencies
run: poetry install --no-interaction
- name: Update version (if specified)
if: ${{ github.event.inputs.version != '' }}
run: |
poetry version ${{ github.event.inputs.version }}
echo "Updated version to ${{ github.event.inputs.version }}"
- name: Build package
run: poetry build
- name: Publish to PyPI
if: ${{ github.event.inputs.registry == 'pypi' || github.event.inputs.registry == 'both' || github.event_name == 'release' }}
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
run: poetry publish
- name: Publish to GitHub Packages
if: ${{ github.event.inputs.registry == 'github' || github.event.inputs.registry == 'both' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
poetry config repositories.github https://pypi.pkg.github.com/katanemo
poetry config http-basic.github __token__ $GITHUB_TOKEN
poetry publish --repository github
- name: Create release summary
run: |
VERSION=$(poetry version -s)
echo "## 📦 Package Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** $VERSION" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ github.event.inputs.registry }}" = "pypi" ] || [ "${{ github.event.inputs.registry }}" = "both" ] || [ "${{ github.event_name }}" = "release" ]; then
echo "### PyPI.org" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "pip install plano==$VERSION" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ github.event.inputs.registry }}" = "github" ] || [ "${{ github.event.inputs.registry }}" = "both" ]; then
echo "### GitHub Packages" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "pip install plano==$VERSION \\" >> $GITHUB_STEP_SUMMARY
echo " --index-url https://pypi.pkg.github.com/katanemo/simple/" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
fi

98
arch/tools/publish_cli.sh Executable file
View file

@ -0,0 +1,98 @@
#!/bin/bash
# Publishing script for plano CLI
# Supports publishing to:
# - PyPI (default)
# - GitHub Packages PyPI registry
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Parse command-line arguments
REGISTRY="pypi"
BUILD_ONLY=false
while [[ $# -gt 0 ]]; do
case $1 in
--github)
REGISTRY="github"
shift
;;
--pypi)
REGISTRY="pypi"
shift
;;
--build-only)
BUILD_ONLY=true
shift
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --pypi Publish to PyPI.org (default)"
echo " --github Publish to GitHub Packages PyPI registry"
echo " --build-only Only build the package, don't publish"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Publish to PyPI.org"
echo " $0 --github # Publish to GitHub Packages"
echo " $0 --build-only # Only build the package"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use -h or --help for usage information"
exit 1
;;
esac
done
echo "🔨 Building plano package..."
poetry build
if [ "$BUILD_ONLY" = true ]; then
echo "✅ Build complete. Package files are in dist/"
exit 0
fi
if [ "$REGISTRY" = "github" ]; then
echo "📦 Publishing to GitHub Packages PyPI registry..."
# Check for GitHub token
if [ -z "$GITHUB_TOKEN" ]; then
echo "❌ Error: GITHUB_TOKEN environment variable is not set"
echo "Please set it with: export GITHUB_TOKEN=your_github_token"
echo "Or create a token at: https://github.com/settings/tokens"
exit 1
fi
# Configure poetry to use GitHub Packages
poetry config repositories.github https://pypi.pkg.github.com/katanemo
poetry config http-basic.github __token__ "$GITHUB_TOKEN"
# Publish to GitHub Packages
poetry publish --repository github
echo "✅ Successfully published to GitHub Packages!"
echo ""
echo "Install with:"
echo " pip install plano --index-url https://pypi.pkg.github.com/katanemo/simple/"
echo ""
echo "Or with authentication:"
echo " pip install plano --index-url https://\${GITHUB_TOKEN}@pypi.pkg.github.com/katanemo/simple/"
elif [ "$REGISTRY" = "pypi" ]; then
echo "📦 Publishing to PyPI.org..."
# Publish to PyPI
poetry publish
echo "✅ Successfully published to PyPI.org!"
echo ""
echo "Install with:"
echo " pip install plano"
fi