Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions .github/workflows/pr-preview-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
types: [opened, synchronize, reopened]
paths:
- 'packages/miro-api/**'
- 'packages/miro-api-python/**'

permissions:
contents: read
Expand Down Expand Up @@ -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
});
}
70 changes: 70 additions & 0 deletions packages/miro-api-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/miro-api-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions packages/miro-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading