Skip to content

Commit 77374aa

Browse files
authored
♻️ Refactor Deploy Docs GitHub Action to be a script and update token preparing for org (#1039)
1 parent d7af50c commit 77374aa

File tree

6 files changed

+57
-92
lines changed

6 files changed

+57
-92
lines changed

.github/actions/comment-docs-preview-in-pr/Dockerfile

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

.github/actions/comment-docs-preview-in-pr/action.yml

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

.github/actions/comment-docs-preview-in-pr/app/main.py

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

.github/workflows/deploy-docs.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
types:
77
- completed
88

9+
permissions:
10+
deployments: write
11+
issues: write
12+
pull-requests: write
13+
914
jobs:
1015
deploy-docs:
1116
runs-on: ubuntu-latest
@@ -38,9 +43,22 @@ jobs:
3843
directory: './site'
3944
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
4045
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
4158
- name: Comment Deploy
4259
if: steps.deploy.outputs.url != ''
43-
uses: ./.github/actions/comment-docs-preview-in-pr
44-
with:
45-
token: ${{ secrets.GITHUB_TOKEN }}
46-
deploy_url: "${{ steps.deploy.outputs.url }}"
60+
run: python ./scripts/comment_docs_deploy_url_in_pr.py
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
DEPLOY_URL: ${{ steps.deploy.outputs.url }}
64+
COMMIT_SHA: ${{ github.event.workflow_run.head_sha }}

requirements-github-actions.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PyGithub>=2.3.0,<3.0.0
2+
pydantic>=2.5.3,<3.0.0
3+
pydantic-settings>=2.1.0,<3.0.0
4+
httpx>=0.27.0,<0.28.0
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import logging
2+
import sys
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
13+
commit_sha: str
14+
15+
16+
if __name__ == "__main__":
17+
logging.basicConfig(level=logging.INFO)
18+
settings = Settings()
19+
logging.info(f"Using config: {settings.model_dump_json()}")
20+
g = Github(settings.github_token.get_secret_value())
21+
repo = g.get_repo(settings.github_repository)
22+
use_pr = next(
23+
(pr for pr in repo.get_pulls() if pr.head.sha == settings.commit_sha), None
24+
)
25+
if not use_pr:
26+
logging.error(f"No PR found for hash: {settings.commit_sha}")
27+
sys.exit(0)
28+
use_pr.as_issue().create_comment(
29+
f"📝 Docs preview for commit {settings.commit_sha} at: {settings.deploy_url}"
30+
)
31+
logging.info("Finished")

0 commit comments

Comments
 (0)