From 166b59c0e9adbd5183d1477421641d66f07d4c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 8 Aug 2024 17:18:21 -0500 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=9A=9A=20Rename=20script=20deploy=5Fd?= =?UTF-8?q?ocs=5Fstatus.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{comment_docs_deploy_url_in_pr.py => deploy_docs_status.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{comment_docs_deploy_url_in_pr.py => deploy_docs_status.py} (100%) diff --git a/scripts/comment_docs_deploy_url_in_pr.py b/scripts/deploy_docs_status.py similarity index 100% rename from scripts/comment_docs_deploy_url_in_pr.py rename to scripts/deploy_docs_status.py From 93b7530e4294c49e59d788a0aaeaeaa20a7f89c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 8 Aug 2024 17:18:50 -0500 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=91=B7=20Update=20CI=20to=20run=20dep?= =?UTF-8?q?loy=5Fdocs=5Fstatus.py=20before=20and=20after=20deploying=20the?= =?UTF-8?q?=20preview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-docs.yml | 35 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 1984643ddd..619e689dcb 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -10,6 +10,7 @@ permissions: deployments: write issues: write pull-requests: write + statuses: write jobs: deploy-docs: @@ -20,6 +21,25 @@ jobs: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + - uses: actions/cache@v4 + id: cache + with: + path: ${{ env.pythonLocation }} + key: ${{ runner.os }}-python-github-actions-${{ env.pythonLocation }}-${{ hashFiles('requirements-github-actions.txt') }}-v01 + - name: Install GitHub Actions dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: pip install -r requirements-github-actions.txt + - name: Deploy Docs Status Pending + run: python ./scripts/deploy_docs_status.py + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} + RUN_ID: ${{ github.run_id }} + - name: Clean site run: | rm -rf ./site @@ -43,22 +63,11 @@ jobs: directory: './site' gitHubToken: ${{ secrets.GITHUB_TOKEN }} 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 ) }} - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - uses: actions/cache@v4 - id: cache - with: - path: ${{ env.pythonLocation }} - key: ${{ runner.os }}-python-github-actions-${{ env.pythonLocation }}-${{ hashFiles('requirements-github-actions.txt') }}-v01 - - name: Install GitHub Actions dependencies - if: steps.cache.outputs.cache-hit != 'true' - run: pip install -r requirements-github-actions.txt - name: Comment Deploy if: steps.deploy.outputs.url != '' - run: python ./scripts/comment_docs_deploy_url_in_pr.py + run: python ./scripts/deploy_docs_status.py env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} DEPLOY_URL: ${{ steps.deploy.outputs.url }} COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} + RUN_ID: ${{ github.run_id }} From 0676d78f528b189f1591613777b8cda8fda0125b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 8 Aug 2024 17:22:06 -0500 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=94=A8=20Update=20script=20to=20show?= =?UTF-8?q?=20docs=20deployment=20status=20and=20comment=20with=20preview?= =?UTF-8?q?=20links?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy_docs_status.py | 60 +++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/scripts/deploy_docs_status.py b/scripts/deploy_docs_status.py index 3148a3bb40..def57e1471 100644 --- a/scripts/deploy_docs_status.py +++ b/scripts/deploy_docs_status.py @@ -1,5 +1,5 @@ import logging -import sys +import re from github import Github from pydantic import SecretStr @@ -9,13 +9,15 @@ class Settings(BaseSettings): github_repository: str github_token: SecretStr - deploy_url: str + deploy_url: str | None = None commit_sha: str + run_id: int -if __name__ == "__main__": +def main(): logging.basicConfig(level=logging.INFO) settings = Settings() + logging.info(f"Using config: {settings.model_dump_json()}") g = Github(settings.github_token.get_secret_value()) repo = g.get_repo(settings.github_repository) @@ -24,8 +26,54 @@ class Settings(BaseSettings): ) if not use_pr: logging.error(f"No PR found for hash: {settings.commit_sha}") - sys.exit(0) - use_pr.as_issue().create_comment( - f"📝 Docs preview for commit {settings.commit_sha} at: {settings.deploy_url}" + return + commits = list(use_pr.get_commits()) + current_commit = [c for c in commits if c.sha == settings.commit_sha][0] + run_url = f"https://github.com/{settings.github_repository}/actions/runs/{settings.run_id}" + if not settings.deploy_url: + current_commit.create_status( + state="pending", + description="Deploy Docs", + context="deploy-docs", + target_url=run_url, + ) + logging.info("No deploy URL available yet") + return + current_commit.create_status( + state="success", + description="Deploy Docs", + context="deploy-docs", + target_url=run_url, ) + + files = list(use_pr.get_files()) + docs_files = [f for f in files if f.filename.startswith("docs/")] + + deploy_url = settings.deploy_url.rstrip("/") + links: list[str] = [] + for f in docs_files: + match = re.match(r"docs/(.*)", f.filename) + assert match + path = match.group(1) + if path.endswith("index.md"): + path = path.replace("index.md", "") + else: + path = path.replace(".md", "/") + link = f"{deploy_url}/{path}" + links.append(link) + links.sort() + + message = f"📝 Docs preview for commit {settings.commit_sha} at: {deploy_url}" + + if links: + message += "\n\n### Modified Pages\n\n" + message += "\n".join([f"* {link}" for link in links]) + + print(message) + use_pr.as_issue().create_comment(message) + logging.info("Finished") + + +if __name__ == "__main__": + main() From d38319e4d56eab4a637c8177ff1db44ecfa401da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 8 Aug 2024 17:23:54 -0500 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=93=9D=20Add=20change=20to=20docs=20t?= =?UTF-8?q?o=20test=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ docs/index.md | 2 ++ docs/tutorial/index.md | 2 ++ docs/tutorial/one.md | 2 ++ 4 files changed, 8 insertions(+) diff --git a/README.md b/README.md index ba3bb2196e..5a899846c7 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ --- +🚀 + **Documentation**: https://sqlmodel.tiangolo.com **Source Code**: https://github.com/tiangolo/sqlmodel diff --git a/docs/index.md b/docs/index.md index f77cc7b8b4..b106426693 100644 --- a/docs/index.md +++ b/docs/index.md @@ -24,6 +24,8 @@ --- +🚀 + **Documentation**: https://sqlmodel.tiangolo.com **Source Code**: https://github.com/tiangolo/sqlmodel diff --git a/docs/tutorial/index.md b/docs/tutorial/index.md index 88d952a746..671bddd84a 100644 --- a/docs/tutorial/index.md +++ b/docs/tutorial/index.md @@ -1,5 +1,7 @@ # Intro, Installation, and First Steps +🚀 + ## Type hints If you need a refresher about how to use Python type hints (type annotations), check FastAPI's Python types intro. diff --git a/docs/tutorial/one.md b/docs/tutorial/one.md index f374d1b4a6..ba49c36bd9 100644 --- a/docs/tutorial/one.md +++ b/docs/tutorial/one.md @@ -1,5 +1,7 @@ # Read One Row +🚀 + You already know how to filter rows to select using `.where()`. And you saw how when executing a `select()` it normally returns an **iterable** object. From 3f3a611ab18e24db8ebcea2081b97026c54a63ca Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 8 Aug 2024 22:24:55 +0000 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy_docs_status.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deploy_docs_status.py b/scripts/deploy_docs_status.py index def57e1471..e4e665e865 100644 --- a/scripts/deploy_docs_status.py +++ b/scripts/deploy_docs_status.py @@ -62,7 +62,7 @@ def main(): link = f"{deploy_url}/{path}" links.append(link) links.sort() - + message = f"📝 Docs preview for commit {settings.commit_sha} at: {deploy_url}" if links: From b13a3c280027d54db6c5ca94161b1b599dba7e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 8 Aug 2024 17:35:47 -0500 Subject: [PATCH 6/7] =?UTF-8?q?=E2=8F=AA=EF=B8=8F=20Revert=20testing=20cha?= =?UTF-8?q?nges=20in=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.md | 2 -- docs/tutorial/index.md | 2 -- docs/tutorial/one.md | 2 -- 3 files changed, 6 deletions(-) diff --git a/docs/index.md b/docs/index.md index b106426693..f77cc7b8b4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -24,8 +24,6 @@ --- -🚀 - **Documentation**: https://sqlmodel.tiangolo.com **Source Code**: https://github.com/tiangolo/sqlmodel diff --git a/docs/tutorial/index.md b/docs/tutorial/index.md index 671bddd84a..88d952a746 100644 --- a/docs/tutorial/index.md +++ b/docs/tutorial/index.md @@ -1,7 +1,5 @@ # Intro, Installation, and First Steps -🚀 - ## Type hints If you need a refresher about how to use Python type hints (type annotations), check FastAPI's Python types intro. diff --git a/docs/tutorial/one.md b/docs/tutorial/one.md index ba49c36bd9..f374d1b4a6 100644 --- a/docs/tutorial/one.md +++ b/docs/tutorial/one.md @@ -1,7 +1,5 @@ # Read One Row -🚀 - You already know how to filter rows to select using `.where()`. And you saw how when executing a `select()` it normally returns an **iterable** object. From 617064cddc69d8c2712ac861481973259c2dada1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 8 Aug 2024 17:36:45 -0500 Subject: [PATCH 7/7] =?UTF-8?q?=E2=8F=AA=EF=B8=8F=20Revert=20README.md=20c?= =?UTF-8?q?hange?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 5a899846c7..ba3bb2196e 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,6 @@ --- -🚀 - **Documentation**: https://sqlmodel.tiangolo.com **Source Code**: https://github.com/tiangolo/sqlmodel