Skip to content

Commit 2aa6e58

Browse files
committed
CI updates for linting, testing & publishing package
1 parent c60cd13 commit 2aa6e58

File tree

5 files changed

+179
-1
lines changed

5 files changed

+179
-1
lines changed

.bumpversion.cfg

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[bumpversion]
2+
current_version = 0.3.0
3+
commit = True
4+
tag = True
5+
6+
[bumpversion:file:setup.py]
7+
search = version="{current_version}"
8+
replace = version="{new_version}"
9+
10+
[bumpversion:file:stagehand/__init__.py]
11+
search = __version__ = "{current_version}"
12+
replace = __version__ = "{new_version}"

.github/README_PUBLISHING.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Publishing stagehand-python to PyPI
2+
3+
This repository is configured with a GitHub Actions workflow to automate the process of publishing new versions to PyPI.
4+
5+
## Prerequisites
6+
7+
Before using the publishing workflow, ensure you have:
8+
9+
1. Set up the following secrets in your GitHub repository settings:
10+
- `PYPI_USERNAME`: Your PyPI username
11+
- `PYPI_API_TOKEN`: Your PyPI API token (not your password)
12+
13+
## How to Publish a New Version
14+
15+
### Manual Trigger
16+
17+
1. Go to the "Actions" tab in your GitHub repository
18+
2. Select the "Publish to PyPI" workflow from the list
19+
3. Click "Run workflow" on the right side
20+
4. Configure the workflow:
21+
- Choose the release type:
22+
- `patch` (e.g., 0.3.0 → 0.3.1) for bug fixes
23+
- `minor` (e.g., 0.3.0 → 0.4.0) for backward-compatible features
24+
- `major` (e.g., 0.3.0 → 1.0.0) for breaking changes
25+
- Toggle "Create GitHub Release" if you want to create a GitHub release
26+
5. Click "Run workflow" to start the process
27+
28+
### What Happens During Publishing
29+
30+
The workflow will:
31+
32+
1. Checkout the repository
33+
2. Set up Python environment
34+
3. Install dependencies
35+
4. **Run Ruff linting checks**:
36+
- Checks for code style and quality issues
37+
- Verifies formatting according to project standards
38+
- Fails the workflow if issues are found
39+
5. Run tests to ensure everything works
40+
6. Update the version number using bumpversion
41+
7. Build the package
42+
8. Upload to PyPI
43+
9. Push the version bump commit and tag
44+
10. Create a GitHub release (if selected)
45+
46+
## Code Quality Standards
47+
48+
This project uses Ruff for linting and formatting. The workflow enforces these standards before publishing:
49+
50+
- Style checks following configured rules in `pyproject.toml`
51+
- Format verification without making changes
52+
- All linting issues must be fixed before a successful publish
53+
54+
To run the same checks locally:
55+
```bash
56+
# Install Ruff
57+
pip install ruff
58+
59+
# Run linting
60+
ruff check .
61+
62+
# Check formatting
63+
ruff format --check .
64+
65+
# Auto-fix issues where possible
66+
ruff check --fix .
67+
ruff format .
68+
69+
# Use Black to format the code
70+
black .
71+
```
72+
73+
## Troubleshooting
74+
75+
If the workflow fails, check the following:
76+
77+
1. **Linting errors**: Fix any issues reported by Ruff
78+
2. Ensure all secrets are properly set
79+
3. Verify that tests pass locally
80+
4. Check if you have proper permissions on the repository
81+
5. Make sure you have a PyPI account with publishing permissions

.github/workflows/publish.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release_type:
7+
description: 'Release type (patch, minor, major)'
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
create_release:
16+
description: 'Create GitHub Release'
17+
required: true
18+
default: true
19+
type: boolean
20+
21+
jobs:
22+
build-and-publish:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Check out repository
26+
uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Set up Python
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: '3.10'
34+
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install build twine wheel setuptools bumpversion ruff
39+
pip install -r requirements.txt
40+
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
41+
42+
- name: Run Ruff linting
43+
run: |
44+
# Run Ruff linter
45+
ruff check .
46+
47+
# Run Ruff formatter check (without modifying files)
48+
ruff format --check .
49+
50+
- name: Run tests
51+
run: |
52+
pytest
53+
54+
- name: Update version
55+
run: |
56+
git config --local user.email "[email protected]"
57+
git config --local user.name "GitHub Action"
58+
bumpversion ${{ github.event.inputs.release_type }}
59+
60+
- name: Build package
61+
run: |
62+
python -m build
63+
64+
- name: Upload to PyPI
65+
env:
66+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
67+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
68+
run: |
69+
twine upload dist/*
70+
71+
- name: Push version bump
72+
run: |
73+
git push
74+
git push --tags
75+
76+
- name: Create GitHub Release
77+
if: ${{ github.event.inputs.create_release == 'true' }}
78+
uses: softprops/action-gh-release@v1
79+
with:
80+
tag_name: v$(python setup.py --version)
81+
name: Release v$(python setup.py --version)
82+
generate_release_notes: true

examples/example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ async def main():
8686
if len(observed) > 0:
8787
element = observed[0]
8888
console.print("✅ [success]Found element:[/] News button")
89+
console.print(f"\n▶️ [highlight] Performing action on observed element")
8990
await page.act(element)
91+
console.print("✅ [success]Performing Action:[/] Action completed successfully")
92+
9093
else:
9194
console.print("❌ [error]No element found[/]")
9295

stagehand/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .client import Stagehand
22

3-
__version__ = "0.1.0"
3+
__version__ = "0.3.0"
44
__all__ = ["Stagehand"]

0 commit comments

Comments
 (0)