diff --git a/.github/workflows/pr-preview-publish.yml b/.github/workflows/pr-preview-publish.yml index 872e2a1b..47afe498 100644 --- a/.github/workflows/pr-preview-publish.yml +++ b/.github/workflows/pr-preview-publish.yml @@ -5,6 +5,7 @@ on: types: [opened, synchronize, reopened] paths: - 'packages/miro-api/**' + - 'packages/miro-api-python/**' permissions: contents: read @@ -139,3 +140,135 @@ jobs: body: commentBody }); } + + publish-python-preview: + runs-on: ubuntu-latest + # Only run for non-fork PRs + if: github.event.pull_request.head.repo.full_name == github.repository + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install Poetry + run: | + curl -sSL https://install.python-poetry.org | python3 - + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: Calculate preview version + id: version + run: | + BASE_VERSION=$(poetry version -s) + SHORT_SHA=$(git rev-parse --short HEAD) + PREVIEW_VERSION="${BASE_VERSION}.dev${{ github.event.pull_request.number }}+${SHORT_SHA}" + echo "preview_version=${PREVIEW_VERSION}" >> $GITHUB_OUTPUT + echo "Preview version: ${PREVIEW_VERSION}" + working-directory: packages/miro-api-python + + - name: Update version in pyproject.toml + run: poetry version ${{ steps.version.outputs.preview_version }} + working-directory: packages/miro-api-python + + - name: Build package + run: poetry build + working-directory: packages/miro-api-python + + - name: Upload package artifacts + uses: actions/upload-artifact@v4 + with: + name: python-preview-package-pr${{ github.event.pull_request.number }} + path: packages/miro-api-python/dist/* + retention-days: 30 + + - name: Comment on PR + uses: actions/github-script@v7 + continue-on-error: true + with: + script: | + const previewVersion = '${{ steps.version.outputs.preview_version }}'; + const runId = '${{ github.run_id }}'; + const artifactName = 'python-preview-package-pr${{ github.event.pull_request.number }}'; + + const commentBody = `## 🐍 Python Preview Package Built + + A preview version of \`miro-api\` Python package has been built and is available for testing. + + **Preview Version:** \`${previewVersion}\` + + ### Installation Instructions + + #### Option 1: Download and Install from Artifacts (Recommended) + + 1. **Download the package files:** + - Go to the [workflow run artifacts](https://github.com/${{ github.repository }}/actions/runs/${runId}) + - Download the \`${artifactName}\` artifact + - Extract the ZIP file to get the \`.whl\` and \`.tar.gz\` files + + 2. **Install the wheel file:** + \`\`\`bash + pip install miro_api-${previewVersion}-py3-none-any.whl + \`\`\` + + Or install from the source distribution: + \`\`\`bash + pip install miro_api-${previewVersion}.tar.gz + \`\`\` + + #### Option 2: Direct Installation with GitHub CLI + + If you have GitHub CLI installed: + + \`\`\`bash + # Download artifact + gh run download ${runId} -n ${artifactName} + + # Install the wheel + pip install miro_api-${previewVersion}-py3-none-any.whl + \`\`\` + + #### Option 3: Install with Poetry + + \`\`\`bash + # Download the wheel file first, then: + poetry add ./miro_api-${previewVersion}-py3-none-any.whl + \`\`\` + + --- + + ⚠️ **This is a preview package for testing purposes only.** It will not affect the production package on PyPI. + + 📦 **Artifact Name:** \`${artifactName}\` + 🔗 **Download:** [View workflow artifacts](https://github.com/${{ github.repository }}/actions/runs/${runId})`; + + // Find existing Python comment + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + const botComment = comments.find(comment => + comment.user.type === 'Bot' && + comment.body.includes('Python Preview Package Published') + ); + + if (botComment) { + // Update existing comment + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: commentBody + }); + } else { + // Create new comment + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: commentBody + }); + } diff --git a/packages/miro-api-python/README.md b/packages/miro-api-python/README.md index 3867881d..879ee050 100644 --- a/packages/miro-api-python/README.md +++ b/packages/miro-api-python/README.md @@ -33,6 +33,76 @@ pip install miro_api poetry add miro_api ``` +## Testing Preview Packages + +When a pull request is opened with changes to this library, a preview version is automatically built and made available as a workflow artifact. This allows you to test changes before they're merged and released to PyPI. + +### How to Test a Preview Package + +1. **Find the preview package:** + - Navigate to the pull request you want to test + - Look for the bot comment titled **"🐍 Python Preview Package Built"** + - Note the preview version number (format: `2.2.4.dev123+abc1234`) + - Click the workflow artifacts link in the comment + +2. **Download the package:** + - Click on the artifact name to download it (e.g., `python-preview-package-pr123`) + - Extract the ZIP file to get the `.whl` (wheel) and `.tar.gz` (source) files + +3. **Install the package:** + + **Using pip with wheel file (recommended):** + ```bash + pip install miro_api-2.2.4.dev123+abc1234-py3-none-any.whl + ``` + + **Using pip with source distribution:** + ```bash + pip install miro_api-2.2.4.dev123+abc1234.tar.gz + ``` + + **Using Poetry:** + ```bash + poetry add ./miro_api-2.2.4.dev123+abc1234-py3-none-any.whl + ``` + +### Alternative: Using GitHub CLI + +If you have the [GitHub CLI](https://cli.github.com/) installed, you can download artifacts directly: + +```bash +# Download the artifact (replace RUN_ID and ARTIFACT_NAME from the PR comment) +gh run download RUN_ID -n ARTIFACT_NAME + +# Install the wheel +pip install miro_api-2.2.4.dev123+abc1234-py3-none-any.whl +``` + +### Testing in a Virtual Environment + +It's recommended to test preview packages in an isolated environment: + +```bash +# Create a virtual environment +python -m venv test-env +source test-env/bin/activate # On Windows: test-env\Scripts\activate + +# Install the preview package +pip install miro_api-2.2.4.dev123+abc1234-py3-none-any.whl + +# Test your code +python your_test_script.py + +# Deactivate when done +deactivate +``` + +### Notes + +- ⚠️ Preview packages are for testing only and should not be used in production +- Artifacts are retained for 30 days +- Each PR gets its own artifact with a unique name + ## Configuration The high-level client (`Miro`) automatically loads app configuration from the following environment variables: diff --git a/packages/miro-api-python/pyproject.toml b/packages/miro-api-python/pyproject.toml index 1b61f93e..5af60206 100644 --- a/packages/miro-api-python/pyproject.toml +++ b/packages/miro-api-python/pyproject.toml @@ -27,7 +27,7 @@ flask = "^3.0.3" [tool.poetry.group.docs.dependencies] pdoc = "^14.4.0" -[project.urls] +[tool.poetry.urls] Homepage = "https://github.com/miroapp/api-clients" Issues = "https://github.com/miroapp/api-clients/issues" diff --git a/packages/miro-api/README.md b/packages/miro-api/README.md index a83ed957..eb0a745a 100644 --- a/packages/miro-api/README.md +++ b/packages/miro-api/README.md @@ -28,6 +28,7 @@ When a pull request is opened with changes to this library, a preview version is 1. Navigate to the pull request you want to test 2. Look for the bot comment titled "📦 Preview Package Published" 3. Note the preview version number (format: `2.2.4-pr123.a1cf07f`) +4. Follow the installation instructions in the PR comment ### Setting Up Access to GitHub Packages