| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a20a3a8 commit ad375dc
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ permissions: | |||
| 10 | 10 | deployments: write | |
| 11 | 11 | issues: write | |
| 12 | 12 | pull-requests: write | |
| 13 | + statuses: write | ||
| 13 | 14 | ||
| 14 | 15 | jobs: | |
| 15 | 16 | deploy-docs: | |
@@ -20,6 +21,25 @@ jobs: | |||
| 20 | 21 | GITHUB_CONTEXT: ${{ toJson(github) }} | |
| 21 | 22 | run: echo "$GITHUB_CONTEXT" | |
| 22 | 23 | - uses: actions/checkout@v4 | |
| 24 | + - name: Set up Python | ||
| 25 | + uses: actions/setup-python@v5 | ||
| 26 | + with: | ||
| 27 | + python-version: "3.11" | ||
| 28 | + - uses: actions/cache@v4 | ||
| 29 | + id: cache | ||
| 30 | + with: | ||
| 31 | + path: ${{ env.pythonLocation }} | ||
| 32 | + key: ${{ runner.os }}-python-github-actions-${{ env.pythonLocation }}-${{ hashFiles('requirements-github-actions.txt') }}-v01 | ||
| 33 | + - name: Install GitHub Actions dependencies | ||
| 34 | + if: steps.cache.outputs.cache-hit != 'true' | ||
| 35 | + run: pip install -r requirements-github-actions.txt | ||
| 36 | + - name: Deploy Docs Status Pending | ||
| 37 | + run: python ./scripts/deploy_docs_status.py | ||
| 38 | + env: | ||
| 39 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| 40 | + COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} | ||
| 41 | + RUN_ID: ${{ github.run_id }} | ||
| 42 | + | ||
| 23 | 43 | - name: Clean site | |
| 24 | 44 | run: | | |
| 25 | 45 | rm -rf ./site | |
@@ -43,22 +63,11 @@ jobs: | |||
| 43 | 63 | directory: './site' | |
| 44 | 64 | gitHubToken: ${{ secrets.GITHUB_TOKEN }} | |
| 45 | 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 ) }} | |
| 46 | - - name: Set up Python | ||
| 47 | - uses: actions/setup-python@v5 | ||
| 48 | - with: | ||
| 49 | - python-version: "3.11" | ||
| 50 | - - uses: actions/cache@v4 | ||
| 51 | - id: cache | ||
| 52 | - with: | ||
| 53 | - path: ${{ env.pythonLocation }} | ||
| 54 | - key: ${{ runner.os }}-python-github-actions-${{ env.pythonLocation }}-${{ hashFiles('requirements-github-actions.txt') }}-v01 | ||
| 55 | - - name: Install GitHub Actions dependencies | ||
| 56 | - if: steps.cache.outputs.cache-hit != 'true' | ||
| 57 | - run: pip install -r requirements-github-actions.txt | ||
| 58 | 66 | - name: Comment Deploy | |
| 59 | 67 | if: steps.deploy.outputs.url != '' | |
| 60 | - run: python ./scripts/comment_docs_deploy_url_in_pr.py | ||
| 68 | + run: python ./scripts/deploy_docs_status.py | ||
| 61 | 69 | env: | |
| 62 | 70 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| 63 | 71 | DEPLOY_URL: ${{ steps.deploy.outputs.url }} | |
| 64 | 72 | COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} | |
| 73 | + RUN_ID: ${{ github.run_id }} | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,79 @@ | |||
| 1 | + import logging | ||
| 2 | + import re | ||
| 3 | + | ||
| 4 | + from github import Github | ||
| 5 | + from pydantic import SecretStr | ||
| 6 | + from pydantic_settings import BaseSettings | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + class Settings(BaseSettings): | ||
| 10 | + github_repository: str | ||
| 11 | + github_token: SecretStr | ||
| 12 | + deploy_url: str | None = None | ||
| 13 | + commit_sha: str | ||
| 14 | + run_id: int | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + def main(): | ||
| 18 | + logging.basicConfig(level=logging.INFO) | ||
| 19 | + settings = Settings() | ||
| 20 | + | ||
| 21 | + logging.info(f"Using config: {settings.model_dump_json()}") | ||
| 22 | + g = Github(settings.github_token.get_secret_value()) | ||
| 23 | + repo = g.get_repo(settings.github_repository) | ||
| 24 | + use_pr = next( | ||
| 25 | + (pr for pr in repo.get_pulls() if pr.head.sha == settings.commit_sha), None | ||
| 26 | + ) | ||
| 27 | + if not use_pr: | ||
| 28 | + logging.error(f"No PR found for hash: {settings.commit_sha}") | ||
| 29 | + return | ||
| 30 | + commits = list(use_pr.get_commits()) | ||
| 31 | + current_commit = [c for c in commits if c.sha == settings.commit_sha][0] | ||
| 32 | + run_url = f"https://github.com/{settings.github_repository}/actions/runs/{settings.run_id}" | ||
| 33 | + if not settings.deploy_url: | ||
| 34 | + current_commit.create_status( | ||
| 35 | + state="pending", | ||
| 36 | + description="Deploy Docs", | ||
| 37 | + context="deploy-docs", | ||
| 38 | + target_url=run_url, | ||
| 39 | + ) | ||
| 40 | + logging.info("No deploy URL available yet") | ||
| 41 | + return | ||
| 42 | + current_commit.create_status( | ||
| 43 | + state="success", | ||
| 44 | + description="Deploy Docs", | ||
| 45 | + context="deploy-docs", | ||
| 46 | + target_url=run_url, | ||
| 47 | + ) | ||
| 48 | + | ||
| 49 | + files = list(use_pr.get_files()) | ||
| 50 | + docs_files = [f for f in files if f.filename.startswith("docs/")] | ||
| 51 | + | ||
| 52 | + deploy_url = settings.deploy_url.rstrip("/") | ||
| 53 | + links: list[str] = [] | ||
| 54 | + for f in docs_files: | ||
| 55 | + match = re.match(r"docs/(.*)", f.filename) | ||
| 56 | + assert match | ||
| 57 | + path = match.group(1) | ||
| 58 | + if path.endswith("index.md"): | ||
| 59 | + path = path.replace("index.md", "") | ||
| 60 | + else: | ||
| 61 | + path = path.replace(".md", "/") | ||
| 62 | + link = f"{deploy_url}/{path}" | ||
| 63 | + links.append(link) | ||
| 64 | + links.sort() | ||
| 65 | + | ||
| 66 | + message = f"📝 Docs preview for commit {settings.commit_sha} at: {deploy_url}" | ||
| 67 | + | ||
| 68 | + if links: | ||
| 69 | + message += "\n\n### Modified Pages\n\n" | ||
| 70 | + message += "\n".join([f"* {link}" for link in links]) | ||
| 71 | + | ||
| 72 | + print(message) | ||
| 73 | + use_pr.as_issue().create_comment(message) | ||
| 74 | + | ||
| 75 | + logging.info("Finished") | ||
| 76 | + | ||
| 77 | + | ||
| 78 | + if __name__ == "__main__": | ||
| 79 | + main() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments