Skip to content
Myr

✨ Add support for previewing docs in PRs from forks and enable MkDocs Insiders (#357)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastián Ramírez · committed by GitHub · parent ac0e1bb · Browse files · 8 files+216 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+216 added−29 removed

  • other:+216 added−29 removed

8 files+216 added−29 removed

added:.github/actions/comment-docs-preview-in-pr/app/main.py+70 added
1import logging2import sys3from pathlib import Path4from typing import Optional56import httpx7from github import Github8from github.PullRequest import PullRequest9from pydantic import BaseModel, BaseSettings, SecretStr, ValidationError1011github_api = "https://api.github.com"121314class Settings(BaseSettings):15 github_repository: str16 github_event_path: Path17 github_event_name: Optional[str] = None18 input_token: SecretStr19 input_deploy_url: str202122class PartialGithubEventHeadCommit(BaseModel):23 id: str242526class PartialGithubEventWorkflowRun(BaseModel):27 head_commit: PartialGithubEventHeadCommit282930class PartialGithubEvent(BaseModel):31 workflow_run: PartialGithubEventWorkflowRun323334if __name__ == "__main__":35 logging.basicConfig(level=logging.INFO)36 settings = Settings()37 logging.info(f"Using config: {settings.json()}")38 g = Github(settings.input_token.get_secret_value())39 repo = g.get_repo(settings.github_repository)40 try:41 event = PartialGithubEvent.parse_file(settings.github_event_path)42 except ValidationError as e:43 logging.error(f"Error parsing event file: {e.errors()}")44 sys.exit(0)45 use_pr: Optional[PullRequest] = None46 for pr in repo.get_pulls():47 if pr.head.sha == event.workflow_run.head_commit.id:48 use_pr = pr49 break50 if not use_pr:51 logging.error(52 f"No PR found for hash: {event.workflow_run.head_commit.id}"53 )54 sys.exit(0)55 github_headers = {56 "Authorization": f"token {settings.input_token.get_secret_value()}"57 }58 url = f"{github_api}/repos/{settings.github_repository}/issues/{use_pr.number}/comments"59 logging.info(f"Using comments URL: {url}")60 response = httpx.post(61 url,62 headers=github_headers,63 json={64 "body": f"📝 Docs preview for commit {use_pr.head.sha} at: {settings.input_deploy_url}"65 },66 )67 if not (200 <= response.status_code <= 300):68 logging.error(f"Error posting comment: {response.text}")69 sys.exit(1)70 logging.info("Finished")
added:.github/actions/comment-docs-preview-in-pr/action.yml+13 added
added:.github/actions/comment-docs-preview-in-pr/Dockerfile+7 added
1FROM python:3.723RUN pip install httpx "pydantic==1.5.1" pygithub45COPY ./app /app67CMD ["python", "/app/main.py"]
added:.github/workflows/build-docs.yml+72 added
deleted:.github/workflows/deploy-docs.yml-29 removed
added:.github/workflows/preview-docs.yml+41 added
added:scripts/zip-docs.sh+9 added
added:mkdocs.insiders.yml+4 added