From 4173feaf222114fd943e2c129c9f77ee5d348c27 Mon Sep 17 00:00:00 2001 From: Adil Hafeez Date: Tue, 23 Dec 2025 19:00:41 -0800 Subject: [PATCH] publish to gh --- .github/workflows/publish-plano-cli.yml | 102 ++++++++++++++++++++++++ arch/tools/publish_cli.sh | 98 +++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 .github/workflows/publish-plano-cli.yml create mode 100755 arch/tools/publish_cli.sh diff --git a/.github/workflows/publish-plano-cli.yml b/.github/workflows/publish-plano-cli.yml new file mode 100644 index 00000000..2996fda7 --- /dev/null +++ b/.github/workflows/publish-plano-cli.yml @@ -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 diff --git a/arch/tools/publish_cli.sh b/arch/tools/publish_cli.sh new file mode 100755 index 00000000..5da164c7 --- /dev/null +++ b/arch/tools/publish_cli.sh @@ -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