Release #15
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: ['v**'] | |
| workflow_dispatch: | |
| inputs: | |
| allow_example_test_failures: | |
| description: 'Publish even if the live example tests fail (use only when a SerpApi engine is down)' | |
| type: boolean | |
| default: false | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| test: | |
| name: Test / Python ${{ matrix.python-version }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Ensure ref is a tag | |
| if: github.ref_type != 'tag' | |
| run: | | |
| echo "Release must run against a tag, got '${{ github.ref }}'" >&2 | |
| exit 1 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: pip install -e .[test] | |
| - name: Run tests | |
| run: pytest -k "not example" | |
| env: | |
| API_KEY: ${{ secrets.API_KEY }} | |
| - name: Run example tests | |
| if: matrix.python-version == '3.14' | |
| continue-on-error: ${{ inputs.allow_example_test_failures == true }} | |
| run: pytest -k "example" | |
| env: | |
| API_KEY: ${{ secrets.API_KEY }} | |
| build: | |
| name: Build distribution | |
| needs: [test] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.13" | |
| - name: Build sdist and wheel | |
| run: | | |
| pip install build | |
| python -m build | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: dist | |
| path: dist/ | |
| if-no-files-found: error | |
| publish: | |
| name: Publish release | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/serpapi | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: dist | |
| path: dist/ | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_REPO: ${{ github.repository }} | |
| run: | | |
| gh release create ${{ github.ref_name }} dist/* --generate-notes \ | |
| || gh release upload ${{ github.ref_name }} dist/* --clobber | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| smoke-test: | |
| name: Smoke test published package | |
| needs: [publish] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.13" | |
| - name: Wait for PyPI availability | |
| run: | | |
| VERSION=${GITHUB_REF_NAME#v} | |
| echo "Waiting for serpapi==$VERSION on PyPI..." | |
| for i in $(seq 1 12); do | |
| if pip index versions serpapi 2>/dev/null | grep -q "$VERSION"; then | |
| echo "Available!" | |
| exit 0 | |
| fi | |
| echo "Attempt $i/12 — sleeping 10s..." | |
| sleep 10 | |
| done | |
| echo "Timed out waiting for PyPI propagation" && exit 1 | |
| - name: Install from PyPI | |
| run: | | |
| VERSION=${GITHUB_REF_NAME#v} | |
| pip install "serpapi==$VERSION" | |
| - name: Verify import and version | |
| env: | |
| API_KEY: ${{ secrets.API_KEY }} | |
| EXPECTED_VERSION: ${{ github.ref_name }} | |
| shell: python3 {0} | |
| run: | | |
| import os | |
| import serpapi | |
| expected = os.environ["EXPECTED_VERSION"].lstrip("v") | |
| assert serpapi.__version__ == expected, f"Version mismatch: {serpapi.__version__} != {expected}" | |
| print(f"OK: serpapi=={serpapi.__version__} installed successfully") | |
| client = serpapi.Client(api_key=os.environ["API_KEY"]) | |
| results = client.search({"engine": "google", "q": "coffee"}) | |
| assert results.get("organic_results"), "No organic results returned" | |
| print(f"OK: live search returned {len(results['organic_results'])} organic results") |