Skip to content

Commit 18db2ae

Browse files
authored
Merge branch 'main' into mkdocs-updates
2 parents 5da4c3f + 0678615 commit 18db2ae

File tree

5 files changed

+127
-45
lines changed

5 files changed

+127
-45
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ permissions:
1010
deployments: write
1111
issues: write
1212
pull-requests: write
13+
statuses: write
1314

1415
jobs:
1516
deploy-docs:
@@ -20,6 +21,25 @@ jobs:
2021
GITHUB_CONTEXT: ${{ toJson(github) }}
2122
run: echo "$GITHUB_CONTEXT"
2223
- 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+
2343
- name: Clean site
2444
run: |
2545
rm -rf ./site
@@ -43,22 +63,11 @@ jobs:
4363
directory: './site'
4464
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
4565
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
5866
- name: Comment Deploy
59-
if: steps.deploy.outputs.url != ''
60-
run: python ./scripts/comment_docs_deploy_url_in_pr.py
67+
run: python ./scripts/deploy_docs_status.py
6168
env:
6269
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6370
DEPLOY_URL: ${{ steps.deploy.outputs.url }}
6471
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }}
72+
RUN_ID: ${{ github.run_id }}
73+
IS_DONE: "true"

.github/workflows/test-redistribute.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,15 @@ jobs:
5151
run: |
5252
cd dist
5353
pip wheel --no-deps sqlmodel*.tar.gz
54+
55+
# https://github.com/marketplace/actions/alls-green#why
56+
test-redistribute-alls-green: # This job does nothing and is only used for the branch protection
57+
if: always()
58+
needs:
59+
- test-redistribute
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Decide whether the needed jobs succeeded or failed
63+
uses: re-actors/alls-green@release/v1
64+
with:
65+
jobs: ${{ toJSON(needs) }}

docs/release-notes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
### Internal
1010

11+
* 👷 Add alls-green for test-redistribute. PR [#1055](https://github.com/tiangolo/sqlmodel/pull/1055) by [@tiangolo](https://github.com/tiangolo).
12+
* 👷 Update docs-previews to handle no docs changes. PR [#1056](https://github.com/tiangolo/sqlmodel/pull/1056) by [@tiangolo](https://github.com/tiangolo).
13+
* 👷🏻 Show docs deployment status and preview URLs in comment. PR [#1054](https://github.com/tiangolo/sqlmodel/pull/1054) by [@tiangolo](https://github.com/tiangolo).
1114
* 🔧 Enable auto dark mode. PR [#1046](https://github.com/tiangolo/sqlmodel/pull/1046) by [@tiangolo](https://github.com/tiangolo).
1215
* 👷 Update issue-manager. PR [#1045](https://github.com/tiangolo/sqlmodel/pull/1045) by [@tiangolo](https://github.com/tiangolo).
1316
* 👷 Update issue-manager.yml GitHub Action permissions. PR [#1040](https://github.com/tiangolo/sqlmodel/pull/1040) by [@tiangolo](https://github.com/tiangolo).

scripts/comment_docs_deploy_url_in_pr.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

scripts/deploy_docs_status.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
is_done: bool = False
16+
17+
18+
def main():
19+
logging.basicConfig(level=logging.INFO)
20+
settings = Settings()
21+
22+
logging.info(f"Using config: {settings.model_dump_json()}")
23+
g = Github(settings.github_token.get_secret_value())
24+
repo = g.get_repo(settings.github_repository)
25+
use_pr = next(
26+
(pr for pr in repo.get_pulls() if pr.head.sha == settings.commit_sha), None
27+
)
28+
if not use_pr:
29+
logging.error(f"No PR found for hash: {settings.commit_sha}")
30+
return
31+
commits = list(use_pr.get_commits())
32+
current_commit = [c for c in commits if c.sha == settings.commit_sha][0]
33+
run_url = f"https://github.com/{settings.github_repository}/actions/runs/{settings.run_id}"
34+
if settings.is_done and not settings.deploy_url:
35+
current_commit.create_status(
36+
state="success",
37+
description="No Docs Changes",
38+
context="deploy-docs",
39+
target_url=run_url,
40+
)
41+
logging.info("No docs changes found")
42+
return
43+
if not settings.deploy_url:
44+
current_commit.create_status(
45+
state="pending",
46+
description="Deploying Docs",
47+
context="deploy-docs",
48+
target_url=run_url,
49+
)
50+
logging.info("No deploy URL available yet")
51+
return
52+
current_commit.create_status(
53+
state="success",
54+
description="Docs Deployed",
55+
context="deploy-docs",
56+
target_url=run_url,
57+
)
58+
59+
files = list(use_pr.get_files())
60+
docs_files = [f for f in files if f.filename.startswith("docs/")]
61+
62+
deploy_url = settings.deploy_url.rstrip("/")
63+
links: list[str] = []
64+
for f in docs_files:
65+
match = re.match(r"docs/(.*)", f.filename)
66+
assert match
67+
path = match.group(1)
68+
if path.endswith("index.md"):
69+
path = path.replace("index.md", "")
70+
else:
71+
path = path.replace(".md", "/")
72+
link = f"{deploy_url}/{path}"
73+
links.append(link)
74+
links.sort()
75+
76+
message = f"📝 Docs preview for commit {settings.commit_sha} at: {deploy_url}"
77+
78+
if links:
79+
message += "\n\n### Modified Pages\n\n"
80+
message += "\n".join([f"* {link}" for link in links])
81+
82+
print(message)
83+
use_pr.as_issue().create_comment(message)
84+
85+
logging.info("Finished")
86+
87+
88+
if __name__ == "__main__":
89+
main()

0 commit comments

Comments
 (0)