-
Notifications
You must be signed in to change notification settings - Fork 68
CI updates for linting, testing & publishing package #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[bumpversion] | ||
current_version = 0.3.0 | ||
commit = True | ||
tag = True | ||
|
||
[bumpversion:file:setup.py] | ||
search = version="{current_version}" | ||
replace = version="{new_version}" | ||
|
||
[bumpversion:file:stagehand/__init__.py] | ||
search = __version__ = "{current_version}" | ||
replace = __version__ = "{new_version}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Publishing stagehand-python to PyPI | ||
|
||
This repository is configured with a GitHub Actions workflow to automate the process of publishing new versions to PyPI. | ||
|
||
## Prerequisites | ||
|
||
Before using the publishing workflow, ensure you have: | ||
|
||
1. Set up the following secrets in your GitHub repository settings: | ||
- `PYPI_USERNAME`: Your PyPI username | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don;'t think I have the access rights to set these, and would likely not want my pypi account in the secrets for this repo anyway - you want me to create a new one? or idk There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should def set up a browserbase account for this |
||
- `PYPI_API_TOKEN`: Your PyPI API token (not your password) | ||
|
||
## How to Publish a New Version | ||
|
||
### Manual Trigger | ||
|
||
1. Go to the "Actions" tab in your GitHub repository | ||
2. Select the "Publish to PyPI" workflow from the list | ||
3. Click "Run workflow" on the right side | ||
4. Configure the workflow: | ||
- Choose the release type: | ||
- `patch` (e.g., 0.3.0 → 0.3.1) for bug fixes | ||
- `minor` (e.g., 0.3.0 → 0.4.0) for backward-compatible features | ||
- `major` (e.g., 0.3.0 → 1.0.0) for breaking changes | ||
- Toggle "Create GitHub Release" if you want to create a GitHub release | ||
5. Click "Run workflow" to start the process | ||
|
||
### What Happens During Publishing | ||
|
||
The workflow will: | ||
|
||
1. Checkout the repository | ||
2. Set up Python environment | ||
3. Install dependencies | ||
4. **Run Ruff linting checks**: | ||
- Checks for code style and quality issues | ||
- Verifies formatting according to project standards | ||
- Fails the workflow if issues are found | ||
5. Run tests to ensure everything works | ||
6. Update the version number using bumpversion | ||
7. Build the package | ||
8. Upload to PyPI | ||
9. Push the version bump commit and tag | ||
10. Create a GitHub release (if selected) | ||
|
||
## Code Quality Standards | ||
|
||
This project uses Ruff for linting and formatting. The workflow enforces these standards before publishing: | ||
|
||
- Style checks following configured rules in `pyproject.toml` | ||
- Format verification without making changes | ||
- All linting issues must be fixed before a successful publish | ||
|
||
To run the same checks locally: | ||
```bash | ||
# Install Ruff | ||
pip install ruff | ||
|
||
# Run linting | ||
ruff check . | ||
|
||
# Check formatting | ||
ruff format --check . | ||
|
||
# Auto-fix issues where possible | ||
ruff check --fix . | ||
ruff format . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I currently get lots of issues running this locally? meaning, many type issues |
||
|
||
# Use Black to format the code | ||
black . | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
If the workflow fails, check the following: | ||
|
||
1. **Linting errors**: Fix any issues reported by Ruff | ||
2. Ensure all secrets are properly set | ||
3. Verify that tests pass locally | ||
4. Check if you have proper permissions on the repository | ||
5. Make sure you have a PyPI account with publishing permissions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: Publish to PyPI | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_type: | ||
description: 'Release type (patch, minor, major)' | ||
required: true | ||
default: 'patch' | ||
type: choice | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
create_release: | ||
description: 'Create GitHub Release' | ||
required: true | ||
default: true | ||
type: boolean | ||
|
||
jobs: | ||
build-and-publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build twine wheel setuptools bumpversion ruff | ||
pip install -r requirements.txt | ||
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi | ||
|
||
- name: Run Ruff linting | ||
run: | | ||
# Run Ruff linter | ||
ruff check . | ||
|
||
# Run Ruff formatter check (without modifying files) | ||
ruff format --check . | ||
|
||
- name: Run tests | ||
run: | | ||
pytest | ||
|
||
- name: Update version | ||
run: | | ||
git config --local user.email "action@github.com" | ||
git config --local user.name "GitHub Action" | ||
bumpversion ${{ github.event.inputs.release_type }} | ||
|
||
- name: Build package | ||
run: | | ||
python -m build | ||
|
||
- name: Upload to PyPI | ||
env: | ||
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | ||
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | ||
run: | | ||
twine upload dist/* | ||
|
||
- name: Push version bump | ||
run: | | ||
git push | ||
git push --tags | ||
|
||
- name: Create GitHub Release | ||
if: ${{ github.event.inputs.create_release == 'true' }} | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: v$(python setup.py --version) | ||
name: Release v$(python setup.py --version) | ||
generate_release_notes: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
# Define source directories (adjust as needed) | ||
SOURCE_DIRS="evals stagehand" | ||
|
||
# Apply Black formatting only to source directories | ||
echo "Applying Black formatting..." | ||
black $SOURCE_DIRS | ||
|
||
# Fix import sorting (addresses I001 errors) | ||
echo "Sorting imports..." | ||
isort $SOURCE_DIRS | ||
|
||
# Apply Ruff with autofix for remaining issues | ||
echo "Applying Ruff autofixes..." | ||
ruff check --fix $SOURCE_DIRS | ||
|
||
echo "Checking for remaining issues..." | ||
ruff check $SOURCE_DIRS | ||
|
||
echo "Done! Code has been formatted and linted." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea 0.3 makes sense