-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use REST API to trigger RTD build. (#11216)
--------- Co-authored-by: Hyunsu Cho <[email protected]> Co-authored-by: Hyunsu Cho <[email protected]>
- Loading branch information
1 parent
9715661
commit f78aebb
Showing
4 changed files
with
199 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: XGBoost-docs | ||
|
||
on: [push, pull_request] | ||
|
||
env: | ||
BRANCH_NAME: >- | ||
${{ github.event.pull_request.number && 'PR-' }}${{ github.event.pull_request.number || github.ref_name }} | ||
jobs: | ||
build-jvm-docs: | ||
name: Build docs for JVM packages | ||
runs-on: | ||
- runs-on=${{ github.run_id }} | ||
- runner=linux-amd64-cpu | ||
- tag=doc-build-jvm-docs | ||
steps: | ||
# Restart Docker daemon so that it recognizes the ephemeral disks | ||
- run: sudo systemctl restart docker | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: "true" | ||
- name: Log into Docker registry (AWS ECR) | ||
run: bash ops/pipeline/login-docker-registry.sh | ||
- run: bash ops/pipeline/build-jvm-gpu.sh | ||
- run: bash ops/pipeline/build-jvm-doc.sh | ||
- name: Upload JVM doc | ||
run: | | ||
# xgboost-docs/{branch}/{commit}/{branch}.tar.bz2 | ||
# branch can be the name of the dmlc/xgboost branch, or `PR-{number}`. | ||
python3 ops/pipeline/manage-artifacts.py upload \ | ||
--s3-bucket xgboost-docs \ | ||
--prefix ${BRANCH_NAME}/${GITHUB_SHA} --make-public \ | ||
jvm-packages/${{ env.BRANCH_NAME }}.tar.bz2 | ||
trigger-rtd-build: | ||
needs: [build-jvm-docs] | ||
name: Trigger Read The Docs build. | ||
runs-on: | ||
- runs-on=${{ github.run_id }} | ||
- runner=linux-amd64-cpu | ||
- tag=doc-trigger-rtd-build | ||
steps: | ||
# Restart Docker daemon so that it recognizes the ephemeral disks | ||
- run: sudo systemctl restart docker | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: "true" | ||
- name: Trigger RTD | ||
run: bash ops/pipeline/trigger-rtd.sh |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Helper script for triggering Read the docs build. | ||
See `doc/contrib/docs.rst <https://xgboost.readthedocs.io/en/stable/contrib/docs.html>`__ | ||
for more info. | ||
""" | ||
|
||
import json | ||
import os | ||
import pprint | ||
from http.client import responses as http_responses | ||
|
||
import requests # type: ignore | ||
|
||
|
||
def trigger_build(token: str) -> None: | ||
"""Trigger RTD build.""" | ||
|
||
event_path = os.environ["GITHUB_EVENT_PATH"] | ||
with open(event_path, "r") as fd: | ||
event: dict = json.load(fd) | ||
|
||
if event.get("pull_request", None) is None: | ||
# refs/heads/branch-name | ||
branch = event["ref"].split("/")[-1] | ||
else: | ||
branch = event["pull_request"]["number"] | ||
|
||
URL = f"https://readthedocs.org/api/v3/projects/xgboost/versions/{branch}/builds/" | ||
HEADERS = {"Authorization": f"token {token}"} | ||
response = requests.post(URL, headers=HEADERS) | ||
# 202 means the build is successfully triggered. | ||
if response.status_code != 202: | ||
status_text = http_responses[response.status_code] | ||
raise RuntimeError( | ||
"ReadTheDocs returned an unexpected response: " | ||
f"{response.status_code} {status_text}, reason: {response.reason}" | ||
) | ||
pprint.pprint(response.json(), indent=4) | ||
|
||
|
||
def main() -> None: | ||
token = os.getenv("RTD_AUTH_TOKEN") | ||
# GA redacts the secret by default, but we should still be really careful to not log | ||
# (expose) the token in the CI. | ||
if token is None: | ||
raise RuntimeError( | ||
"The RTD_AUTH_TOKEN environment variable must be set to a valid auth token for the" | ||
"ReadTheDocs service." | ||
) | ||
if len(token) == 0: | ||
print("Document build is not triggered.") | ||
return | ||
|
||
if not isinstance(token, str) or len(token) != 40: | ||
raise ValueError(f"Invalid token.") | ||
|
||
trigger_build(token) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
## Trigger a new build on ReadTheDocs service. | ||
|
||
set -euo pipefail | ||
|
||
if [[ -z ${BRANCH_NAME:-} ]] | ||
then | ||
echo "Make sure to define environment variable BRANCH_NAME." | ||
exit 1 | ||
fi | ||
|
||
echo "Branch name: ${BRANCH_NAME}" | ||
export RTD_AUTH_TOKEN=$(aws secretsmanager get-secret-value \ | ||
--secret-id runs-on/readthedocs-auth-token --output text \ | ||
--region us-west-2 --query SecretString || echo -n '') | ||
python3 ops/pipeline/trigger-rtd-impl.py |