-
Notifications
You must be signed in to change notification settings - Fork 113
139 lines (117 loc) · 4.31 KB
/
publish.yml
File metadata and controls
139 lines (117 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
permissions:
contents: write
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine wheel setuptools ruff black
pip install -r requirements.txt
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
# TODO add playwright install for CI pytest
- name: Run linting and formatting
run: |
# Run linter
black --check --diff stagehand
# Run Ruff formatter check (without modifying files)
ruff check stagehand
# TODO: add back as soon as CI is passing
# - name: Run tests
# run: |
# pytest
- name: Calculate new version
id: version
run: |
# Get current version from pyproject.toml
CURRENT_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Parse version components
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
# Calculate new version based on release type
case "${{ github.event.inputs.release_type }}" in
"major")
NEW_MAJOR=$((MAJOR + 1))
NEW_MINOR=0
NEW_PATCH=0
;;
"minor")
NEW_MAJOR=$MAJOR
NEW_MINOR=$((MINOR + 1))
NEW_PATCH=0
;;
"patch")
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION"
- name: Update version files
run: |
CURRENT_VERSION="${{ steps.version.outputs.current_version }}"
NEW_VERSION="${{ steps.version.outputs.new_version }}"
# Update pyproject.toml
sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" pyproject.toml
# Update __init__.py
sed -i "s/__version__ = \"$CURRENT_VERSION\"/__version__ = \"$NEW_VERSION\"/" stagehand/__init__.py
echo "Updated version to $NEW_VERSION in pyproject.toml and __init__.py"
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Commit version bump
run: |
git add pyproject.toml stagehand/__init__.py
git commit -m "Bump version to ${{ steps.version.outputs.new_version }}"
git tag "v${{ steps.version.outputs.new_version }}"
- name: Build package
run: |
python -m build
- name: Upload to PyPI
env:
TWINE_USERNAME: __token__
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${{ steps.version.outputs.new_version }}
name: Release v${{ steps.version.outputs.new_version }}
generate_release_notes: true