Visitar URL original
fix: fix RTD publish script, allow manual docs deployment from main · serpapi/serpapi-python@c6f7f63 · GitHub
Skip to content

Commit c6f7f63

Browse files
committed
fix: fix RTD publish script, allow manual docs deployment from main
1 parent c4f5f5f commit c6f7f63

4 files changed

Lines changed: 25 additions & 12 deletions

File tree

‎.github/workflows/docs.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ permissions:
1111
jobs:
1212
live-examples:
1313
name: Live documentation examples
14-
if: startsWith(github.ref, 'refs/tags/v')
14+
if: >-
15+
github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
1516
runs-on: ubuntu-latest
1617
timeout-minutes: 30
1718
steps:
@@ -87,7 +88,7 @@ jobs:
8788
needs.live-examples.result == 'success' &&
8889
needs.build.result == 'success' &&
8990
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
90-
startsWith(github.ref, 'refs/tags/v')
91+
(github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v'))
9192
runs-on: ubuntu-latest
9293
timeout-minutes: 60
9394
environment:

‎CONTRIBUTING.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ This includes live account, location, search, and pagination checks. To run ever
6161
python -m pytest -q
6262
```
6363

64-
Both commands make real SerpApi requests. The full suite can use more searches than a test run limited to the files you changed. PR CI also runs the standalone engine examples on Python 3.14. Documentation tests run only in the package and documentation release workflows, on release tags.
64+
Both commands make real SerpApi requests. The full suite can use more searches than a test run limited to the files you changed. PR CI also runs the standalone engine examples on Python 3.14. Documentation tests run in the package and documentation release workflows on release tags, and in manual documentation runs on `master`.
6565

6666
### Testing documentation examples
6767

@@ -146,9 +146,9 @@ The files are written to `dist/`. Documentation sources, this guide, and the log
146146

147147
## Documentation publishing
148148

149-
The [documentation workflow](.github/workflows/docs.yml) runs the live examples before building HTML and EPUB when a `v*` release tag is pushed or selected for a manual run. It does not run on branch pushes or pull requests.
149+
The [documentation workflow](.github/workflows/docs.yml) runs the live examples before building HTML and EPUB when a `v*` release tag is pushed, or when `master` or a release tag is selected for a manual run. It does not run on branch pushes or pull requests.
150150

151-
After the live examples and documentation build pass, the same workflow publishes to Read the Docs for the selected release tag. The publishing job uses the `docs` GitHub environment and its `RTD_API_TOKEN` secret. The SerpApi key stays in GitHub as the existing `API_KEY` repository or organization secret.
151+
After the live examples and documentation build pass, the same workflow publishes to Read the Docs for the selected ref. A manual run on `master` updates `latest` without triggering the package release workflow or changing the package version. The publishing job uses the `docs` GitHub environment and its `RTD_API_TOKEN` secret. The SerpApi key stays in GitHub as the existing `API_KEY` repository or organization secret.
152152

153153
The workflow syncs RTD versions, activates the requested version if needed, and waits for the build to finish. `latest` tracks `master`. A release tag has its own version and also updates `stable` when RTD identifies it as the highest stable release. RTD still builds the site from the repository using [.readthedocs.yaml](.readthedocs.yaml); it does not receive the HTML artifact from GitHub. Documentation publishing runs independently of the PyPI release workflow.
154154

@@ -163,8 +163,8 @@ Maintainers can configure the existing RTD project and GitHub environment with t
163163
3. Under RTD **Automation Rules**, remove rules that activate new versions or change the default version. The workflow handles release activation. Under **Settings > Pull request builds**, turn off **Build pull requests for this project**. GitHub Actions runs the existing SDK and engine example tests on PRs.
164164
4. Under RTD **Environment Variables**, remove `API_KEY` or `SERPAPI_KEY` if you added either for docs tests. Do not add the RTD API token here. The workflow manages `DOCS_CI_REVISION` automatically.
165165
5. Keep `latest` active in **Versions** and use it as the default documentation version during this migration. Existing release tags contain their original docs and build configuration. After the first release containing these changes builds successfully, you can choose `stable` as the default version.
166-
6. Create an RTD API token in your [RTD profile settings](https://app.readthedocs.org/accounts/tokens/), using an account that maintains the `serpapi-python` project. In GitHub, open the repository's **Settings > Environments**, create an environment named `docs`, and add an environment secret named `RTD_API_TOKEN` with that value. Under **Deployment branches and tags**, select **Selected branches and tags** and add a Tag rule for `v*`. Leave required reviewers and wait timers disabled if publishing should run without a manual approval.
167-
7. Merge the changes to `master`, then push the version tag for the release. In GitHub **Actions > Documentation**, follow **Live documentation examples**, **Build Sphinx documentation**, and **Publish Read the Docs**. The publishing log links to the RTD build. To retry publishing, run the Documentation workflow on the intended release tag. A manual run on a branch skips the documentation jobs.
166+
6. Create an RTD API token in your [RTD profile settings](https://app.readthedocs.org/accounts/tokens/), using an account that maintains the `serpapi-python` project. In GitHub, open the repository's **Settings > Environments**, create an environment named `docs`, and add an environment secret named `RTD_API_TOKEN` with that value. Under **Deployment branches and tags**, select **Selected branches and tags** and add a Branch rule for `master` and a Tag rule for `v*`. Leave required reviewers and wait timers disabled if publishing should run without a manual approval.
167+
7. Merge the changes to `master`, then push the version tag for the release. In GitHub **Actions > Documentation**, follow **Live documentation examples**, **Build Sphinx documentation**, and **Publish Read the Docs**. The publishing log links to the RTD build. To retry publishing, run the Documentation workflow on the intended release tag, or select `master` to publish updated `latest` docs without a new package release. A manual run on any other branch skips the documentation jobs.
168168

169169
Use GitHub Actions to request builds after this setup. A manual RTD build has no CI revision record and will fail the revision check. If a branch or tag moves between testing and the RTD checkout, rerun the workflow for its current commit. Pushing a `v*` tag also starts the PyPI release workflow, so use an actual package release to test release documentation.
170170

‎scripts/check_docs_revision.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import re
4+
import shlex
45
import subprocess
56
import sys
67
import time
@@ -13,7 +14,11 @@ def check_revision(environ, commit, now=None):
1314
if environ.get("READTHEDOCS_VERSION_TYPE") == "external":
1415
return
1516
try:
16-
context = json.loads(environ[CONTEXT_VARIABLE])
17+
value = environ[CONTEXT_VARIABLE]
18+
# RTD stores custom environment values with shlex.quote.
19+
if value.startswith("'"):
20+
value, = shlex.split(value)
21+
context = json.loads(value)
1722
expected = context["commit"]
1823
versions = context["versions"]
1924
expires = context["expires_at"]

‎tests/test_docs_publishing.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
from collections import deque
44
from pathlib import Path
5+
from shlex import quote
56
import subprocess
67
from types import SimpleNamespace
78
from urllib.error import HTTPError
@@ -27,13 +28,19 @@ def ci_environment(**context_changes):
2728
}
2829

2930

30-
def test_revision_guard_accepts_only_the_tested_commit():
31-
guard.check_revision(ci_environment(), COMMIT, now=100)
31+
@pytest.mark.parametrize("shell_quoted", [False, True])
32+
def test_revision_guard_accepts_only_the_tested_commit(shell_quoted):
33+
env = ci_environment()
34+
if shell_quoted:
35+
env[guard.CONTEXT_VARIABLE] = quote(env[guard.CONTEXT_VARIABLE])
36+
guard.check_revision(env, COMMIT, now=100)
3237
with pytest.raises(RuntimeError, match="different commit"):
33-
guard.check_revision(ci_environment(), "b" * 40, now=100)
38+
guard.check_revision(env, "b" * 40, now=100)
3439

3540

36-
@pytest.mark.parametrize("context", [None, "not json", "null", "[]", "{}"])
41+
@pytest.mark.parametrize("context", [
42+
None, "not json", "null", "[]", "{}", "'unterminated", "'{}' '{}'", quote("not json"),
43+
])
3744
def test_revision_guard_rejects_missing_or_malformed_context(context):
3845
env = ci_environment()
3946
if context is None:

0 commit comments

Comments
 (0)