|
1 | 1 | # This workflow is triggered when a GitHub release is created. |
2 | 2 | # It can also be run manually to re-publish to PyPI in case it failed for some reason. |
3 | | -# You can run this workflow by navigating to https://www.github.com/browserbase/stagehand-python/actions/workflows/publish-pypi.yml |
4 | 3 | name: Publish PyPI |
| 4 | + |
5 | 5 | on: |
6 | 6 | workflow_dispatch: |
| 7 | + inputs: |
| 8 | + stagehand_tag: |
| 9 | + description: "Stagehand repo git ref to build SEA binaries from (e.g. @browserbasehq/stagehand@3.0.6)" |
| 10 | + required: true |
| 11 | + type: string |
7 | 12 |
|
8 | 13 | release: |
9 | 14 | types: [published] |
10 | 15 |
|
11 | 16 | jobs: |
| 17 | + build_wheels: |
| 18 | + name: build wheels (${{ matrix.binary_name }}) |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + - os: ubuntu-latest |
| 24 | + binary_name: stagehand-linux-x64 |
| 25 | + output_path: src/stagehand/_sea/stagehand-linux-x64 |
| 26 | + wheel_platform_tag: manylinux2014_x86_64 |
| 27 | + - os: macos-latest |
| 28 | + binary_name: stagehand-darwin-arm64 |
| 29 | + output_path: src/stagehand/_sea/stagehand-darwin-arm64 |
| 30 | + wheel_platform_tag: macosx_11_0_arm64 |
| 31 | + - os: macos-13 |
| 32 | + binary_name: stagehand-darwin-x64 |
| 33 | + output_path: src/stagehand/_sea/stagehand-darwin-x64 |
| 34 | + wheel_platform_tag: macosx_10_9_x86_64 |
| 35 | + - os: windows-latest |
| 36 | + binary_name: stagehand-win32-x64.exe |
| 37 | + output_path: src/stagehand/_sea/stagehand-win32-x64.exe |
| 38 | + wheel_platform_tag: win_amd64 |
| 39 | + |
| 40 | + runs-on: ${{ matrix.os }} |
| 41 | + permissions: |
| 42 | + contents: read |
| 43 | + |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Install uv |
| 48 | + uses: astral-sh/setup-uv@v5 |
| 49 | + with: |
| 50 | + version: "0.9.13" |
| 51 | + |
| 52 | + - name: Checkout stagehand (server source) |
| 53 | + uses: actions/checkout@v4 |
| 54 | + with: |
| 55 | + repository: browserbase/stagehand |
| 56 | + ref: ${{ inputs.stagehand_tag || vars.STAGEHAND_TAG }} |
| 57 | + path: _stagehand |
| 58 | + fetch-depth: 1 |
| 59 | + # If browserbase/stagehand is private, set STAGEHAND_SOURCE_TOKEN (PAT) in this repo. |
| 60 | + token: ${{ secrets.STAGEHAND_SOURCE_TOKEN || github.token }} |
| 61 | + |
| 62 | + - name: Setup pnpm |
| 63 | + uses: pnpm/action-setup@v4 |
| 64 | + |
| 65 | + - name: Setup Node.js |
| 66 | + uses: actions/setup-node@v4 |
| 67 | + with: |
| 68 | + node-version: "23" |
| 69 | + cache: "pnpm" |
| 70 | + cache-dependency-path: _stagehand/pnpm-lock.yaml |
| 71 | + |
| 72 | + - name: Build SEA server binary (from source) |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + set -euo pipefail |
| 76 | +
|
| 77 | + if [[ -z "${{ inputs.stagehand_tag }}" && -z "${{ vars.STAGEHAND_TAG }}" ]]; then |
| 78 | + echo "Missing stagehand ref: set repo variable STAGEHAND_TAG or provide workflow input stagehand_tag." >&2 |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | +
|
| 82 | + # Ensure we only ship the binary built for this runner's OS/arch. |
| 83 | + python - <<'PY' |
| 84 | + from pathlib import Path |
| 85 | + sea_dir = Path("src/stagehand/_sea") |
| 86 | + sea_dir.mkdir(parents=True, exist_ok=True) |
| 87 | + for p in sea_dir.glob("stagehand-*"): |
| 88 | + p.unlink(missing_ok=True) |
| 89 | + for p in sea_dir.glob("*.exe"): |
| 90 | + p.unlink(missing_ok=True) |
| 91 | + PY |
| 92 | +
|
| 93 | + pushd _stagehand >/dev/null |
| 94 | + pnpm install --frozen-lockfile |
| 95 | + CI=true pnpm --filter @browserbasehq/stagehand-server build:binary |
| 96 | + popd >/dev/null |
| 97 | +
|
| 98 | + cp "_stagehand/packages/server/dist/sea/${{ matrix.binary_name }}" "${{ matrix.output_path }}" |
| 99 | + chmod +x "${{ matrix.output_path }}" 2>/dev/null || true |
| 100 | +
|
| 101 | + - name: Build wheel |
| 102 | + env: |
| 103 | + STAGEHAND_WHEEL_TAG: py3-none-${{ matrix.wheel_platform_tag }} |
| 104 | + run: uv build --wheel |
| 105 | + |
| 106 | + - name: Upload wheel artifact |
| 107 | + uses: actions/upload-artifact@v4 |
| 108 | + with: |
| 109 | + name: wheel-${{ matrix.binary_name }} |
| 110 | + path: dist/*.whl |
| 111 | + retention-days: 7 |
| 112 | + |
| 113 | + build_sdist: |
| 114 | + name: build sdist |
| 115 | + runs-on: ubuntu-latest |
| 116 | + permissions: |
| 117 | + contents: read |
| 118 | + steps: |
| 119 | + - uses: actions/checkout@v4 |
| 120 | + |
| 121 | + - name: Install uv |
| 122 | + uses: astral-sh/setup-uv@v5 |
| 123 | + with: |
| 124 | + version: "0.9.13" |
| 125 | + |
| 126 | + - name: Build sdist |
| 127 | + run: uv build --sdist |
| 128 | + |
| 129 | + - name: Upload sdist artifact |
| 130 | + uses: actions/upload-artifact@v4 |
| 131 | + with: |
| 132 | + name: sdist |
| 133 | + path: dist/*.tar.gz |
| 134 | + retention-days: 7 |
| 135 | + |
12 | 136 | publish: |
13 | 137 | name: publish |
| 138 | + needs: [build_wheels, build_sdist] |
14 | 139 | runs-on: ubuntu-latest |
15 | | - |
| 140 | + permissions: |
| 141 | + contents: read |
16 | 142 | steps: |
17 | 143 | - uses: actions/checkout@v4 |
18 | 144 |
|
19 | 145 | - name: Install uv |
20 | 146 | uses: astral-sh/setup-uv@v5 |
21 | 147 | with: |
22 | | - version: '0.9.13' |
| 148 | + version: "0.9.13" |
23 | 149 |
|
24 | | - - name: Publish to PyPI |
| 150 | + - name: Download build artifacts |
| 151 | + uses: actions/download-artifact@v4 |
| 152 | + with: |
| 153 | + path: dist |
| 154 | + |
| 155 | + - name: Flatten dist directory |
| 156 | + shell: bash |
25 | 157 | run: | |
26 | | - bash ./bin/publish-pypi |
| 158 | + set -euo pipefail |
| 159 | + mkdir -p dist_out |
| 160 | + find dist -type f \( -name "*.whl" -o -name "*.tar.gz" \) -print0 | while IFS= read -r -d '' f; do |
| 161 | + cp -f "$f" dist_out/ |
| 162 | + done |
| 163 | + ls -la dist_out |
| 164 | +
|
| 165 | + - name: Publish to PyPI |
27 | 166 | env: |
28 | 167 | PYPI_TOKEN: ${{ secrets.STAGEHAND_PYPI_TOKEN || secrets.PYPI_TOKEN }} |
| 168 | + run: | |
| 169 | + set -euo pipefail |
| 170 | + uv publish --token="$PYPI_TOKEN" dist_out/* |
0 commit comments