| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,7 @@ jobs: | |||
| 44 | 44 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| 45 | 45 | COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} | |
| 46 | 46 | RUN_ID: ${{ github.run_id }} | |
| 47 | - | ||
| 47 | + STATE: "pending" | ||
| 48 | 48 | - name: Clean site | |
| 49 | 49 | run: | | |
| 50 | 50 | rm -rf ./site | |
@@ -62,17 +62,25 @@ jobs: | |||
| 62 | 62 | id: deploy | |
| 63 | 63 | env: | |
| 64 | 64 | PROJECT_NAME: sqlmodel | |
| 65 | - BRANCH: ${{ ( github.event.workflow_run.head_repository.full_name == github.repository && github.event.workflow_run.head_branch == 'main' && 'main' ) || ( github.event.workflow_run.head_sha ) }} | ||
| 65 | + BRANCH: ${{ ( github.event.workflow_run.head_repository.full_name == github.repository && github.event.workflow_run.head_branch == 'master' && 'main' ) || ( github.event.workflow_run.head_sha ) }} | ||
| 66 | 66 | uses: cloudflare/wrangler-action@v3 | |
| 67 | 67 | with: | |
| 68 | 68 | apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| 69 | 69 | accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| 70 | 70 | command: pages deploy ./site --project-name=${{ env.PROJECT_NAME }} --branch=${{ env.BRANCH }} | |
| 71 | + - name: Deploy Docs Status Error | ||
| 72 | + if: failure() | ||
| 73 | + run: python ./scripts/deploy_docs_status.py | ||
| 74 | + env: | ||
| 75 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| 76 | + COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} | ||
| 77 | + RUN_ID: ${{ github.run_id }} | ||
| 78 | + STATE: "error" | ||
| 71 | 79 | - name: Comment Deploy | |
| 72 | 80 | run: python ./scripts/deploy_docs_status.py | |
| 73 | 81 | env: | |
| 74 | 82 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| 75 | 83 | DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }} | |
| 76 | 84 | COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} | |
| 77 | 85 | RUN_ID: ${{ github.run_id }} | |
| 78 | - IS_DONE: "true" | ||
| 86 | + STATE: "success" | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,8 @@ | |||
| 1 | 1 | import logging | |
| 2 | 2 | import re | |
| 3 | + from typing import Literal | ||
| 3 | 4 | ||
| 4 | - from github import Github | ||
| 5 | + from github import Auth, Github | ||
| 5 | 6 | from pydantic import BaseModel, SecretStr | |
| 6 | 7 | from pydantic_settings import BaseSettings | |
| 7 | 8 | ||
@@ -14,7 +15,7 @@ class Settings(BaseSettings): | |||
| 14 | 15 | deploy_url: str | None = None | |
| 15 | 16 | commit_sha: str | |
| 16 | 17 | run_id: int | |
| 17 | - is_done: bool = False | ||
| 18 | + state: Literal["pending", "success", "error"] = "pending" | ||
| 18 | 19 | ||
| 19 | 20 | ||
| 20 | 21 | class LinkData(BaseModel): | |
@@ -27,7 +28,7 @@ def main() -> None: | |||
| 27 | 28 | settings = Settings() | |
| 28 | 29 | ||
| 29 | 30 | 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())) | ||
| 31 | 32 | repo = g.get_repo(settings.github_repository) | |
| 32 | 33 | use_pr = next( | |
| 33 | 34 | (pr for pr in repo.get_pulls() if pr.head.sha == settings.commit_sha), None | |
@@ -38,24 +39,35 @@ def main() -> None: | |||
| 38 | 39 | commits = list(use_pr.get_commits()) | |
| 39 | 40 | current_commit = [c for c in commits if c.sha == settings.commit_sha][0] | |
| 40 | 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": | ||
| 42 | 43 | current_commit.create_status( | |
| 43 | - state="success", | ||
| 44 | - description="No Docs Changes", | ||
| 44 | + state="pending", | ||
| 45 | + description="Deploying Docs", | ||
| 45 | 46 | context="deploy-docs", | |
| 46 | 47 | target_url=run_url, | |
| 47 | 48 | ) | |
| 48 | - logging.info("No docs changes found") | ||
| 49 | + logging.info("No deploy URL available yet") | ||
| 49 | 50 | return | |
| 51 | + 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 | + return | ||
| 60 | + assert settings.state == "success" | ||
| 50 | 61 | if not settings.deploy_url: | |
| 51 | 62 | current_commit.create_status( | |
| 52 | - state="pending", | ||
| 53 | - description="Deploying Docs", | ||
| 63 | + state="success", | ||
| 64 | + description="No Docs Changes", | ||
| 54 | 65 | context="deploy-docs", | |
| 55 | 66 | target_url=run_url, | |
| 56 | 67 | ) | |
| 57 | - logging.info("No deploy URL available yet") | ||
| 68 | + logging.info("No docs changes found") | ||
| 58 | 69 | return | |
| 70 | + assert settings.deploy_url | ||
| 59 | 71 | current_commit.create_status( | |
| 60 | 72 | state="success", | |
| 61 | 73 | description="Docs Deployed", | |
@@ -84,7 +96,9 @@ def main() -> None: | |||
| 84 | 96 | links.append(link) | |
| 85 | 97 | links.sort(key=lambda x: x.preview_link) | |
| 86 | 98 | ||
| 87 | - message = f"📝 Docs preview for commit {settings.commit_sha} at: {deploy_url}" | ||
| 99 | + header = "## 📝 Docs preview" | ||
| 100 | + message = header | ||
| 101 | + message += f"\n\nLast commit {settings.commit_sha} at: {deploy_url}" | ||
| 88 | 102 | ||
| 89 | 103 | if links: | |
| 90 | 104 | message += "\n\n### Modified Pages\n\n" | |
@@ -94,7 +108,17 @@ def main() -> None: | |||
| 94 | 108 | message += "\n" | |
| 95 | 109 | ||
| 96 | 110 | print(message) | |
| 97 | - use_pr.as_issue().create_comment(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 | + break | ||
| 120 | + else: | ||
| 121 | + issue.create_comment(message) | ||
| 98 | 122 | ||
| 99 | 123 | logging.info("Finished") | |
| 100 | 124 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments