Skip to content
Myr

👷 Update docs previews comment, single comment, add failure status (#1359)

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 dc07284 · Browse files · 2 files+46 added−14 removed
This commit

State

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

Diff stats

2 files+46 added−14 removed

  • other:+46 added−14 removed

2 files+46 added−14 removed

modified:.github/workflows/deploy-docs.yml+10 added-2 removed
modified:scripts/deploy_docs_status.py+36 added-12 removed
1import logging2import re3from typing import Literal44from github import Github5from github import Auth, Github6from pydantic import BaseModel, SecretStr7from pydantic_settings import BaseSettings89site_domain = "typer.tiangolo.com"
4 unmodified lines
14 github_token: SecretStr15 deploy_url: str | None = None16 commit_sha: str17 run_id: int17 is_done: bool = False18 state: Literal["pending", "success", "error"] = "pending"192021class LinkData(BaseModel):22 previous_link: str
4 unmodified lines
27 logging.basicConfig(level=logging.INFO)28 settings = Settings()2930 logging.info(f"Using config: {settings.model_dump_json()}")30 g = Github(settings.github_token.get_secret_value())31 g = Github(auth=Auth.Token(settings.github_token.get_secret_value()))32 repo = g.get_repo(settings.github_repository)33 use_pr = next(34 (pr for pr in repo.get_pulls() if pr.head.sha == settings.commit_sha), None35 )
2 unmodified lines
38 return39 commits = list(use_pr.get_commits())40 current_commit = [c for c in commits if c.sha == settings.commit_sha][0]41 run_url = f"https://github.com/{settings.github_repository}/actions/runs/{settings.run_id}"41 if settings.is_done and not settings.deploy_url:42 if settings.state == "pending":43 current_commit.create_status(43 state="success",44 description="No Docs Changes",44 state="pending",45 description="Deploying Docs",46 context="deploy-docs",47 target_url=run_url,48 )48 logging.info("No docs changes found")49 logging.info("No deploy URL available yet")50 return51 if settings.state == "error":52 current_commit.create_status(53 state="error",54 description="Error Deploying Docs",55 context="deploy-docs",56 target_url=run_url,57 )58 logging.info("Error deploying docs")59 return60 assert settings.state == "success"61 if not settings.deploy_url:62 current_commit.create_status(52 state="pending",53 description="Deploying Docs",63 state="success",64 description="No Docs Changes",65 context="deploy-docs",66 target_url=run_url,67 )57 logging.info("No deploy URL available yet")68 logging.info("No docs changes found")69 return70 assert settings.deploy_url71 current_commit.create_status(72 state="success",73 description="Docs Deployed",74 context="deploy-docs",
20 unmodified lines
95 )96 links.append(link)97 links.sort(key=lambda x: x.preview_link)9899 header = "## 📝 Docs preview"100 message = header87 message = f"📝 Docs preview for commit {settings.commit_sha} at: {deploy_url}"101 message += f"\n\nLast commit {settings.commit_sha} at: {deploy_url}"102103 if links:104 message += "\n\n### Modified Pages\n\n"105 for link in links:
1 unmodified line
107 message += f" - ([before]({link.previous_link}))"108 message += "\n"109110 print(message)111 issue = use_pr.as_issue()112 comments = list(issue.get_comments())113 for comment in comments:114 if (115 comment.body.startswith(header)116 and comment.user.login == "github-actions[bot]"117 ):118 comment.edit(message)119 break120 else:97 use_pr.as_issue().create_comment(message)121 issue.create_comment(message)122123 logging.info("Finished")124125
2 unmodified lines